Plc4XProducer extends DefaultAsyncProducer { @Override protected void doStop() throws Exception { int openRequestsAtStop = openRequests.get(); log.debug("Stopping with {} open requests", openRequestsAtStop); if (openRequestsAtStop > 0) { log.warn("There are still {} open requests", openRequestsAtStop); } } Plc4XProducer(Plc4XEndpoint endpoint); @Override void process(Exchange exchange); @Override boolean process(Exchange exchange, AsyncCallback callback);  }
@Test public void doStop() throws Exception { SUT.doStop(); }
@Test public void doStopOpenRequest() throws Exception { Field openRequests = SUT.getClass().getDeclaredField("openRequests"); openRequests.setAccessible(true); AtomicInteger atomicInteger = (AtomicInteger) openRequests.get(SUT); atomicInteger.incrementAndGet(); SUT.doStop(); }
@Test public void doStopBadConnection() throws Exception { Field openRequests = SUT.getClass().getDeclaredField("plcConnection"); openRequests.setAccessible(true); PlcConnection plcConnectionMock = mock(PlcConnection.class); doThrow(new RuntimeException("oh noes")).when(plcConnectionMock).close(); openRequests.set(SUT, plcConnectionMock); SUT.doStop(); }