Esempio n. 1
0
  @Test(timeOut = 20000)
  public void checkPingTimeout() throws Exception {
    set(ping, "firstConnectionTimeout", 500000);

    ping.start(port, firstConnectionTimeout, testTimeout);

    do {
      Thread.yield();
      Thread.sleep(100);
    } while (!ThreadStatus.STARTED.equals(ping.getStatus()));

    Socket s = new Socket("localhost", port);
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

    String request = in.readLine();
    assertEquals(request, STATUS);

    do {
      Thread.yield();
      Thread.sleep(100);
    } while (!ThreadStatus.ERROR.equals(ping.getStatus()));

    assertEquals(ping.getError().getClass(), SocketTimeoutException.class);

    s.close();
  }
Esempio n. 2
0
  @Test(timeOut = 20000, invocationCount = 10)
  public void checkPing() throws Exception {
    set(ping, "firstConnectionTimeout", 500000);
    set(ping, "testTimeout", 100000);

    ping.start(port, firstConnectionTimeout, testTimeout);

    do {
      Thread.yield();
      Thread.sleep(100);
    } while (!ThreadStatus.STARTED.equals(ping.getStatus()));

    Socket s = new Socket("localhost", port);
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    OutputStream out = s.getOutputStream();

    String request = in.readLine();
    assertEquals(request, STATUS);
    IOUtil.copy(OK + EOL, out);

    request = in.readLine();
    assertEquals(request, STATUS);
    IOUtil.copy(OK + EOL, out);

    request = in.readLine();
    assertEquals(request, STATUS);
    IOUtil.copy(OK + EOL, out);

    request = in.readLine();
    assertEquals(request, STATUS);
    IOUtil.copy(FINISHED + EOL, out);

    do {
      Thread.yield();
      Thread.sleep(100);
    } while (!ThreadStatus.DONE.equals(ping.getStatus()));

    s.close();
  }