Commit 5d4b8be9 authored by legoc's avatar legoc

Adapted tests

parent 648b5ba1
......@@ -237,12 +237,16 @@
<start executable="build/bin/testrequesterandresponder" args="repcpp"/>
</application>
<application name="repcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="build/bin/testrespondertimeout"/>
<application name="reqcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="build/bin/testrequestertimeout"/>
</application>
<application name="reqrepcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="build/bin/testrequesterandrespondertimeout"/>
</application>
<application name="startrepcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="build/bin/testrequesterandrespondertimeout" args="repcppt"/>
<start executable="build/bin/testrequesterandrespondertimeout" args="reqcppt"/>
</application>
<application name="streamcpp" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
......
......@@ -245,12 +245,16 @@
<start executable="build/bin/testrequesterandresponder" args="repcpp"/>
</application>
<application name="repcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="build/bin/testrespondertimeout"/>
<application name="reqcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="build/bin/testrequestertimeout"/>
</application>
<application name="reqrepcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="build/bin/testrequesterandrespondertimeout"/>
</application>
<application name="startrepcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="build/bin/testrequesterandrespondertimeout" args="repcppt"/>
<start executable="build/bin/testrequesterandrespondertimeout" args="reqcppt"/>
</application>
<application name="streamcpp" starting_time="0" retries="0" stopping_time="1" stream="yes" log_directory="logs" multiple="no" restart="no">
......
......@@ -27,7 +27,7 @@ bin_PROGRAMS = \
teststoptimeout \
requesterclient \
responderserver \
testrespondertimeout \
testrequestertimeout \
testrequesterandrespondertimeout \
teststream \
teststartstream \
......@@ -241,12 +241,12 @@ responderserver_LDFLAGS = $(CT_LDFLAGS)
responderserver_LDADD = $(CT_LIBS)
testrespondertimeout_SOURCES = \
TestResponderApplicationForTimeout.cpp
testrequestertimeout_SOURCES = \
TestRequesterApplicationForTimeout.cpp
testrespondertimeout_CPPFLAGS = $(CT_CXXFLAGS)
testrespondertimeout_LDFLAGS = $(CT_LDFLAGS)
testrespondertimeout_LDADD = $(CT_LIBS)
testrequestertimeout_CPPFLAGS = $(CT_CXXFLAGS)
testrequestertimeout_LDFLAGS = $(CT_LDFLAGS)
testrequestertimeout_LDADD = $(CT_LIBS)
testrequesterandrespondertimeout_SOURCES = \
......
......@@ -96,13 +96,12 @@ int main(int argc, char *argv[]) {
// send a simple message but do not receive the response immediately.
requester->send("request");
cout << "wait for 1s so that the responder has timed out" << endl;
cout << "wait so that the responder has timed out" << endl;
this_thread::sleep_for(chrono::seconds(1));
requester->receive(response);
cout << "response is " << response << endl;
// send a new simple message.
requester->send("request after timeout");
......
......@@ -25,6 +25,12 @@ using namespace cameo;
int main(int argc, char *argv[]) {
/**
* This goal of the test was to test the linger value. In fact, it does not seem important for us.
*
*
*
application::This::init(argc, argv);
// New block to ensure cameo objects are terminated before the application.
......@@ -35,7 +41,7 @@ int main(int argc, char *argv[]) {
if (argc > 2) {
applicationName = argv[1];
cout << "responder application is " + applicationName << endl;
cout << "requester application is " + applicationName << endl;
if (argc > 3) {
numberOfTimes = stoi(argv[2]);
......@@ -55,62 +61,67 @@ int main(int argc, char *argv[]) {
cout << "connected server " << server << endl;
}
// start the application.
unique_ptr<application::Instance> responderApplication = server.connect(applicationName);
cout << "connected application " << *responderApplication << " with state " << application::toString(responderApplication->now()) << endl;
// create a subscriber to the application applicationName
unique_ptr<application::Requester> requester = application::Requester::create(*responderApplication, "responder");
// create a responder to the application applicationName
unique_ptr<application::Responder> responder = application::Responder::create("responder");
cout << "created requester " << *requester << endl;
cout << "created responder " << *responder << endl;
if (requester.get() == 0) {
cout << "requester error" << endl;
if (responder.get() == 0) {
cout << "responder error" << endl;
return -1;
}
cout << "application " << *responderApplication << " has state " << application::toString(responderApplication->now()) << endl;
int base = 10;
vector<int> timeouts = {-2, base}; // -2 => 0
vector<bool> lingers = {false, true};
// loop the number of times.
for (int i = 0; i < numberOfTimes; ++i) {
application::This::setTimeout(1);
for (int t : timeouts) {
for (bool l : lingers) {
for (int j = 0; j < 2; ++j) {
try {
// send a simple message.
requester->send("request");
int r = 0;
switch (j) {
case 0: r = t / 2; break;
case 1: r = t + base; break;
}
if (r < 0) r = base;
string response;
requester->receive(response);
cout << "response is " << response << endl;
cout << "t = " << t << ", l = " << l << ", r = " << r << endl;
} catch (...) {
cout << "timeout" << endl;
}
vector<string> args = {to_string(r)};
// start the application.
unique_ptr<application::Instance> requesterApplication = server.start(applicationName, args);
this_thread::sleep_for(chrono::milliseconds(100));
cout << "started application " << *requesterApplication << endl;
application::This::setTimeout(1000);
// receive request.
unique_ptr<application::Request> request = responder->receive();
cout << "received request " << *request << endl;
try {
// send a simple message.
requester->send("request");
request->setTimeout(t, l);
string response;
requester->receive(response);
cout << "response is " << response << endl;
string response = string("response ") + to_string(r);
request->reply(response);
} catch (...) {
cout << "timeout" << endl;
this_thread::sleep_for(chrono::milliseconds(2*r));
requesterApplication->kill();
application::State state = requesterApplication->waitFor();
cout << *requesterApplication << " terminated with state " << application::toString(state) << endl << endl;
}
}
}
}
responderApplication->kill();
application::State state = responderApplication->waitFor();
cout << "responder application terminated with state " << application::toString(state) << endl;
cout << "finished the application" << endl;
}
*/
return 0;
}
......@@ -23,42 +23,54 @@
using namespace std;
using namespace cameo;
int main(int argc, char *argv[]) {
/**
* This goal of the test was to test the linger value. In fact, it does not seem important for us.
*
application::This::init(argc, argv);
// New block to ensure cameo objects are terminated before the application.
{
if (application::This::isAvailable()) {
cout << "connected" << endl;
}
unique_ptr<application::Responder> responder;
// Sleep time between send and receive.
int sleepTime = 0;
if (argc > 2) {
sleepTime = stoi(argv[1]);
try {
cout << "creating responder" << endl;
cout << "sleep time is " << sleepTime << endl;
}
responder = application::Responder::create("responder");
unique_ptr<application::Instance> responderApplication = application::This::connectToStarter();
} catch (const ResponderCreationException& e) {
cout << "responder error" << endl;
return -1;
}
// Create a requester.
unique_ptr<application::Requester> requester = application::Requester::create(*responderApplication, "responder");
cout << "created requester " << *requester << endl;
application::This::setRunning();
while (true) {
try {
// send a simple message.
requester->send("request");
unique_ptr<application::Request> request = responder->receive();
cout << "received request " << *request << endl;
// sleep.
this_thread::sleep_for(chrono::milliseconds(sleepTime));
request->reply("done");
// response.
string response;
requester->receive(response);
cout << "response is " << response << endl;
this_thread::sleep_for(chrono::milliseconds(100));
} catch (...) {
cout << "error" << endl;
}
cout << "finished the application" << endl;
}
*/
return 0;
}
......@@ -70,9 +70,13 @@ int main(int argc, char *argv[]) {
request = responder->receive();
cout << "received request " << request->get() << endl;
// reply with timeout of 100ms
// reply with timeout
request->setTimeout(100);
request->reply("3rd response");
bool res = request->reply("3rd response");
if (!res) {
cout << "timeout with " << request->getObjectId() << endl;
}
// receive request after timeout.
......
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