@@ -238,4 +238,50 @@ public void testBorrow_twoHiPrioBlocks() throws Exception {
238
238
verify (factoryMock , times (2 )).makeObject (workerKey1 );
239
239
verify (factoryMock , times (1 )).makeObject (workerKey2 );
240
240
}
241
+
242
+ @ Test
243
+ public void testStopWork_activePoolsStopped () throws Exception {
244
+ WorkerPool pool =
245
+ new WorkerPool (
246
+ factoryMock ,
247
+ // Have to declare the mnemonics, or they all fall into the default SimpleWorkerPool.
248
+ ImmutableMap .of ("mnem1" , 2 , "mnem2" , 2 ),
249
+ ImmutableMap .of ("mnem2" , 2 , "mnem3" , 2 ),
250
+ Lists .newArrayList ());
251
+ WorkerKey singleKey1 = createWorkerKey (fileSystem , "mnem1" , false );
252
+ // These workers get borrowed, then both get destroyed in stopWork because they share mnemonic
253
+ WorkerKey singleKey1a = createWorkerKey (fileSystem , "mnem1" , false , "anArg" );
254
+ pool .borrowObject (singleKey1 );
255
+ Worker worker1a = pool .borrowObject (singleKey1a );
256
+ pool .returnObject (singleKey1a , worker1a );
257
+ WorkerKey singleKey2 = createWorkerKey (fileSystem , "mnem2" , false );
258
+ // This worker gets borrowed, then returned, doesn't get destroyed in stopWork
259
+ Worker worker1 = pool .borrowObject (singleKey2 );
260
+ pool .returnObject (singleKey2 , worker1 );
261
+ WorkerKey multiKey1 = createWorkerKey (fileSystem , "mnem2" , true );
262
+ // This worker gets borrowed, then destroyed in stopWork, but separately from the singleplex
263
+ // worker2 even though they share a mnemonic.
264
+ pool .borrowObject (multiKey1 );
265
+ WorkerKey multiKey2 = createWorkerKey (fileSystem , "mnem3" , true );
266
+ // This worker gets borrowed, then returned, doesn't get destroyed during stopWork.
267
+ Worker worker2 = pool .borrowObject (multiKey2 );
268
+ pool .returnObject (multiKey2 , worker2 );
269
+ verify (factoryMock , times (1 )).makeObject (singleKey1 );
270
+ verify (factoryMock , times (1 )).makeObject (singleKey1a );
271
+ verify (factoryMock , times (1 )).makeObject (singleKey2 );
272
+ verify (factoryMock , times (1 )).makeObject (multiKey1 );
273
+ verify (factoryMock , times (1 )).makeObject (multiKey2 );
274
+ pool .stopWork ();
275
+ pool .borrowObject (singleKey1 );
276
+ pool .borrowObject (singleKey1a );
277
+ pool .borrowObject (singleKey2 );
278
+ pool .borrowObject (multiKey1 );
279
+ pool .borrowObject (multiKey2 );
280
+ // After stopWork, we had to create new workers for the keys that got their pools destroyed.
281
+ verify (factoryMock , times (2 )).makeObject (singleKey1 );
282
+ verify (factoryMock , times (2 )).makeObject (singleKey1a );
283
+ verify (factoryMock , times (1 )).makeObject (singleKey2 );
284
+ verify (factoryMock , times (2 )).makeObject (multiKey1 );
285
+ verify (factoryMock , times (1 )).makeObject (multiKey2 );
286
+ }
241
287
}
0 commit comments