Commit ce8c34c1 authored by legoc's avatar legoc

Changed non sync subscriber and publisher test

parent 361cf382
......@@ -121,7 +121,7 @@
</application>
<application name="startnpubjava" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath cameo-tests-jeromq/target/cameo-tests-jeromq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication npubjava 10"/>
<start executable="java" args="-classpath cameo-tests-jeromq/target/cameo-tests-jeromq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication nsubjava"/>
</application>
<application name="startrepjava" starting_time="inf" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
......
......@@ -121,7 +121,7 @@
</application>
<application name="startnpubjava" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication nsubjava 10"/>
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication nsubjava"/>
</application>
<application name="startrepjava" starting_time="inf" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
......
......@@ -114,7 +114,7 @@
</application>
<application name="startnpubjava" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="java" args="-Djava.library.path=C:/Users/legoc/Documents/zeromq-4.0.5/java/lib -classpath target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication nsubjava 10"/>
<start executable="java" args="-Djava.library.path=C:/Users/legoc/Documents/zeromq-4.0.5/java/lib -classpath target/cameo-tests-jzmq-0.0.1-full.jar fr.ill.ics.cameo.test.TestNonSyncSubscribersAndPublisherApplication nsubjava"/>
</application>
<application name="startrepjava" starting_time="inf" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
......
......@@ -36,15 +36,17 @@ public class TestNonSyncSubscribersAndPublisherApplication {
Application.This.init(args);
String applicationName = null;
String subscriberApplicationName = null;
int N = 1;
if (args.length > 2) {
applicationName = args[0];
subscriberApplicationName = args[0];
N = Integer.parseInt(args[1]);
System.out.println("subscriber application is " + applicationName);
System.out.println("subscriber application is " + subscriberApplicationName);
System.out.println("loops = " + N);
} else {
System.err.println("arguments: [subscriber application name] [number of subscribers]");
System.err.println("arguments: [subscriber application name] [number of loops]");
System.exit(-1);
}
......@@ -61,47 +63,61 @@ public class TestNonSyncSubscribersAndPublisherApplication {
try {
for (int i = 0; i < N; i++) {
// pass the name of the application in argument
String[] applicationArgs = {Application.This.getName()};
// start the subscriber applications that can subscribe whereas the publisher is not created
Application.Instance subscriberApplication = server.start(applicationName, applicationArgs);
System.out.println("iteration " + i);
if (subscriberApplication.exists()) {
System.out.println("started application " + subscriberApplication);
}
else {
System.out.println("cannot start subscriber application");
// Create 5 subscribers.
for (int s = 0; s < 5; ++s) {
// pass the name of the application in argument
String[] applicationArgs = {Application.This.getName()};
// start the subscriber applications that can subscribe whereas the publisher is not created
Application.Instance subscriberApplication = server.start(subscriberApplicationName, applicationArgs);
if (subscriberApplication.exists()) {
System.out.println("started application " + subscriberApplication);
}
else {
System.out.println("cannot start subscriber application");
}
}
}
// the publisher is created after the applications that will wait for it
Application.Publisher publisher = Application.Publisher.create("publisher");
int j = 0;
while (j < 20) {
int[] data = {j, j * j};
publisher.send(data);
System.out.println("sent " + data[0] + ", " + data[1]);
// the publisher is created after the applications that will wait for it
Application.Publisher publisher = Application.Publisher.create("publisher");
// Wait 100ms.
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
j++;
}
// the publisher must terminate so that the subscriber applications receive end of stream
publisher.terminate();
// wait for the end of the applications
List<Application.Instance> subscriberApplications = server.connectAll(applicationName);
for (Application.Instance subscriberApplication : subscriberApplications) {
subscriberApplication.waitFor();
int j = 0;
while (j < 20) {
int[] data = {j, j * j};
publisher.send(data);
System.out.println("sent " + data[0] + ", " + data[1]);
j++;
}
// The publisher must terminate so that the subscriber applications receive end of stream.
// However the subscribers may not be connected.
System.out.println("Terminating the publisher");
publisher.terminate();
System.out.println("Terminated the publisher");
// So we must kill all the subscribers
List<Application.Instance> subscriberApplications = server.connectAll(subscriberApplicationName);
for (Application.Instance subscriberApplication : subscriberApplications) {
subscriberApplication.kill();
subscriberApplication.waitFor();
System.out.println("Killed " + subscriberApplication);
}
}
} catch (ConnectionTimeout e) {
......
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