@Test
public void testFail()
throws Exception
{
SuspendingExecutor suspendingExecutor = createSuspendingExecutor();
HiveSplitSource hiveSplitSource = new HiveSplitSource("test", 10, suspendingExecutor);
// add some splits
for (int i = 0; i < 5; i++) {
hiveSplitSource.addToQueue(new TestSplit(i));
assertEquals(hiveSplitSource.getOutstandingSplitCount(), i + 1);
}
// remove a split and verify
assertEquals(hiveSplitSource.getNextBatch(1).size(), 1);
assertEquals(hiveSplitSource.getOutstandingSplitCount(), 4);
// fail source
hiveSplitSource.fail(new RuntimeException("test"));
assertEquals(hiveSplitSource.getOutstandingSplitCount(), 4);
// try to remove a split and verify we got the expected exception
try {
hiveSplitSource.getNextBatch(1);
fail("expected RuntimeException");
}
catch (RuntimeException e) {
assertEquals(e.getCause().getMessage(), "test");
}
assertEquals(hiveSplitSource.getOutstandingSplitCount(), 4);
// attempt to add another split and verify it does not work
hiveSplitSource.addToQueue(new TestSplit(99));
assertEquals(hiveSplitSource.getOutstandingSplitCount(), 4);
// fail source again
hiveSplitSource.fail(new RuntimeException("another failure"));
assertEquals(hiveSplitSource.getOutstandingSplitCount(), 4);
// try to remove a split and verify we got the first exception
try {
hiveSplitSource.getNextBatch(1);
fail("expected RuntimeException");
}
catch (RuntimeException e) {
assertEquals(e.getCause().getMessage(), "test");
}