Commit 7002759c authored by legoc's avatar legoc

Added test for timeouts in Requester/Responder

parent 8f5f33d5
......@@ -225,6 +225,15 @@
<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>
<application name="startrepcppt" starting_time="0" retries="0" stopping_time="1" stream="yes" multiple="no" restart="no">
<start executable="build/bin/testrequesterandrespondertimeout" args="repcppt"/>
</application>
</applications>
</config>
......@@ -26,10 +26,11 @@ bin_PROGRAMS = \
testveryfast \
teststoptimeout \
requesterclient \
responderserver
responderserver \
testrespondertimeout \
testrequesterandrespondertimeout
testcameo_SOURCES = \
Test.cpp
......@@ -234,3 +235,21 @@ responderserver_SOURCES = \
responderserver_CPPFLAGS = $(CT_CXXFLAGS)
responderserver_LDFLAGS = $(CT_LDFLAGS)
responderserver_LDADD = $(CT_LIBS)
testrespondertimeout_SOURCES = \
TestResponderApplicationForTimeout.cpp
testrespondertimeout_CPPFLAGS = $(CT_CXXFLAGS)
testrespondertimeout_LDFLAGS = $(CT_LDFLAGS)
testrespondertimeout_LDADD = $(CT_LIBS)
testrequesterandrespondertimeout_SOURCES = \
TestRequesterAndResponderApplicationForTimeout.cpp
testrequesterandrespondertimeout_CPPFLAGS = $(CT_CXXFLAGS)
testrequesterandrespondertimeout_LDFLAGS = $(CT_LDFLAGS)
testrequesterandrespondertimeout_LDADD = $(CT_LIBS)
/*
* 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.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <cameo/cameo.h>
using namespace std;
using namespace cameo;
int main(int argc, char *argv[]) {
application::This::init(argc, argv);
// New block to ensure cameo objects are terminated before the application.
{
string applicationName;
int numberOfTimes = 1;
if (argc > 2) {
applicationName = argv[1];
cout << "responder application is " + applicationName << endl;
if (argc > 3) {
numberOfTimes = boost::lexical_cast<int>(argv[2]);
}
} else {
cerr << "arguments: [application name] <number of times>" << endl;
return -1;
}
cout << "number of times is " << numberOfTimes << endl;
// get the client services
Server& server = application::This::getServer();
if (application::This::isAvailable() && server.isAvailable()) {
cout << "connected server " << server << endl;
}
// start the application.
auto_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
auto_ptr<application::Requester> requester = application::Requester::create(*responderApplication, "responder");
cout << "created requester " << *requester << endl;
if (requester.get() == 0) {
cout << "requester error" << endl;
return -1;
}
cout << "application " << *responderApplication << " has state " << application::toString(responderApplication->now()) << endl;
// loop the number of times.
for (int i = 0; i < numberOfTimes; ++i) {
application::This::setTimeout(1);
try {
// send a simple message.
requester->send("request");
string response;
requester->receive(response);
cout << "response is " << response << endl;
} catch (...) {
cout << "timeout" << endl;
}
usleep(100000);
application::This::setTimeout(1000);
try {
// send a simple message.
requester->send("request");
string response;
requester->receive(response);
cout << "response is " << response << endl;
} catch (...) {
cout << "timeout" << 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;
}
/*
* 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.
*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cameo/cameo.h>
using namespace std;
using namespace cameo;
int main(int argc, char *argv[]) {
application::This::init(argc, argv);
// New block to ensure cameo objects are terminated before the application.
{
if (application::This::isAvailable()) {
cout << "connected" << endl;
}
auto_ptr<application::Responder> responder;
try {
cout << "creating responder" << endl;
responder = application::Responder::create("responder");
} catch (const ResponderCreationException& e) {
cout << "responder error" << endl;
return -1;
}
application::This::setRunning();
while (true) {
auto_ptr<application::Request> request = responder->receive();
cout << "received request " << *request << endl;
request->reply("done");
usleep(100000);
}
cout << "finished the application" << endl;
}
return 0;
}
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