Пример #1
0
 /** Helper method for main to load tests into a thread group and start each test case. */
 private static void loadThread(String name) {
   try {
     ThreadGroup myThreadGroup = new ThreadGroup(name);
     String urlSpec = "http://54.201.122.231:8181/v4/gumball";
     // String urlSpec = "http://localhost:8080/v4/gumball" ;
     RunLoadTest test = new RunLoadTest(myThreadGroup, urlSpec);
     test.runTest(); // Run The Test in its own thread
     myThreadGroup.list();
   } catch (Exception e) {
     System.out.println("ERROR: " + e.getMessage());
   }
 }
Пример #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");
    }
  }