Esempio n. 1
0
  /**
   * In a situation where the upgrade/connection is successfull, and there is no activity for a
   * while, the idle timeout triggers on the client side and automatically initiates a close
   * handshake.
   */
  @Test
  public void testIdleDetectedByClient() throws Exception {
    TrackingSocket wsocket = new TrackingSocket();

    WebSocketClient client = factory.newWebSocketClient(wsocket);

    URI wsUri = server.getWsUri();
    Future<UpgradeResponse> future = client.connect(wsUri);

    ServerConnection ssocket = server.accept();
    ssocket.upgrade();

    // Validate that connect occurred
    future.get(500, TimeUnit.MILLISECONDS);
    wsocket.waitForConnected(500, TimeUnit.MILLISECONDS);

    // Wait for inactivity idle timeout.
    long start = System.currentTimeMillis();
    wsocket.waitForClose(10, TimeUnit.SECONDS);
    long end = System.currentTimeMillis();
    long dur = (end - start);
    // Make sure idle timeout takes less than 5 total seconds
    Assert.assertThat("Idle Timeout", dur, lessThanOrEqualTo(5000L));

    // Client should see a close event, with status NO_CLOSE
    wsocket.assertCloseCode(StatusCode.NORMAL);
  }
Esempio n. 2
0
 @After
 public void stopFactory() throws Exception {
   factory.stop();
 }
Esempio n. 3
0
 @Before
 public void startFactory() throws Exception {
   factory = new WebSocketClientFactory();
   factory.getPolicy().setIdleTimeout(250); // idle timeout (for all tests here)
   factory.start();
 }