Java client
To use our Java API to start or stop tests onto NeoLoad, use our classes as explained in Create the Java Runtime API client.
First instantiate a RuntimeAPIClient
providing a URL and API key.
Then call the method available:
-
GetStatus()
to get the current status of NeoLoad, -
StartTest()
to start a test, -
StopTest()
to stop a test, -
AddVirtualUsers()
to add Virtual Users instances, -
StopVirtualUsers()
to stop Virtual Users instances, -
StartInfrastructures()
to start infrastructures, -
StopInfrastructures()
to stop infrastructures, -
GetInfrastructuresStatus()
to get the current status of the infrastructures.
Configure the project
To configure your Java project, it is recommended to use Maven.
Maven projects
In a Java Maven project, you need to add a dependency to the Maven settings file (pom.xml) using the examples below.
Repository:
<repositories>
<repository>
<id>neotys-public-releases</id>
<url>http://maven.neotys.com/content/repositories/releases/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
Dependency:
<dependencies>
<dependency>
<groupId>com.neotys.rest</groupId>
<artifactId>neotys-rest-api-runtime-client-olingo</artifactId>
<version>1.0.6</version>
</dependency>
</dependencies>
Non-Maven projects
If your project is not developed using Maven, it is necessary to include the JAR files available in the \api
folder of the NeoLoad installation directory:
- in the
<install-dir>
\apiRuntime API Client\Java
folder - in the
<install-dir>
\api\Common\Java
folder
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.
-
we override variable "
name
" with value "value
"
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.ExecutionContext;
import com.neotys.rest.runtime.model.StartTestParams;
import com.neotys.rest.runtime.model.StartTestInfo;
import com.neotys.rest.runtime.model.Status;
public class StartTestExample {
public static void main(String[] args) throws Exception {
final RuntimeAPIClient client;
try {
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
final StartTestInfo startTestInfo = client.startTest(new StartTestParams.StartTestBuilder("scenario1")
.nlweb(true)
.build());
System.out.println(startTestInfo);
do {
// wait that the test is launched
Thread.sleep(1000);
} while (Status.TEST_LOADING.equals(client.getStatus()));
if (Status.TEST_RUNNING.equals(client.getStatus())) {
//TODO
}
} else {
System.out.println(client.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
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());
}
}
}