Commit 000e75bb authored by legoc's avatar legoc

Test responder renamed

parent 518243d1
......@@ -18,7 +18,7 @@ if (NOT DEFINED CMAKE_CXX_STANDARD)
endif()
find_package(cameo 1.1.0 REQUIRED)
find_package(cameo 1.1 REQUIRED)
#------------------------------------------------------------
# Programs
......@@ -77,6 +77,11 @@ target_link_libraries(subscriber PUBLIC cameo zmq)
add_executable(testsubscriber src/tests/TestSubscriber.cpp)
target_link_libraries(testsubscriber PUBLIC cameo zmq)
add_executable(responder src/tests/Responder.cpp)
target_link_libraries(responder PUBLIC cameo zmq)
add_executable(testresponder src/tests/TestResponder.cpp)
target_link_libraries(testresponder PUBLIC cameo zmq)
......@@ -114,11 +119,6 @@ target_link_libraries(testsubscriberandpublishertwo PUBLIC cameo zmq)
add_executable(testpublisherloop src/tests/TestPublisherLoopApplication.cpp)
target_link_libraries(testpublisherloop PUBLIC cameo zmq)
add_executable(testresponder src/tests/TestResponderApplication.cpp)
target_link_libraries(testresponder PUBLIC cameo zmq)
add_executable(testrequesterandresponder src/tests/TestRequesterAndResponderApplication.cpp)
target_link_libraries(testrequesterandresponder PUBLIC cameo zmq)
add_executable(testcancel src/tests/TestCancelApplication.cpp)
target_link_libraries(testcancel PUBLIC cameo zmq pthread)
......
......@@ -10,7 +10,7 @@ public class TestSelector {
public static Process startServer(String config) {
System.out.println("Starting server");
System.out.println("*** Starting server ***");
String jarFileName = "";
......@@ -44,7 +44,7 @@ public class TestSelector {
builder.redirectErrorStream(true);
try {
System.out.println("Server started");
System.out.println("*** Server started ***");
return builder.start();
}
catch (IOException e) {
......@@ -67,7 +67,7 @@ public class TestSelector {
// The socket can be null if the application is already terminated.
if (streamSocket == null) {
System.out.println("The application " + instance.getNameId() + " has no output stream.");
System.out.println("*** The application " + instance.getNameId() + " has no output stream ***");
}
else {
outputThread = new OutputPrintThread(streamSocket);
......@@ -85,7 +85,7 @@ public class TestSelector {
System.out.println("*** Finished test application ***");
}
else {
System.out.println("No application");
System.out.println("*** No application ***");
}
}
......@@ -107,7 +107,7 @@ public class TestSelector {
Server server = new Server("tcp://localhost:10000"); // change depending on config
if (server.isAvailable()) {
System.out.println("Server is available");
System.out.println("*** Server is available ***");
}
argsIndex = 1;
......@@ -121,7 +121,7 @@ public class TestSelector {
if (args.length < argsIndex + 1) {
System.out.println("Available applications:");
System.out.println("*** Available applications ***");
for (String app : apps) {
System.out.println("\t" + app);
......@@ -142,8 +142,7 @@ public class TestSelector {
apps.add("testwaitstoragejava");
apps.add("testpublisherjava");
apps.add("testsubscriberjava");
apps.add("startrepjava");
apps.add("testresponderjava");
apps.add("startreqjava");
apps.add("canceljava");
......@@ -157,8 +156,8 @@ public class TestSelector {
apps.add("testwaitstoragecpp");
apps.add("testpublishercpp");
apps.add("testsubscribercpp");
apps.add("testrespondercpp");
apps.add("startrepcpp");
apps.add("cancelcpp");
......@@ -169,6 +168,7 @@ public class TestSelector {
apps.add("testerrorpy");
apps.add("testpublisherpy");
apps.add("testsubscriberpy");
apps.add("testresponderpy");
}
else if (appName.equals("java")) {
apps.add("testsimplejava");
......@@ -180,8 +180,8 @@ public class TestSelector {
apps.add("testwaitstoragejava");
apps.add("testpublisherjava");
apps.add("testsubscriberjava");
apps.add("testresponderjava");
apps.add("startrepjava");
apps.add("startreqjava");
apps.add("canceljava");
}
......@@ -195,8 +195,8 @@ public class TestSelector {
apps.add("testwaitstoragecpp");
apps.add("testpublishercpp");
apps.add("testsubscribercpp");
apps.add("testrespondercpp");
apps.add("startrepcpp");
apps.add("cancelcpp");
}
else if (appName.equals("python")) {
......@@ -207,6 +207,7 @@ public class TestSelector {
apps.add("testerrorpy");
apps.add("testpublisherpy");
apps.add("testsubscriberpy");
apps.add("testresponderpy");
}
else {
apps.add(appName);
......
......@@ -21,18 +21,14 @@ import fr.ill.ics.cameo.RemoteException;
import fr.ill.ics.cameo.messages.Message;
public class TestResponderApplication {
public class Responder {
public static void main(String[] args) {
Application.This.init(args);
if (Application.This.isAvailable()) {
System.out.println("connected");
}
try {
System.out.println("creating responder");
System.out.println("Creating responder");
// Create the responder.
Application.Responder responder = Application.Responder.create("responder");
......@@ -43,7 +39,7 @@ public class TestResponderApplication {
// Receive the first request.
Application.Request request = responder.receive();
System.out.println("received request " + request.get());
System.out.println("Received request " + request.get());
// Reply.
request.reply("1st response");
......@@ -53,7 +49,7 @@ public class TestResponderApplication {
request = responder.receive();
byte[][] data = request.getTwoBinaryParts();
System.out.println("received request " + Message.parseString(data[0]) + " " + Message.parseString(data[1]));
System.out.println("Received request " + Message.parseString(data[0]) + " " + Message.parseString(data[1]));
// Reply.
request.reply("2nd response");
......@@ -61,7 +57,7 @@ public class TestResponderApplication {
// Receive the third request.
request = responder.receive();
System.out.println("received request " + request.get());
System.out.println("Received request " + request.get());
// Reply.
//request.setTimeout(100);
......@@ -71,7 +67,7 @@ public class TestResponderApplication {
// Receive the fourth request.
request = responder.receive();
System.out.println("received request " + request.get());
System.out.println("Received request " + request.get());
// Reply.
request.reply("4th response");
......@@ -80,19 +76,18 @@ public class TestResponderApplication {
// Test connection.
Application.Instance requester = request.connectToRequester();
System.out.println("requester is " + requester);
System.out.println("Requester is " + requester);
request.terminate();
} catch (RemoteException e) {
System.out.println("responder error");
System.out.println("Responder error");
} finally {
// Do not forget to terminate This.
Application.This.terminate();
}
System.out.println("finished the application");
System.out.println("Finished the application");
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ import fr.ill.ics.cameo.Server;
import fr.ill.ics.cameo.messages.Message;
public class TestRequesterAndResponderApplication {
public class TestResponder {
public static void main(String[] args) {
......@@ -33,51 +33,43 @@ public class TestRequesterAndResponderApplication {
if (args.length > 1) {
applicationName = args[0];
System.out.println("responder application is " + applicationName);
System.out.println("Responder application is " + applicationName);
if (args.length > 2) {
numberOfTimes = Integer.parseInt(args[1]);
}
} else {
System.err.println("arguments: [application name]");
System.err.println("Arguments: [application name]");
System.exit(-1);
}
// get the client services
Server server = Application.This.getServer();
if (Application.This.isAvailable() && server.isAvailable()) {
System.out.println("connected application");
System.out.println("connected server " + server);
} 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.
Application.Instance responderApplication = server.start(applicationName);
System.out.println("started application " + responderApplication + " with state " + Application.State.toString(responderApplication.getActualState()));
System.out.println("Started application " + responderApplication + " with state " + Application.State.toString(responderApplication.getActualState()));
Application.Requester requester = Application.Requester.create(responderApplication, "responder");
System.out.println("created requester " + requester);
System.out.println("Created requester " + requester);
// Check the state of the responder app.
System.out.println("application " + responderApplication + " has state " + Application.State.toString(responderApplication.getActualState()));
System.out.println("Application " + responderApplication + " has state " + Application.State.toString(responderApplication.getActualState()));
// Send a simple message.
requester.send("request");
System.out.println("response is " + requester.receiveString());
System.out.println("Response is " + requester.receiveString());
// Send a two-parts message.
requester.sendTwoParts(Message.serialize("first"), Message.serialize("second"));
System.out.println("response is " + requester.receiveString());
System.out.println("Response is " + requester.receiveString());
// Send a simple message.
......@@ -89,30 +81,29 @@ public class TestRequesterAndResponderApplication {
} catch (InterruptedException e) {
}
System.out.println("response is " + requester.receiveString());
System.out.println("Response is " + requester.receiveString());
// Send a simple message.
requester.send("request");
System.out.println("response is " + requester.receiveString());
System.out.println("Response is " + requester.receiveString());
int state = responderApplication.waitFor();
System.out.println("responder application terminated with state " + Application.State.toString(state));
System.out.println("Responder application terminated with state " + Application.State.toString(state));
// Terminate the requester.
requester.terminate();
}
} catch (RemoteException e) {
System.out.println("requester error:" + e);
System.out.println("Requester error:" + e);
} finally {
// Do not forget to terminate This.
Application.This.terminate();
}
System.out.println("finished the application");
System.out.println("Finished the application");
}
}
\ No newline at end of file
......@@ -101,6 +101,13 @@
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.TestSubscriber subscriberjava"/>
</application>
<application name="responderjava" starting_time="inf" 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.Responder"/>
</application>
<application name="testresponderjava" starting_time="inf" 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.TestResponder responderjava"/>
</application>
......@@ -145,9 +152,6 @@
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.TestCancelApplication"/>
</application>
<application name="repjava" starting_time="inf" 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.TestResponderApplication"/>
</application>
<application name="reqrepjava" starting_time="inf" 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.TestRequesterAndResponderApplication"/>
......@@ -165,10 +169,6 @@
<start executable="java" args="-classpath cameo-tests-jzmq/target/cameo-tests-jzmq-full.jar fr.ill.ics.cameo.test.TestConnectionCheckerApplication"/>
</application>
<application name="startrepjava" starting_time="inf" 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.TestRequesterAndResponderApplication repjava"/>
</application>
<application name="startendpointjava" starting_time="inf" 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.TestEndpoint"/>
</application>
......@@ -263,6 +263,16 @@
<start executable="testsubscriber" args="subscribercpp"/>
</application>
<application name="respondercpp" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="responder"/>
</application>
<application name="testrespondercpp" starting_time="0" stopping_time="1" output_stream="yes" multiple="no" restart="no">
<start executable="testresponder" args="respondercpp"/>
</application>
......@@ -295,10 +305,6 @@
<start executable="testcancel"/>
</application>
<application name="repcpp" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="testresponder"/>
</application>
<application name="reqrepcpp" starting_time="0" stopping_time="1" output_stream="yes" multiple="no" restart="no">
<start executable="testrequesterandresponder"/>
</application>
......@@ -325,10 +331,6 @@
<application name="startrepcpp" starting_time="0" stopping_time="1" output_stream="yes" multiple="no" restart="no">
<start executable="testrequesterandresponder" args="repcpp"/>
</application>
<application name="reqcppt" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="testrequestertimeout"/>
</application>
......@@ -412,6 +414,15 @@
<start executable="testsubscriber.py" args="subscriberpy"/>
</application>
<application name="responderpy" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="yes" restart="no">
<start executable="responder.py"/>
</application>
<application name="testresponderpy" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="testresponder.py" args="responderpy"/>
</application>
<!-- Test apps -->
......
#!/usr/bin/python3 -u
import sys
import cameopy
this = cameopy.This
this.init(sys.argv)
print("Creating responder")
responder = cameopy.Responder.create("responder")
this.setRunning()
# Receive first request.
request = responder.receive();
print("Received request", request.get())
request.reply("1st response")
# Receive second request.
request = responder.receive();
print("Received request with parts", request.get(), request.getSecondBinaryPart())
request.reply("2nd response")
# Receive third request without receive on the requester side.
request = responder.receive();
print("Received request", request.get())
# Reply with timeout.
request.setTimeout(100)
res = request.reply("3rd response")
if not res:
print("Timeout with", request.getObjectId())
# Receive request after timeout.
request = responder.receive();
print("Received request", request.get())
request.reply("4th response after timeout")
print("Finished the application")
#!/usr/bin/python3 -u
import sys
import time
import cameopy
applicationName = ""
numberOfTimes = 1
if len(sys.argv) >= 3:
applicationName = sys.argv[1]
if len(sys.argv) >= 4:
numberOfTimes = int(sys.argv[2])
print("Responder application is", applicationName)
this = cameopy.This
this.init(sys.argv)
server = this.getServer()
for i in range(numberOfTimes):
app = server.start(applicationName, 0)
print("Started application", applicationName)
requester = cameopy.Requester.create(app, "responder")
# Send a simple message.
requester.send("request")
response = requester.receive()
print("Response is", response)
# Send a two-parts message.
requester.sendTwoBinaryParts("first", "second")
response = requester.receive()
print("Response is", response)
# Send a simple message but do not receive the response immediately.
requester.send("request");
print("Wait so that the responder has timed out")
time.sleep(1)
response = requester.receive()
print("Response is", response)
# Send a new simple message.
requester.send("request after timeout")
response = requester.receive()
print("Response is", response)
# Wait for the application.
app.waitFor()
print("Finished the application")
\ No newline at end of file
......@@ -14,11 +14,9 @@
* limitations under the Licence.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cameo/cameo.h>
#include <iostream>
using namespace std;
using namespace cameo;
......@@ -29,57 +27,50 @@ int main(int argc, char *argv[]) {
// New block to ensure cameo objects are terminated before the application.
{
if (application::This::isAvailable()) {
cout << "connected" << endl;
}
unique_ptr<application::Responder> responder;
try {
cout << "creating responder" << endl;
cout << "Creating responder" << endl;
responder = application::Responder::create("responder");
} catch (const ResponderCreationException& e) {
cout << "responder error" << endl;
cout << "Responder error" << endl;
return -1;
}
application::This::setRunning();
// receive first request.
// Receive first request.
unique_ptr<application::Request> request = responder->receive();
cout << "received request " << *request << endl;
cout << "Received request " << *request << endl;
request->reply("1st response");
// receive second request.
// Receive second request.
request = responder->receive();
string data1, data2;
parse(request->getBinary(), data1);
parse(request->getSecondBinaryPart(), data2);
cout << "received request " << data1 << " " << data2 << endl;
cout << "Received request " << data1 << " " << data2 << endl;
request->reply("2nd response");
// receive third request without receive on the requester side.
// Receive third request without receive on the requester side.
request = responder->receive();
cout << "received request " << request->get() << endl;
cout << "Received request " << request->get() << endl;
// reply with timeout
// Reply with timeout
request->setTimeout(100);
bool res = request->reply("3rd response");
if (!res) {
cout << "timeout with " << request->getObjectId() << endl;
cout << "Timeout with " << request->getObjectId() << endl;
}
// receive request after timeout.
// Receive request after timeout.
request = responder->receive();
cout << "received request " << *request << endl;
......@@ -87,9 +78,9 @@ int main(int argc, char *argv[]) {
unique_ptr<application::Instance> requester = request->connectToRequester();
cout << "requester " << *requester << endl;
cout << "Requester " << *requester << endl;
cout << "finished the application" << endl;
cout << "Finished the application" << endl;
}
return 0;
......
......@@ -14,11 +14,9 @@
* limitations under the Licence.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cameo/cameo.h>
#include <iostream>
using namespace std;
using namespace cameo;
......@@ -35,53 +33,48 @@ int main(int argc, char *argv[]) {
if (argc > 2) {
applicationName = argv[1];
cout << "responder application is " + applicationName << endl;
cout << "Responder application is " + applicationName << endl;
if (argc > 3) {
numberOfTimes = stoi(argv[2]);
}
} else {
cerr << "arguments: [application name] <number of times>" << endl;
cerr << "Arguments: [application name] <number of times>" << endl;
return -1;
}