@@ -143,7 +143,7 @@ public void shouldAllowAcquireAfterFailures() throws Exception
143143 {
144144 try
145145 {
146- pool . acquire (). get ( 5 , TimeUnit . SECONDS );
146+ acquire ( pool );
147147 fail ( "Exception expected" );
148148 }
149149 catch ( ExecutionException e )
@@ -154,8 +154,7 @@ public void shouldAllowAcquireAfterFailures() throws Exception
154154
155155 authTokenMap .put ( "credentials" , value ( Neo4jRunner .PASSWORD ) );
156156
157- Channel channel = pool .acquire ().get ( 5 , TimeUnit .SECONDS );
158- assertNotNull ( channel );
157+ assertNotNull ( acquire ( pool ) );
159158 }
160159
161160 @ Test
@@ -166,13 +165,12 @@ public void shouldLimitNumberOfConcurrentConnections() throws Exception
166165
167166 for ( int i = 0 ; i < maxConnections ; i ++ )
168167 {
169- Channel channel = pool .acquire ().get ( 5 , TimeUnit .SECONDS );
170- assertNotNull ( channel );
168+ assertNotNull ( acquire ( pool ) );
171169 }
172170
173171 try
174172 {
175- pool . acquire (). get ( 5 , TimeUnit . SECONDS );
173+ acquire ( pool );
176174 fail ( "Exception expected" );
177175 }
178176 catch ( ExecutionException e )
@@ -182,6 +180,29 @@ public void shouldLimitNumberOfConcurrentConnections() throws Exception
182180 }
183181 }
184182
183+ @ Test
184+ public void shouldTrackActiveChannels () throws Exception
185+ {
186+ ActiveChannelTracker activeChannelTracker = new ActiveChannelTracker ( DEV_NULL_LOGGING );
187+
188+ poolHandler = activeChannelTracker ;
189+ pool = newPool ( neo4j .authToken () );
190+
191+ Channel channel1 = acquire ( pool );
192+ Channel channel2 = acquire ( pool );
193+ Channel channel3 = acquire ( pool );
194+ assertEquals ( 3 , activeChannelTracker .activeChannelCount ( neo4j .address () ) );
195+
196+ release ( channel1 );
197+ release ( channel2 );
198+ release ( channel3 );
199+ assertEquals ( 0 , activeChannelTracker .activeChannelCount ( neo4j .address () ) );
200+
201+ assertNotNull ( acquire ( pool ) );
202+ assertNotNull ( acquire ( pool ) );
203+ assertEquals ( 2 , activeChannelTracker .activeChannelCount ( neo4j .address () ) );
204+ }
205+
185206 private NettyChannelPool newPool ( AuthToken authToken )
186207 {
187208 return newPool ( authToken , 100 );
@@ -195,4 +216,14 @@ private NettyChannelPool newPool( AuthToken authToken, int maxConnections )
195216 return new NettyChannelPool ( neo4j .address (), connector , bootstrap , poolHandler , ChannelHealthChecker .ACTIVE ,
196217 1_000 , maxConnections );
197218 }
219+
220+ private static Channel acquire ( NettyChannelPool pool ) throws Exception
221+ {
222+ return pool .acquire ().get ( 5 , TimeUnit .SECONDS );
223+ }
224+
225+ private void release ( Channel channel ) throws Exception
226+ {
227+ pool .release ( channel ).get ( 5 , TimeUnit .SECONDS );
228+ }
198229}
0 commit comments