public void verifyTableOperationsExceptions() throws Exception {
String tableName = namespace + ".1";
IteratorSetting setting = new IteratorSetting(200, VersioningIterator.class);
Text a = new Text("a");
Text z = new Text("z");
TableOperations ops = c.tableOperations();
// this one doesn't throw an exception, so don't fail; just check that it works
assertFalse(ops.exists(tableName));
// table operations that should throw an AccumuloException caused by NamespaceNotFoundException
int numRun = 0;
ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND: for (int i = 0;; ++i)
try {
switch (i) {
case 0:
ops.create(tableName);
fail();
case 1:
ops.create("a");
ops.clone("a", tableName, true, Collections.<String,String> emptyMap(), Collections.<String> emptySet());
fail();
case 2:
ops.importTable(tableName, System.getProperty("user.dir") + "/target");
fail();
default:
// break out of infinite loop
assertEquals(3, i); // check test integrity
assertEquals(3, numRun); // check test integrity
break ACCUMULOEXCEPTIONS_NAMESPACENOTFOUND;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof AccumuloException) || !(e.getCause() instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
// table operations that should throw an AccumuloException caused by a TableNotFoundException caused by a NamespaceNotFoundException
// these are here because we didn't declare TableNotFoundException in the API :(
numRun = 0;
ACCUMULOEXCEPTIONS_TABLENOTFOUND: for (int i = 0;; ++i)
try {
switch (i) {
case 0:
ops.removeConstraint(tableName, 0);
fail();
case 1:
ops.removeProperty(tableName, "a");
fail();
case 2:
ops.setProperty(tableName, "a", "b");
fail();
default:
// break out of infinite loop
assertEquals(3, i); // check test integrity
assertEquals(3, numRun); // check test integrity
break ACCUMULOEXCEPTIONS_TABLENOTFOUND;
}
} catch (Exception e) {
numRun++;
if (!(e instanceof AccumuloException) || !(e.getCause() instanceof TableNotFoundException)
|| !(e.getCause().getCause() instanceof NamespaceNotFoundException))
throw new Exception("Case " + i + " resulted in " + e.getClass().getName(), e);
}
// table operations that should throw a TableNotFoundException caused by NamespaceNotFoundException
numRun = 0;
TABLENOTFOUNDEXCEPTIONS: for (int i = 0;; ++i)
try {
switch (i) {
case 0:
ops.addConstraint(tableName, NumericValueConstraint.class.getName());
fail();
case 1:
ops.addSplits(tableName, new TreeSet<Text>());
fail();
case 2:
ops.attachIterator(tableName, setting);
fail();
case 3:
ops.cancelCompaction(tableName);
fail();
case 4:
ops.checkIteratorConflicts(tableName, setting, EnumSet.allOf(IteratorScope.class));
fail();
case 5:
ops.clearLocatorCache(tableName);
fail();
case 6:
ops.clone(tableName, "2", true, Collections.<String,String> emptyMap(), Collections.<String> emptySet());
fail();
case 7:
ops.compact(tableName, a, z, true, true);
fail();
case 8:
ops.delete(tableName);
fail();
case 9:
ops.deleteRows(tableName, a, z);
fail();
case 10:
ops.splitRangeByTablets(tableName, new Range(), 10);
fail();
case 11:
ops.exportTable(tableName, namespace + "_dir");
fail();
case 12:
ops.flush(tableName, a, z, true);
fail();
case 13:
ops.getDiskUsage(Collections.singleton(tableName));
fail();
case 14:
ops.getIteratorSetting(tableName, "a", IteratorScope.scan);
fail();
case 15:
ops.getLocalityGroups(tableName);
fail();
case 16:
ops.getMaxRow(tableName, Authorizations.EMPTY, a, true, z, true);
fail();
case 17:
ops.getProperties(tableName);
fail();
case 18:
ops.importDirectory(tableName, "", "", false);
fail();
case 19:
ops.testClassLoad(tableName, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
fail();
case 20:
ops.listConstraints(tableName);
fail();
case 21:
ops.listIterators(tableName);
fail();
case 22:
ops.listSplits(tableName);
fail();
case 23:
ops.merge(tableName, a, z);
fail();
case 24:
ops.offline(tableName, true);
fail();
case 25:
ops.online(tableName, true);
fail();
case 26:
ops.removeIterator(tableName, "a", EnumSet.of(IteratorScope.scan));
fail();
case 27:
ops.rename(tableName, tableName + "2");
fail();
case 28:
ops.setLocalityGroups(tableName, Collections.<String,Set<Text>> emptyMap());
fail();
default:
// break out of infinite loop
assertEquals(29, i); // check test integrity
assertEquals(29, numRun); // check test integrity