Esempio n. 1
0
  /** Creates a thread and runs a test case */
  public void runTest() {
    // anonymous inner class for thread target
    Thread myThread =
        new Thread(
            this.myGroup,
            new Runnable() {
              public void run() {
                while (!RunLoadTest.isOutOfTime()) {
                  doTest();
                  try {
                    Thread.sleep(500);
                  } catch (InterruptedException e) {
                    System.out.println(e.getMessage());
                  }
                }
                System.out.println("Test " + myGroup + " Stopped! ==> " + reqCount + " Runs.");
              }
            });

    myThread.start();
  }
Esempio n. 2
0
  /**
   * Performs a test by sending HTTP Gets to the URL, and records the number of bytes returned. Each
   * test results are documented and displayed in standard out with the following information:
   *
   * <p>URL - The source URL of the test REQ CNT - How many times this test has run START - The
   * start time of the last test run STOP - The stop time of the last test run THREAD - The thread
   * id handling this test case RESULT - The result of the test. Either the number of bytes returned
   * or an error message.
   */
  private void doTest() {
    String result = "";
    this.reqCount++;

    // Connect and run test steps
    Date startTime = new Date();
    try {
      ClientResource client = new ClientResource(this.myURL);

      // place order
      JSONObject json = new JSONObject();
      json.put("payment", "quarter");
      json.put("action", "place-order");
      client.post(new JsonRepresentation(json), MediaType.APPLICATION_JSON);

      // Get Gumball Count
      Representation result_string = client.get();
      JSONObject json_count = new JSONObject(result_string.getText());
      result = Integer.toString((int) json_count.get("count"));
    } catch (Exception e) {
      result = e.toString();
    } finally {
      Date stopTime = new Date();
      // Print Report of Result:
      System.out.println(
          "======================================\n"
              + "URL     => "
              + this.myURL
              + "\n"
              + "REQ CNT => "
              + this.reqCount
              + "\n"
              + "START   => "
              + startTime
              + "\n"
              + "STOP    => "
              + stopTime
              + "\n"
              + "THREAD  => "
              + Thread.currentThread().getName()
              + "\n"
              + "RESULT  => "
              + result
              + "\n");
    }
  }