Esempio n. 1
0
  @Test
  @Slow
  public void testServerSlowToRead() throws Exception {
    TrackingSocket tsocket = new TrackingSocket();
    client.setMasker(new ZeroMasker());
    client.getPolicy().setIdleTimeout(60000);

    URI wsUri = server.getWsUri();
    Future<Session> future = client.connect(tsocket, wsUri);

    ServerConnection sconnection = server.accept();
    sconnection.setSoTimeout(60000);
    sconnection.upgrade();

    // Confirm connected
    future.get(500, TimeUnit.MILLISECONDS);
    tsocket.waitForConnected(500, TimeUnit.MILLISECONDS);

    int messageCount = 10; // TODO: increase to 1000

    // Setup slow server read thread
    ServerReadThread reader = new ServerReadThread(sconnection);
    reader.setExpectedMessageCount(messageCount);
    reader.setSlowness(100); // slow it down
    reader.start();

    // Have client write as quickly as it can.
    ClientWriteThread writer = new ClientWriteThread(tsocket.getConnection());
    writer.setMessageCount(messageCount);
    writer.setMessage("Hello");
    writer.setSlowness(-1); // disable slowness
    writer.start();
    writer.join();

    // Verify receive
    reader.waitForExpectedMessageCount(10, TimeUnit.SECONDS);
    Assert.assertThat("Frame Receive Count", reader.getFrameCount(), is(messageCount));

    // Close
    tsocket.getConnection().close(StatusCode.NORMAL, "Done");

    Assert.assertTrue("Client Socket Closed", tsocket.closeLatch.await(10, TimeUnit.SECONDS));
    tsocket.assertCloseCode(StatusCode.NORMAL);

    reader.cancel(); // stop reading
  }
Esempio n. 2
0
  @Test
  @Slow
  public void testServerSlowToSend() throws Exception {
    // final Exchanger<String> exchanger = new Exchanger<String>();
    TrackingSocket tsocket = new TrackingSocket();
    // tsocket.messageExchanger = exchanger;
    client.setMasker(new ZeroMasker());
    client.getPolicy().setIdleTimeout(60000);

    URI wsUri = server.getWsUri();
    Future<Session> future = client.connect(tsocket, wsUri);

    ServerConnection sconnection = server.accept();
    sconnection.setSoTimeout(60000);
    sconnection.upgrade();

    // Confirm connected
    future.get(500, TimeUnit.MILLISECONDS);
    tsocket.waitForConnected(500, TimeUnit.MILLISECONDS);

    // Have server write slowly.
    int messageCount = 1000;

    ServerWriteThread writer = new ServerWriteThread(sconnection);
    writer.setMessageCount(messageCount);
    writer.setMessage("Hello");
    // writer.setExchanger(exchanger);
    writer.setSlowness(10);
    writer.start();
    writer.join();

    // Verify receive
    Assert.assertThat("Message Receive Count", tsocket.messageQueue.size(), is(messageCount));

    // Close
    sconnection.close(StatusCode.NORMAL);

    Assert.assertTrue("Client Socket Closed", tsocket.closeLatch.await(10, TimeUnit.SECONDS));
    tsocket.assertCloseCode(StatusCode.NORMAL);
  }