This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push: new 763a3d6 [plc4j-pool] replaced pair with custom pool key added TODOs and notes about partial wrong pooling (part2) 763a3d6 is described below commit 763a3d6317ea4e63b087b6bbd0fa5661b82a9677 Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Fri Oct 26 09:24:00 2018 +0200 [plc4j-pool] replaced pair with custom pool key added TODOs and notes about partial wrong pooling (part2) --- .../connectionpool/PooledPlcDriverManagerTest.java | 39 +++++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/plc4j/utils/connection-pool/src/test/java/org/apache/plc4x/java/utils/connectionpool/PooledPlcDriverManagerTest.java b/plc4j/utils/connection-pool/src/test/java/org/apache/plc4x/java/utils/connectionpool/PooledPlcDriverManagerTest.java index 9d7b465..86153df 100644 --- a/plc4j/utils/connection-pool/src/test/java/org/apache/plc4x/java/utils/connectionpool/PooledPlcDriverManagerTest.java +++ b/plc4j/utils/connection-pool/src/test/java/org/apache/plc4x/java/utils/connectionpool/PooledPlcDriverManagerTest.java @@ -54,6 +54,8 @@ import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class PooledPlcDriverManagerTest implements WithAssertions { + private static Logger LOGGER = LoggerFactory.getLogger(PooledPlcDriverManagerTest.class); + private PooledPlcDriverManager SUT = new PooledPlcDriverManager(pooledPlcConnectionFactory -> { GenericObjectPoolConfig<PlcConnection> plcConnectionGenericObjectPoolConfig = new GenericObjectPoolConfig<>(); plcConnectionGenericObjectPoolConfig.setMinIdle(1); @@ -106,12 +108,22 @@ class PooledPlcDriverManagerTest implements WithAssertions { List<Future<PlcConnection>> futures = executorService.invokeAll(callables); + // Wait for existing connections + futures.forEach(plcConnectionFuture1 -> { + try { + plcConnectionFuture1.get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }); + LOGGER.info("Statistics after execution {}", SUT.getStatistics()); + // As we have a pool size of 8 we should have only 8 + 5 calls for the separate pools verify(plcDriver, times(13)).connect(anyString()); assertThat(SUT.getStatistics()).contains( - entry("dummydummy:single.numActive", 8), - entry("dummydummy:single.numIdle", 0) + entry("dummydummy:single/socket1/socket2?fancyOption=true.numActive", 8), + entry("dummydummy:single/socket1/socket2?fancyOption=true.numIdle", 0) ); futures.forEach(plcConnectionFuture -> { @@ -123,8 +135,8 @@ class PooledPlcDriverManagerTest implements WithAssertions { }); assertThat(SUT.getStatistics()).contains( - entry("dummydummy:single.numActive", 0), - entry("dummydummy:single.numIdle", 8) + entry("dummydummy:single/socket1/socket2?fancyOption=true.numActive", 0), + entry("dummydummy:single/socket1/socket2?fancyOption=true.numIdle", 8) ); } @@ -154,17 +166,26 @@ class PooledPlcDriverManagerTest implements WithAssertions { 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()); + // As we have a pool size of 8 we should have only 8 + 5 calls for the separate pools verify(plcDriver, times(13)).connect(anyString(), any()); assertThat(SUT.getStatistics()).contains( - entry("dummydummy:single/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numActive", 8), - entry("dummydummy:single/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numIdle", 0) + entry("dummydummy:single/socket1/socket2?fancyOption=true/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numActive", 8), + entry("dummydummy:single/socket1/socket2?fancyOption=true/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numIdle", 0) ); futures.forEach(plcConnectionFuture -> { try { - plcConnectionFuture.get().connect(); plcConnectionFuture.get().close(); } catch (Exception e) { throw new RuntimeException(e); @@ -172,8 +193,8 @@ class PooledPlcDriverManagerTest implements WithAssertions { }); assertThat(SUT.getStatistics()).contains( - entry("dummydummy:single/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numActive", 0), - entry("dummydummy:single/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numIdle", 8) + entry("dummydummy:single/socket1/socket2?fancyOption=true/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numActive", 0), + entry("dummydummy:single/socket1/socket2?fancyOption=true/PlcUsernamePasswordAuthentication{username='user', password='*****************'}.numIdle", 8) ); }