Commit 648b5ba1 authored by legoc's avatar legoc

Added tests for responder timeout

parent 0198860b
......@@ -93,6 +93,22 @@ int main(int argc, char *argv[]) {
requester->receive(response);
cout << "response is " << response << endl;
// 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;
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");
requester->receive(response);
cout << "response is " << response << endl;
application::State state = responderApplication->waitFor();
......
......@@ -47,21 +47,40 @@ int main(int argc, char *argv[]) {
application::This::setRunning();
// receive first request.
unique_ptr<application::Request> request = responder->receive();
cout << "received request " << *request << endl;
request->reply("done");
request->reply("1st response");
// receive second request.
request = responder->receive();
string data1, data2;
parse(request->getBinary(), data1);
parse(request->getSecondBinaryPart(), data2);
cout << "received request " << data1 << " " << data2 << endl;
request->reply("done");
request->reply("2nd response");
// receive third request without receive on the requester side.
request = responder->receive();
cout << "received request " << request->get() << endl;
// reply with timeout of 100ms
request->setTimeout(100);
request->reply("3rd response");
// receive request after timeout.
request = responder->receive();
cout << "received request " << *request << endl;
request->reply("4th response after timeout");
unique_ptr<application::Instance> requester = request->connectToRequester();
cout << "requester " << *requester << endl;
......
......@@ -69,14 +69,34 @@ public class TestRequesterAndResponderApplication {
// Check the state of the responder app.
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());
// Send a two-parts message.
requester.sendTwoParts(Buffer.serialize("first"), Buffer.serialize("second"));
System.out.println("response is " + requester.receiveString());
// Send a simple message.
requester.send("request");
// Wait 1s.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("response is " + requester.receiveString());
// Send a simple message.
requester.send("request");
System.out.println("response is " + requester.receiveString());
int state = responderApplication.waitFor();
System.out.println("responder application terminated with state " + Application.State.toString(state));
......
......@@ -40,23 +40,43 @@ public class TestResponderApplication {
// Set the state.
Application.This.setRunning();
// Receive the simple request.
// Receive the first request.
Application.Request request = responder.receive();
System.out.println("received request " + request.get());
// Reply.
request.reply("done");
request.reply("1st response");
request.terminate();
// Receive the two-parts request.
// Receive the second request.
request = responder.receive();
byte[][] data = request.getTwoBinaryParts();
System.out.println("received request " + Buffer.parseString(data[0]) + " " + Buffer.parseString(data[1]));
// Reply.
request.reply("done");
request.reply("2nd response");
// Receive the third request.
request = responder.receive();
System.out.println("received request " + request.get());
// Reply.
//request.setTimeout(100);
request.reply("3rd response");
request.terminate();
// Receive the fourth request.
request = responder.receive();
System.out.println("received request " + request.get());
// Reply.
request.reply("4th response");
request.terminate();
// Test connection.
Application.Instance requester = request.connectToRequester();
......
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