@@ -143,7 +143,7 @@ public void shouldAllowAcquireAfterFailures() throws Exception
143
143
{
144
144
try
145
145
{
146
- pool . acquire (). get ( 5 , TimeUnit . SECONDS );
146
+ acquire ( pool );
147
147
fail ( "Exception expected" );
148
148
}
149
149
catch ( ExecutionException e )
@@ -154,8 +154,7 @@ public void shouldAllowAcquireAfterFailures() throws Exception
154
154
155
155
authTokenMap .put ( "credentials" , value ( Neo4jRunner .PASSWORD ) );
156
156
157
- Channel channel = pool .acquire ().get ( 5 , TimeUnit .SECONDS );
158
- assertNotNull ( channel );
157
+ assertNotNull ( acquire ( pool ) );
159
158
}
160
159
161
160
@ Test
@@ -166,13 +165,12 @@ public void shouldLimitNumberOfConcurrentConnections() throws Exception
166
165
167
166
for ( int i = 0 ; i < maxConnections ; i ++ )
168
167
{
169
- Channel channel = pool .acquire ().get ( 5 , TimeUnit .SECONDS );
170
- assertNotNull ( channel );
168
+ assertNotNull ( acquire ( pool ) );
171
169
}
172
170
173
171
try
174
172
{
175
- pool . acquire (). get ( 5 , TimeUnit . SECONDS );
173
+ acquire ( pool );
176
174
fail ( "Exception expected" );
177
175
}
178
176
catch ( ExecutionException e )
@@ -182,6 +180,29 @@ public void shouldLimitNumberOfConcurrentConnections() throws Exception
182
180
}
183
181
}
184
182
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
+
185
206
private NettyChannelPool newPool ( AuthToken authToken )
186
207
{
187
208
return newPool ( authToken , 100 );
@@ -195,4 +216,14 @@ private NettyChannelPool newPool( AuthToken authToken, int maxConnections )
195
216
return new NettyChannelPool ( neo4j .address (), connector , bootstrap , poolHandler , ChannelHealthChecker .ACTIVE ,
196
217
1_000 , maxConnections );
197
218
}
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
+ }
198
229
}
0 commit comments