executorServiceFront.execute(task1);
executorServiceFront.execute(task2);
ThreadHelper threadHelper = new ThreadHelper();
// ie, we'll want two physical threads
LoopThread drainerThread1 = createDrainerThread(threadHelper);
LoopThread drainerThread2 = createDrainerThread(threadHelper);
// this waits for both tasks to get into a Drainer. Two tasks that pause immediately and
// two drainers => we get 1 task per drainer
while (!workQueue.isEmpty()) {
Thread.sleep(50);
}
// check that the names change according to our ESF
Assert.assertEquals(drainerThread1.getName(), "custom-name-000");
task1.proceed();
task1.await();
Assert.assertEquals(drainerThread2.getName(), "custom-name-001");
task2.proceed();
task2.await();
drainerThread1.join();
drainerThread2.join();
// and that the 'base name' of the borrowed threads is restored
Assert.assertEquals(drainerThread1.getName(), "drainer");
Assert.assertEquals(drainerThread2.getName(), "drainer");
}