Commit 263a8b46 authored by legoc's avatar legoc

Test stream for C++ and Java

parent 3d63fb55
......@@ -105,6 +105,7 @@ public class TestSelector {
apps.add("testrequesterjava");
apps.add("testcanceljava");
apps.add("testcomportjava");
apps.add("teststreamjava");
return apps;
}
......@@ -125,6 +126,7 @@ public class TestSelector {
apps.add("testrequestercpp");
apps.add("testcancelcpp");
apps.add("testcomportcpp");
apps.add("teststreamcpp");
return apps;
}
......
......@@ -37,13 +37,13 @@ public class Stop {
@Override
public void handle() {
stopping = true;
System.out.println("stop handler executed");
System.out.println("Stop handler executed");
}
});
int i = 0;
while (!stopping) {
System.out.println("waiting " + i + "...");
System.out.println("Waiting " + i + "...");
Thread.sleep(100);
i++;
}
......@@ -55,7 +55,7 @@ public class Stop {
Application.This.setResult(result);
System.out.println("finished the application");
System.out.println("Finished the application");
}
catch (Throwable e) {
e.printStackTrace();
......
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
import fr.ill.ics.cameo.Application;
public class Stream {
public static void main(String[] args) {
Application.This.init(args);
int i = 0;
while (i < 20) {
System.out.println("Printing " + i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
i++;
}
System.out.println("Finished the application");
Application.This.terminate();
}
}
\ No newline at end of file
......@@ -32,48 +32,42 @@ public class TestStop {
numberOfTimes = Integer.parseInt(args[0]);
}
if (Application.This.isAvailable() && server.isAvailable()) {
System.out.println("application connected");
} else {
System.exit(-1);
}
try {
// loop the number of times.
// Loop the number of times.
for (int i = 0; i < numberOfTimes; ++i) {
// start the application
// Start the application.
Application.Instance stopApplication = server.start("stopjava");
System.out.println("waiting 100ms...");
// stop the application after 1s
System.out.println("Waiting 100ms...");
// Stop the application after 1s.
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.out.println("stopping application " + stopApplication.getNameId());
System.out.println("Stopping application " + stopApplication.getNameId());
stopApplication.stop();
// the getString is blocking until the application finishes
// The call is blocking until the application finishes.
String result = stopApplication.getStringResult();
if (result != null) {
System.out.println("stop application returned " + result);
System.out.println("Stop application returned " + result);
} else {
System.out.println("stop application has no result");
System.out.println("Stop application has no result");
}
System.out.println("stop application finished");
System.out.println("Stop application finished");
}
} finally {
// do not forget to terminate the server and application
Application.This.terminate();
}
System.out.println("finished the application");
System.out.println("Finished the application");
}
}
\ No newline at end of file
/*
* Copyright 2015 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.cameo.test;
import fr.ill.ics.cameo.Application;
import fr.ill.ics.cameo.Application.Output;
import fr.ill.ics.cameo.Option;
import fr.ill.ics.cameo.OutputStreamSocket;
import fr.ill.ics.cameo.Server;
public class TestStream {
public static void main(String[] args) {
Application.This.init(args);
Server server = Application.This.getServer();
// Start the application.
Application.Instance app = server.start("streamjava", Option.OUTPUTSTREAM);
OutputStreamSocket socket = app.getOutputStreamSocket();
// Start thread.
Thread outputThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Output output = socket.receive();
if (output != null) {
System.out.println(output.getMessage());
}
else {
return;
}
}
}
});
outputThread.start();
// Wait before canceling output.
try {
Thread.sleep(1000);
System.out.println("Canceling output");
socket.cancel();
outputThread.join();
} catch (InterruptedException e) {
}
app.waitFor();
Application.This.terminate();
System.out.println("Finished the application");
}
}
\ No newline at end of file
......@@ -105,6 +105,14 @@
<application name="testcomportjava" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.TestComPort"/>
</application>
<application name="streamjava" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.Stream"/>
</application>
<application name="teststreamjava" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.TestStream"/>
</application>
<!-- C++ apps -->
......
......@@ -32,7 +32,7 @@ int main(int argc, char *argv[]) {
application::This::setRunning();
int i = 0;
while (i < 40) {
while (i < 20) {
cout << "Printing " << i << endl;
this_thread::sleep_for(chrono::milliseconds(100));
i++;
......
......@@ -14,11 +14,8 @@
* limitations under the Licence.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cameo/cameo.h>
#include <iostream>
using namespace std;
using namespace cameo;
......@@ -26,9 +23,9 @@ using namespace cameo;
void printOutput(shared_ptr<OutputStreamSocket> socket) {
while (true) {
Output output;
if (socket->receive(output)) {
cout << output.getMessage() << endl;
optional<Output> output = socket->receive();
if (output) {
cout << output.value().getMessage() << endl;
}
else {
return;
......@@ -50,7 +47,7 @@ int main(int argc, char *argv[]) {
shared_ptr<OutputStreamSocket> socket = app->getOutputStreamSocket();
std::thread outputThread(std::bind(printOutput, socket));
this_thread::sleep_for(chrono::seconds(2));
this_thread::sleep_for(chrono::seconds(1));
cout << "Canceling output" << endl;
socket->cancel();
......
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