Search in sources :

Example 16 with Closeable

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());
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with Closeable

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);
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with Closeable

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());
}
Also used : Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with Closeable

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with Closeable

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Closeable (java.io.Closeable)216 IOException (java.io.IOException)88 Test (org.junit.Test)56 ArrayList (java.util.ArrayList)29 File (java.io.File)26 HashMap (java.util.HashMap)12 VirtualFile (org.jboss.vfs.VirtualFile)12 URL (java.net.URL)9 Path (java.nio.file.Path)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Map (java.util.Map)7 ISE (io.druid.java.util.common.ISE)6 InputStream (java.io.InputStream)6 MountHandle (org.jboss.as.server.deployment.module.MountHandle)6 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 ProgramController (co.cask.cdap.app.runtime.ProgramController)5 ProgramType (co.cask.cdap.proto.ProgramType)4 ProgramId (co.cask.cdap.proto.id.ProgramId)4 Pair (io.druid.java.util.common.Pair)4 FileOutputStream (java.io.FileOutputStream)4