use of java.io.Closeable in project druid by druid-io.
the class CloserRuleTest method testJustLogs.
@Test
public void testJustLogs() throws Throwable {
final CloserRule closer = new CloserRule(false);
final String ioExceptionMsg = "You can't triple stamp a double stamp!";
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
throw new IOException(ioExceptionMsg);
}
});
run(closer, Runnables.doNothing());
}
use of java.io.Closeable in project druid by druid-io.
the class CloserRuleTest method testThrowsCloseException.
@Test
public void testThrowsCloseException() {
final CloserRule closer = new CloserRule(true);
final String ioExceptionMsg = "You can't triple stamp a double stamp!";
final IOException ioException = new IOException(ioExceptionMsg);
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
throw ioException;
}
});
Throwable ex = null;
try {
run(closer, Runnables.doNothing());
} catch (Throwable throwable) {
ex = throwable;
}
Assert.assertEquals(ioException, ex);
}
use of java.io.Closeable in project druid by druid-io.
the class CloserRuleTest method testJustLogsAnything.
@Test
public void testJustLogsAnything() throws Throwable {
final CloserRule closer = new CloserRule(false);
final String ioExceptionMsg = "You can't triple stamp a double stamp!";
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
throw new IOException(ioExceptionMsg);
}
});
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
throw new IOException(ioExceptionMsg);
}
});
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
throw new IOException(ioExceptionMsg);
}
});
run(closer, Runnables.doNothing());
}
use of java.io.Closeable in project druid by druid-io.
the class CloserRuleTest method testClosesEverything.
@Test
public void testClosesEverything() {
final AtomicLong counter = new AtomicLong(0L);
final CloserRule closer = new CloserRule(true);
final String ioExceptionMsg = "You can't triple stamp a double stamp!";
final List<IOException> ioExceptions = Arrays.<IOException>asList(new IOException(ioExceptionMsg), null, new IOException(ioExceptionMsg), null, new IOException(ioExceptionMsg), null);
for (final IOException throwable : ioExceptions) {
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
counter.incrementAndGet();
if (throwable != null) {
throw throwable;
}
}
});
}
Throwable ex = null;
try {
run(closer, Runnables.doNothing());
} catch (Throwable throwable) {
ex = throwable;
}
Assert.assertNotNull(ex);
Assert.assertEquals(ioExceptions.size(), counter.get());
Assert.assertEquals(2, ex.getSuppressed().length);
}
use of java.io.Closeable in project druid by druid-io.
the class CloserRuleTest method testCloses.
@Test
public void testCloses() throws Throwable {
final CloserRule closer = new CloserRule(false);
final AtomicBoolean closed = new AtomicBoolean(false);
closer.closeLater(new Closeable() {
@Override
public void close() throws IOException {
closed.set(true);
}
});
run(closer, Runnables.doNothing());
Assert.assertTrue(closed.get());
}
Aggregations