Commit 2206b7b2 authored by legoc's avatar legoc

The return of the server process

parent 8cc98f4a
......@@ -12,14 +12,26 @@
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-server-jeromq</artifactId>
<version>0.1.3</version>
<!-- <exclusions>
<exclusion>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-process-handle-default</artifactId>
</exclusion>
</exclusions> -->
</dependency>
<dependency>
<!-- <dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-process-handle-null</artifactId>
<version>0.0.1</version>
</dependency> -->
<dependency>
<groupId>fr.ill.ics</groupId>
<artifactId>cameo-api-java-jeromq</artifactId>
<version>0.1.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>../src/main/java</sourceDirectory>
</build>
......
package fr.ill.ics.cameo;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.util.ArrayList;
public class TestSelector {
public static Process startServer(String config) {
System.out.println("Starting server");
String jarFileName = "";
CodeSource codeSource = TestSelector.class.getProtectionDomain().getCodeSource();
try {
File jarFile = new File(codeSource.getLocation().toURI().getPath());
jarFileName = jarFile.toString();
} catch (URISyntaxException e1) {
e1.printStackTrace();
System.exit(1);
}
ArrayList<String> commandList = new ArrayList<String>();
commandList.add("java");
String javaLibraryPath = System.getProperty("java.library.path");
if (javaLibraryPath != null) {
commandList.add("-Djava.library.path=" + javaLibraryPath);
}
commandList.add("-classpath");
commandList.add(jarFileName);
commandList.add("fr.ill.ics.cameo.server.Server");
commandList.add(config);
// Prepare the command
String command[] = new String[commandList.size()];
commandList.toArray(command);
String serverCommand = "";
for (String c : command) {
serverCommand += c + " ";
}
System.out.println("Server command : " + serverCommand);
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
try {
System.out.println("Server started");
return builder.start();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void startApplication(Server server, String appName, String[] appArgs) {
Application.Instance instance = server.start(appName, appArgs, Option.OUTPUTSTREAM);
......@@ -44,15 +99,23 @@ public class TestSelector {
System.out.printf("Usage: <application name> <number of iterations>");
System.exit(1);
}
// Send the command.
Server server = new Server("tcp://localhost:10000");
int argsIndex = 0;
if (!server.isAvailable()) {
System.out.printf("Start the server before running the tests");
System.exit(1);
// Define the server process.
Process serverProcess = null;
// Start the server.
serverProcess = startServer(args[0]);
Server server = new Server("tcp://localhost:10000"); // change depending on config
if (server.isAvailable()) {
System.out.println("Server is available");
}
argsIndex = 1;
try {
boolean all = false;
String appName;
......@@ -74,7 +137,7 @@ public class TestSelector {
apps.add("startnpubcpp");
apps.add("startrepcpp");
if (args.length < 1) {
if (args.length < argsIndex + 1) {
System.out.println("Available applications:");
......@@ -85,15 +148,15 @@ public class TestSelector {
return;
}
else {
appName = args[0];
appName = args[argsIndex];
if (appName.equals("all")) {
all = true;
}
appArgs = new String[args.length - 1];
for (int i = 0; i < args.length - 1; ++i) {
appArgs[i] = args[i + 1];
appArgs = new String[args.length - 1 - argsIndex];
for (int i = 0; i < args.length - 1 - argsIndex; ++i) {
appArgs[i] = args[argsIndex + i + 1];
}
}
......@@ -111,6 +174,21 @@ public class TestSelector {
} finally {
// Terminate the server.
server.terminate();
// If the server process exists.
if (serverProcess != null) {
// Destroy the server process.
serverProcess.destroyForcibly();
// Waiting for the server that should not return without
// interruption.
try {
serverProcess.waitFor();
} catch (InterruptedException e) {
// Do nothing.
}
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment