HBASE-9564 Intermittent TestSimpleRpcScheduler#testHandlerIsolation failure

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1524415 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-09-18 13:53:50 +00:00
parent 886a96aed8
commit db0a4b2d07
1 changed files with 9 additions and 3 deletions

View File

@ -38,6 +38,7 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyObject;
@ -91,12 +92,16 @@ public class TestSimpleRpcScheduler {
replicationTask, HConstants.REPLICATION_QOS); replicationTask, HConstants.REPLICATION_QOS);
PriorityFunction qosFunction = mock(PriorityFunction.class); PriorityFunction qosFunction = mock(PriorityFunction.class);
final Map<CallRunner, Thread> handlerThreads = Maps.newHashMap(); final Map<CallRunner, Thread> handlerThreads = Maps.newHashMap();
final CountDownLatch countDownLatch = new CountDownLatch(tasks.size());
Answer<Void> answerToRun = new Answer<Void>() { Answer<Void> answerToRun = new Answer<Void>() {
@Override @Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable { public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
handlerThreads.put( synchronized (handlerThreads) {
(CallRunner) invocationOnMock.getMock(), handlerThreads.put(
Thread.currentThread()); (CallRunner) invocationOnMock.getMock(),
Thread.currentThread());
}
countDownLatch.countDown();
return null; return null;
} }
}; };
@ -119,6 +124,7 @@ public class TestSimpleRpcScheduler {
scheduler.stop(); scheduler.stop();
// Tests that these requests are handled by three distinct threads. // Tests that these requests are handled by three distinct threads.
countDownLatch.await();
assertEquals(3, ImmutableSet.copyOf(handlerThreads.values()).size()); assertEquals(3, ImmutableSet.copyOf(handlerThreads.values()).size());
} }