simplified idle tests
Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
80091f24a4
commit
fc5369a1de
|
@ -293,9 +293,9 @@ public class ByteArrayEndPointTest
|
||||||
assertEquals("test", BufferUtil.toString(buffer));
|
assertEquals("test", BufferUtil.toString(buffer));
|
||||||
|
|
||||||
// Wait for a read timeout.
|
// Wait for a read timeout.
|
||||||
|
long start = System.nanoTime();
|
||||||
fcb = new FutureCallback();
|
fcb = new FutureCallback();
|
||||||
endp.fillInterested(fcb);
|
endp.fillInterested(fcb);
|
||||||
long start = System.nanoTime();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fcb.get();
|
fcb.get();
|
||||||
|
@ -308,40 +308,5 @@ public class ByteArrayEndPointTest
|
||||||
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start), greaterThan(halfIdleTimeout));
|
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start), greaterThan(halfIdleTimeout));
|
||||||
assertThat("Endpoint open", endp.isOpen(), is(true));
|
assertThat("Endpoint open", endp.isOpen(), is(true));
|
||||||
|
|
||||||
// We need to delay the write timeout test below from the read timeout test above.
|
|
||||||
// The reason is that the scheduler thread that fails the endPoint WriteFlusher
|
|
||||||
// because of the read timeout above runs concurrently with the write below, and
|
|
||||||
// if it runs just after the write below, the test fails because the write callback
|
|
||||||
// below fails immediately rather than after the idle timeout.
|
|
||||||
Thread.sleep(halfIdleTimeout);
|
|
||||||
|
|
||||||
// Write more than the output capacity, then wait for idle timeout.
|
|
||||||
fcb = new FutureCallback();
|
|
||||||
start = System.nanoTime();
|
|
||||||
endp.write(fcb, BufferUtil.toBuffer("This is too long"));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
fcb.get();
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
catch (ExecutionException t)
|
|
||||||
{
|
|
||||||
assertThat(t.getCause(), instanceOf(TimeoutException.class));
|
|
||||||
}
|
|
||||||
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start), greaterThan(halfIdleTimeout));
|
|
||||||
// Still open because it has not been oshut or closed explicitly.
|
|
||||||
assertThat("Endpoint open", endp.isOpen(), is(true));
|
|
||||||
|
|
||||||
// Make sure the endPoint is closed when the callback fails.
|
|
||||||
endp.fillInterested(new Closer(endp));
|
|
||||||
Thread.sleep(halfIdleTimeout);
|
|
||||||
// Still open because it has not been oshut or closed explicitly.
|
|
||||||
assertThat("Endpoint open", endp.isOpen(), is(true));
|
|
||||||
|
|
||||||
// Shutdown output.
|
|
||||||
endp.shutdownOutput();
|
|
||||||
|
|
||||||
Thread.sleep(idleTimeout);
|
|
||||||
assertThat("Endpoint closed", endp.isOpen(), is(false));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -444,6 +444,8 @@ public class SelectChannelEndPointTest
|
||||||
server.configureBlocking(false);
|
server.configureBlocking(false);
|
||||||
|
|
||||||
_manager.accept(server);
|
_manager.accept(server);
|
||||||
|
Assert.assertTrue(_lastEndPointLatch.await(10, TimeUnit.SECONDS));
|
||||||
|
_lastEndPoint.setIdleTimeout(idleTimeout);
|
||||||
|
|
||||||
// Write client to server
|
// Write client to server
|
||||||
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
|
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
|
||||||
|
@ -457,14 +459,11 @@ public class SelectChannelEndPointTest
|
||||||
assertEquals(c, (char)b);
|
assertEquals(c, (char)b);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
|
|
||||||
_lastEndPoint.setIdleTimeout(idleTimeout);
|
|
||||||
|
|
||||||
// read until idle shutdown received
|
// read until idle shutdown received
|
||||||
int b = client.getInputStream().read();
|
int b = client.getInputStream().read();
|
||||||
assertEquals(-1, b);
|
assertEquals(-1, b);
|
||||||
long idle = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start;
|
long idle = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start;
|
||||||
assertThat(idle, greaterThan(idleTimeout / 2L));
|
assertThat(idle, greaterThan(idleTimeout - 100L));
|
||||||
assertThat(idle, lessThan(idleTimeout * 2L));
|
assertThat(idle, lessThan(idleTimeout * 2L));
|
||||||
|
|
||||||
// But endpoint may still be open for a little bit.
|
// But endpoint may still be open for a little bit.
|
||||||
|
|
Loading…
Reference in New Issue