Configuration conf = new Configuration(false);
Mockito.when(env.getConfiguration()).thenReturn(conf);
LocalHBaseState table = new SimpleTableState(emptyState);
// make a new codec on those kvs
CoveredColumnIndexCodec codec =
CoveredColumnIndexCodec.getCodecForTesting(Arrays.asList(group));
// start with a basic put that has some keyvalues
Put p = new Put(PK);
// setup the kvs to add
List<Cell> kvs = new ArrayList<Cell>();
byte[] v1 = Bytes.toBytes("v1");
KeyValue kv = new KeyValue(PK, FAMILY, QUAL, 1, v1);
kvs.add(kv);
p.add(kv);
byte[] v2 = Bytes.toBytes("v2");
kv = new KeyValue(PK, Bytes.toBytes("family2"), QUAL, 1, v2);
kvs.add(kv);
p.add(kv);
// check the codec for deletes it should send
LocalTableState state = new LocalTableState(env, table, p);
Iterable<IndexUpdate> updates = codec.getIndexDeletes(state);
assertFalse("Found index updates without any existing kvs in table!", updates.iterator().next()
.isValid());
// get the updates with the pending update
state.setCurrentTimestamp(1);
state.addPendingUpdates(KeyValueUtil.ensureKeyValues(kvs));
updates = codec.getIndexUpserts(state);
assertTrue("Didn't find index updates for pending primary table update!", updates.iterator()
.hasNext());
for (IndexUpdate update : updates) {
assertTrue("Update marked as invalid, but should be a pending index write!", update.isValid());
Put m = (Put) update.getUpdate();
// should just be the single update for the column reference
byte[] expected =
CoveredColumnIndexCodec.composeRowKey(PK, v1.length, Arrays.asList(toColumnEntry(v1)));
assertArrayEquals("Didn't get expected index value", expected, m.getRow());
}
// then apply a delete
Delete d = new Delete(PK, 2);
// need to set the timestamp here, as would actually happen on the server, unlike what happens
// with puts, where the get the constructor specified timestamp for unspecified methods.
d.deleteFamily(FAMILY, 2);
// setup the next batch of 'current state', basically just ripping out the current state from
// the last round
table = new SimpleTableState(Result.create(kvs));
state = new LocalTableState(env, table, d);
state.setCurrentTimestamp(2);
// check the cleanup of the current table, after the puts (mocking a 'next' update)
updates = codec.getIndexDeletes(state);
for (IndexUpdate update : updates) {
assertTrue("Didn't have any index cleanup, even though there is current state",
update.isValid());
Delete m = (Delete) update.getUpdate();
// should just be the single update for the column reference