Connector connector = instance.getConnector("root", password);
BatchWriterConfig config = new BatchWriterConfig();
TCredentials creds = CredentialHelper.create("root", password, instance.getInstanceID());
MultiTableBatchWriter mtbw = new MultiTableBatchWriterImpl(instance, creds, config, 0, TimeUnit.SECONDS);
boolean mutationsRejected = false;
try {
final String table1 = "testOfflineTableWithoutCache_table1", table2 = "testOfflineTableWithoutCache_table2";
TableOperations tops = connector.tableOperations();
tops.create(table1);
tops.create(table2);
BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
Mutation m1 = new Mutation("foo");
m1.put("col1", "", "val1");
m1.put("col2", "", "val2");
bw1.addMutation(m1);
bw2.addMutation(m1);
// Mutations might or might not flush before tables goes offline
tops.offline(table1);
tops.offline(table2);
try {
bw1 = mtbw.getBatchWriter(table1);
Assert.fail(table1 + " should be offline");
} catch (TableOfflineException e) {
// pass
mutationsRejected = true;
}
try {
bw2 = mtbw.getBatchWriter(table2);
Assert.fail(table1 + " should be offline");
} catch (TableOfflineException e) {
// pass
mutationsRejected = true;
}
} finally {
if (null != mtbw) {
try {
// Mutations might have flushed before the table offline occurred
mtbw.close();
} catch (MutationsRejectedException e) {
// Pass
mutationsRejected = true;
}
}