if (!sawMRE) {
throw new Exception("Did not see MutationsRejectedException");
}
// verify mutation did not go through
Scanner scanner = getConnector().createScanner("ct", Constants.NO_AUTHS);
scanner.setRange(new Range(new Text("r1")));
Iterator<Entry<Key,Value>> iter = scanner.iterator();
Entry<Key,Value> entry = iter.next();
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123".getBytes(Constants.UTF8)))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
// remove the numeric value constraint
getConnector().tableOperations().removeConstraint("ct", 1);
UtilWaitThread.sleep(1000);
// now should be able to add a non numeric value
bw = getConnector().createBatchWriter("ct", new BatchWriterConfig());
bw.addMutation(mut2);
bw.close();
// verify mutation went through
iter = scanner.iterator();
entry = iter.next();
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123a".getBytes(Constants.UTF8)))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
// add a constraint that references a non-existant class
getConnector().tableOperations().setProperty("ct", Property.TABLE_CONSTRAINT_PREFIX + "1", "com.foobar.nonExistantClass");
UtilWaitThread.sleep(1000);
// add a mutation
bw = getConnector().createBatchWriter("ct", new BatchWriterConfig());
Mutation mut3 = new Mutation(new Text("r1"));
mut3.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes(Constants.UTF8)));
bw.addMutation(mut3);
sawMRE = false;
try {
bw.close();
// should not get here
throw new Exception("Test failed, mutation went through when table had bad constraints");
} catch (MutationsRejectedException mre) {
sawMRE = true;
}
if (!sawMRE) {
throw new Exception("Did not see MutationsRejectedException");
}
// verify the mutation did not go through
iter = scanner.iterator();
entry = iter.next();
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123a".getBytes(Constants.UTF8)))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
// remove the bad constraint
getConnector().tableOperations().removeProperty("ct", Property.TABLE_CONSTRAINT_PREFIX + "1");
UtilWaitThread.sleep(1000);
// try the mutation again
bw = getConnector().createBatchWriter("ct", new BatchWriterConfig());
bw.addMutation(mut3);
bw.close();
// verify it went through
iter = scanner.iterator();
entry = iter.next();
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("foo".getBytes(Constants.UTF8)))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());