33
33
import org .junit .jupiter .api .BeforeEach ;
34
34
import org .junit .jupiter .api .Test ;
35
35
36
+ import java .util .ArrayList ;
37
+ import java .util .List ;
36
38
import java .util .concurrent .TimeUnit ;
37
39
import java .util .concurrent .atomic .AtomicInteger ;
38
40
@@ -240,15 +242,13 @@ void testPendingAcquisitionsDuringPoolClosure() throws Exception {
240
242
241
243
@ SuppressWarnings ("AnonymousInnerClassMayBeStatic" )
242
244
@ Test
243
- void testPendingCreateChannelFutureDuringPoolClosure () throws Exception {
244
- final Promise <Void > createSuccess = new DefaultPromise <>(EVENT_EXECUTOR );
245
+ void testClosePendingCreateChannelFutureDuringPoolClosure () throws Exception {
246
+ final List <Promise <Channel >> createPromises = new ArrayList <>();
247
+
245
248
final PooledObjectFactory <Channel > factory = new PooledObjectFactory <Channel >() {
246
249
@ Override
247
250
public Future <Channel > create (final Promise <Channel > promise ) {
248
- EVENT_EXECUTOR .schedule (() -> {
249
- promise .trySuccess (new TestChannel (true ));
250
- createSuccess .setSuccess (null );
251
- }, 1 , TimeUnit .SECONDS );
251
+ createPromises .add (promise );
252
252
return promise ;
253
253
}
254
254
@@ -261,8 +261,22 @@ public Future<Void> destroy(final Channel channel, final Promise<Void> promise)
261
261
262
262
final ApnsChannelPool pool = new ApnsChannelPool (factory , 1 , EVENT_EXECUTOR , this .metricsListener );
263
263
264
- pool .acquire ();
265
- pool .close ().await ();
266
- assertTrue (createSuccess .isSuccess ());
264
+ final Future <Channel > acquireNewChannelFuture = pool .acquire ();
265
+ final Future <Channel > acquireReturnedChannelFuture = pool .acquire ();
266
+
267
+ final Future <Void > closeFuture = pool .close ();
268
+
269
+ EVENT_EXECUTOR .submit (() -> {
270
+ final TestChannel channel = new TestChannel (true );
271
+ createPromises .forEach (channelPromise -> channelPromise .trySuccess (channel ));
272
+ });
273
+
274
+ closeFuture .await ();
275
+
276
+ assertTrue (acquireNewChannelFuture .await ().isSuccess (),
277
+ "Futures waiting for new connections at pool closure should succeed." );
278
+
279
+ assertFalse (acquireReturnedChannelFuture .await ().isSuccess (),
280
+ "Futures waiting for existing connections at pool closure should fail." );
267
281
}
268
282
}
0 commit comments