Refactoring ConcurrentOpenSocketFinderTest.testChecksSocketsConcurrently to try to prevent timeouts

This commit is contained in:
Andrew Phillips 2012-11-27 21:06:23 -05:00
parent e5a4dd4e76
commit 19952dec47
1 changed files with 2 additions and 9 deletions

View File

@ -111,25 +111,18 @@ public class ConcurrentOpenSocketFinderTest {
@Test
public void testChecksSocketsConcurrently() throws Exception {
long delayForReachableMs = 25;
expect(nodeRunning.apply(EasyMock.<AtomicReference<NodeMetadata>>anyObject())).andReturn(true);
replay(nodeRunning);
// Can't use mock+answer for concurrency tests; EasyMock uses lock in ReplayState
ControllableSocketOpen socketTester = new ControllableSocketOpen(ImmutableMap.of(
HostAndPort.fromParts("1.2.3.4", 22), new SlowCallable<Boolean>(false, 1000),
HostAndPort.fromParts("1.2.3.5", 22), new SlowCallable<Boolean>(true, delayForReachableMs)));
HostAndPort.fromParts("1.2.3.4", 22), new SlowCallable<Boolean>(true, 1500),
HostAndPort.fromParts("1.2.3.5", 22), new SlowCallable<Boolean>(true, 1000)));
OpenSocketFinder finder = new ConcurrentOpenSocketFinder(socketTester, null, threadPool);
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
HostAndPort result = finder.findOpenSocketOnNode(node, 22, 2000, TimeUnit.MILLISECONDS);
long timetaken = stopwatch.elapsedMillis();
assertEquals(result, HostAndPort.fromParts("1.2.3.5", 22));
assertTrue(timetaken >= delayForReachableMs-EARLY_GRACE && timetaken <= delayForReachableMs+SLOW_GRACE, "timetaken="+timetaken);
verify(node);
}