@Test public void testNullClose() throws Throwable { ClosingService<OpenClose> svc = new ClosingService<OpenClose>("", null); svc.init(new Configuration()); svc.start(); assertNull(svc.getCloseable()); svc.stop(); }
/** * This does not recurse forever, as the service has already entered the * STOPPED state before the inner close tries to stop it -that operation * is a no-op * @throws Throwable */ @Test public void testCloseSelf() throws Throwable { ClosingService<ClosingService> svc = new ClosingService<ClosingService>(""); svc.setCloseable(svc); svc.stop(); }
/** * Stop routine will close the closeable -if not null - and set the * reference to null afterwards * This operation does raise any exception on the close, though it does * record it */ @Override protected void serviceStop() { C target = getCloseable(); if (target != null) { try { target.close(); } catch (IOException ioe) { noteFailure(ioe); } setCloseable(null); } } }
@Test public void testFailingClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); openClose.raiseExceptionOnClose = true; svc.stop(); assertTrue(openClose.closed); Throwable cause = svc.getFailureCause(); assertNotNull(cause); //retry should be a no-op svc.close(); }
private ClosingService<OpenClose> instance(boolean raiseExceptionOnClose) { ClosingService<OpenClose> svc = new ClosingService<OpenClose>(new OpenClose( raiseExceptionOnClose)); svc.init(new Configuration()); svc.start(); return svc; }
@Test public void testDoubleClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); openClose.raiseExceptionOnClose = true; svc.stop(); assertTrue(openClose.closed); Throwable cause = svc.getFailureCause(); assertNotNull(cause); openClose.closed = false; svc.stop(); assertEquals(cause, svc.getFailureCause()); }
@Test public void testSimpleClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); assertFalse(openClose.closed); svc.stop(); assertTrue(openClose.closed); }
jmxReporter = JmxReporter.forRegistry(metrics).build(); jmxReporter.start(); addService(new ClosingService<>(jmxReporter)); .build(); reporter.start(interval, TimeUnit.MINUTES); addService(new ClosingService<>(reporter)); summary.append(String.format(", SLF4J to log %s interval=%d", logName, interval));
@Test public void testFailingClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); openClose.raiseExceptionOnClose = true; svc.stop(); assertTrue(openClose.closed); Throwable cause = svc.getFailureCause(); assertNotNull(cause); //retry should be a no-op svc.close(); }
private ClosingService<OpenClose> instance(boolean raiseExceptionOnClose) { ClosingService<OpenClose> svc = new ClosingService<OpenClose>(new OpenClose( raiseExceptionOnClose)); svc.init(new Configuration()); svc.start(); return svc; }
@Test public void testDoubleClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); openClose.raiseExceptionOnClose = true; svc.stop(); assertTrue(openClose.closed); Throwable cause = svc.getFailureCause(); assertNotNull(cause); openClose.closed = false; svc.stop(); assertEquals(cause, svc.getFailureCause()); }
@Test public void testSimpleClose() throws Throwable { ClosingService<OpenClose> svc = instance(false); OpenClose openClose = svc.getCloseable(); assertFalse(openClose.closed); svc.stop(); assertTrue(openClose.closed); }
jmxReporter = JmxReporter.forRegistry(metrics).build(); jmxReporter.start(); addService(new ClosingService<>(jmxReporter)); .build(); reporter.start(interval, TimeUnit.MINUTES); addService(new ClosingService<>(reporter)); summary.append(String.format(", SLF4J to log %s interval=%d", logName, interval));
@Test public void testNullClose() throws Throwable { ClosingService<OpenClose> svc = new ClosingService<OpenClose>("", null); svc.init(new Configuration()); svc.start(); assertNull(svc.getCloseable()); svc.stop(); }
/** * This does not recurse forever, as the service has already entered the * STOPPED state before the inner close tries to stop it -that operation * is a no-op * @throws Throwable */ @Test public void testCloseSelf() throws Throwable { ClosingService<ClosingService> svc = new ClosingService<ClosingService>(""); svc.setCloseable(svc); svc.stop(); }
/** * Stop routine will close the closeable -if not null - and set the * reference to null afterwards * This operation does raise any exception on the close, though it does * record it */ @Override protected void serviceStop() { C target = getCloseable(); if (target != null) { try { target.close(); } catch (IOException ioe) { noteFailure(ioe); } setCloseable(null); } } }