+

Search Tips   |   Advanced Search

Create the Java Runtime API client


Example 1

In this example, we start a test with the scenario WANImpact Local and then we add Virtual Users to population MyPopulationSmallCities.

import com.neotys.rest.runtime.client.RuntimeAPIClient;
import com.neotys.rest.runtime.client.RuntimeAPIClientFactory;
import com.neotys.rest.runtime.model.AddVirtualUsersParams.AddVirtualUsersBuilder;
import com.neotys.rest.runtime.model.StartTestParams;
import com.neotys.rest.runtime.model.Status;

public class StartTestExample {
    public static void main(String[] args) throws Exception {
   	 final RuntimeAPIClient client = RuntimeAPIClientFactory.newClient("http://localhost:7400/Runtime/v1/Service.svc/");

   	 if (Status.READY.equals(client.getStatus())) {
   		 // make sure that NeoLoad is ready before running a test
   		 client.startTest(new StartTestParams.StartTestBuilder("WANImpact Local").build());

   		 do {
   			 // wait that the test is launched
   			 Thread.sleep(1000);
   		 } while (Status.TEST_LOADING.equals(client.getStatus()));

   		 if (Status.TEST_RUNNING.equals(client.getStatus())) {
   			 int added = client.addVirtualUsers(new AddVirtualUsersBuilder("MyPopulationSmallCities", 10).build());
   			 System.out.println(added + " users added");
   		 }
   	 }
    }
}


Example 2

In this example, we stop Virtual Users in the population MyPopulationSmallCities and then we stop the test itself.

import com.neotys.rest.runtime.client.RuntimeAPIClient;
import com.neotys.rest.runtime.client.RuntimeAPIClientFactory;
import com.neotys.rest.runtime.model.Status;
import com.neotys.rest.runtime.model.StopTestParams;
import com.neotys.rest.runtime.model.StopVirtualUsersParams.StopVirtualUsersBuilder;

public class StopTestExample {
    public static void main(String[] args) throws Exception {
   	 final RuntimeAPIClient client = RuntimeAPIClientFactory.newClient("http://localhost:7400/Runtime/v1/Service.svc/");

   	 // make sure a test is running
   	 if (Status.TEST_RUNNING.equals(client.getStatus())) {
   		 int stopped = client.stopVirtualUsers(new StopVirtualUsersBuilder("MyPopulationSmallCities", 5).build());
   		 System.out.println(stopped + " users stopped");

   		 Thread.sleep(10000);
   		 client.stopTest(new StopTestParams.StopTestBuilder().forceStop(false).build());
   	 }
    }
}


Home