ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(new Authorizations("A")));
Iterator<Result> results = cw.write(mutations.iterator());
int count = 0;
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
count++;
}
Assert.assertEquals(3, count);
Scanner scanner = conn.createScanner(tableName, new Authorizations("A"));
scanner.fetchColumn(new Text("tx"), new Text("seq"));
for (String row : new String[] {"99006", "59056", "19059"}) {
scanner.setRange(new Range(row));
Assert.assertEquals("1", scanner.iterator().next().getValue().toString());
}
TreeSet<Text> splits = new TreeSet<Text>();
splits.add(new Text("7"));
splits.add(new Text("3"));
conn.tableOperations().addSplits(tableName, splits);
mutations.clear();
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvab).setValue("1"));
cm3.put("name", "last", cvab, "Doe");
cm3.put("tx", "seq", cvab, "2");
mutations.add(cm3);
ConditionalMutation cm4 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvab));
cm4.put("name", "last", cvab, "Doe");
cm4.put("tx", "seq", cvab, "1");
mutations.add(cm4);
ConditionalMutation cm5 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvab).setValue("2"));
cm5.put("name", "last", cvab, "Doe");
cm5.put("tx", "seq", cvab, "3");
mutations.add(cm5);
results = cw.write(mutations.iterator());
int accepted = 0;
int rejected = 0;
while (results.hasNext()) {
Result result = results.next();
if (new String(result.getMutation().getRow()).equals("99006")) {
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
accepted++;
} else {
Assert.assertEquals(Status.REJECTED, result.getStatus());
rejected++;
}
}
Assert.assertEquals(1, accepted);