@Test void getConnection() throws Exception { when(plcDriver.getConnection(anyString())).then(invocationOnMock -> new DummyPlcConnection(invocationOnMock.getArgument(0))); LinkedList<Callable<PlcConnection>> callables = new LinkedList<>(); IntStream.range(0, 8).forEach(i -> callables.add(() -> { try { return SUT.getConnection("dummydummy:single/socket1/socket2?fancyOption=true"); } catch (PlcConnectionException e) { throw new RuntimeException(e); } })); IntStream.range(0, 5).forEach(i -> callables.add(() -> { try { return SUT.getConnection("dummydummy:multi-" + i + "/socket1/socket2?fancyOption=true"); } catch (PlcConnectionException e) { throw new RuntimeException(e); } })); List<Future<PlcConnection>> futures = executorService.invokeAll(callables); futures.forEach(plcConnectionFuture1 -> { try { plcConnectionFuture1.get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }); LOGGER.info("Statistics after execution {}", SUT.getStatistics()); verify(plcDriver, times(13)).getConnection(anyString()); assertThat(SUT.getStatistics()).contains( entry("PoolKey{url='dummydummy:single/socket1/socket2?fancyOption=true'}.numActive", 8) ); futures.forEach(plcConnectionFuture -> { try { plcConnectionFuture.get().close(); } catch (Exception e) { throw new RuntimeException(e); } }); assertThat(SUT.getStatistics()).contains( entry("PoolKey{url='dummydummy:single/socket1/socket2?fancyOption=true'}.numActive", 0) ); }
@Override public PlcConnection getConnection(String url) throws PlcConnectionException { return getConnection(url, noPlcAuthentication); }
PooledPlcDriverManager extends PlcDriverManager { @Override public PlcConnection getConnection(String url) throws PlcConnectionException { return getConnection(url, noPlcAuthentication); } }
PooledPlcDriverManager extends PlcDriverManager { @Override public PlcConnection getConnection(String url) throws PlcConnectionException { return getConnection(url, noPlcAuthentication); } PooledPlcDriverManager();  PooledPlcDriverManager(PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader);  PooledPlcDriverManager(ClassLoader classLoader, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(PoolCreator poolCreator);  PooledPlcDriverManager(PoolCreator poolCreator, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader, PoolCreator poolCreator); }
PooledPlcDriverManager extends PlcDriverManager { @Override public PlcConnection getConnection(String url) throws PlcConnectionException { return getConnection(url, noPlcAuthentication); } PooledPlcDriverManager();  PooledPlcDriverManager(PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader);  PooledPlcDriverManager(ClassLoader classLoader, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(PoolCreator poolCreator);  PooledPlcDriverManager(PoolCreator poolCreator, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader, PoolCreator poolCreator); @Override PlcConnection getConnection(String url); @Override PlcConnection getConnection(String url, PlcAuthentication authentication); Map<String, Number> getStatistics(); }
PooledPlcDriverManager extends PlcDriverManager { @Override public PlcConnection getConnection(String url) throws PlcConnectionException { return getConnection(url, noPlcAuthentication); } PooledPlcDriverManager();  PooledPlcDriverManager(PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader);  PooledPlcDriverManager(ClassLoader classLoader, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(PoolCreator poolCreator);  PooledPlcDriverManager(PoolCreator poolCreator, PoolKeyFactory poolKeyFactory);  PooledPlcDriverManager(ClassLoader classLoader, PoolCreator poolCreator); @Override PlcConnection getConnection(String url); @Override PlcConnection getConnection(String url, PlcAuthentication authentication); Map<String, Number> getStatistics();  }