conn.tableOperations().create(tableName);
ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig());
// mutation conditional on column tx:seq not existing
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq"));
cm0.put("name", "last", "doe");
cm0.put("name", "first", "john");
cm0.put("tx", "seq", "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
Assert.assertEquals(Status.REJECTED, cw.write(cm0).getStatus());
// mutation conditional on column tx:seq being 1
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"));
cm1.put("name", "last", "Doe");
cm1.put("tx", "seq", "2");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm1).getStatus());
// test condition where value differs
ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"));
cm2.put("name", "last", "DOE");
cm2.put("tx", "seq", "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
// test condition where column does not exists
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("txtypo", "seq").setValue("1"));
cm3.put("name", "last", "deo");
cm3.put("tx", "seq", "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
// test two conditions, where one should fail
ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("2"), new Condition("name", "last").setValue("doe"));
cm4.put("name", "last", "deo");
cm4.put("tx", "seq", "3");
Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
// test two conditions, where one should fail
ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"), new Condition("name", "last").setValue("Doe"));
cm5.put("name", "last", "deo");
cm5.put("tx", "seq", "3");
Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
// ensure rejected mutations did not write
Scanner scanner = conn.createScanner(tableName, Authorizations.EMPTY);
scanner.fetchColumn(new Text("name"), new Text("last"));
scanner.setRange(new Range("99006"));
Assert.assertEquals("Doe", scanner.iterator().next().getValue().toString());
// test w/ two conditions that are met
ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("2"), new Condition("name", "last").setValue("Doe"));
cm6.put("name", "last", "DOE");
cm6.put("tx", "seq", "3");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
Assert.assertEquals("DOE", scanner.iterator().next().getValue().toString());
// test a conditional mutation that deletes
ConditionalMutation cm7 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("3"));
cm7.putDelete("name", "last");
cm7.putDelete("name", "first");
cm7.putDelete("tx", "seq");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm7).getStatus());