YARN-5857. TestLogAggregationService.testFixedSizeThreadPool fails intermittently on trunk. Contributed by Bilwa S T.

This commit is contained in:
bibinchundatt 2019-08-21 17:14:42 +05:30
parent 10ec31d20e
commit e684b17e6f
1 changed files with 6 additions and 1 deletions

View File

@ -58,6 +58,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -1215,6 +1216,8 @@ public void testFixedSizeThreadPool() throws Exception {
ExecutorService executorService = logAggregationService.threadPool;
CountDownLatch latch = new CountDownLatch(threadPoolSize);
// used to block threads in the thread pool because main thread always
// acquires the write lock first.
final ReadWriteLock rwLock = new ReentrantReadWriteLock();
@ -1227,8 +1230,9 @@ public void testFixedSizeThreadPool() throws Exception {
@Override
public void run() {
try {
latch.countDown();
// threads in the thread pool running this will be blocked
rLock.tryLock(35000, TimeUnit.MILLISECONDS);
rLock.tryLock(15000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
@ -1244,6 +1248,7 @@ public void run() {
executorService.submit(runnable);
}
latch.await();
// count the number of current running LogAggregationService threads
int runningThread = ((ThreadPoolExecutor) executorService).getActiveCount();
assertEquals(threadPoolSize, runningThread);