public void runEcho(Options clientOptions, boolean asyncReply, boolean asyncAcks, boolean explicitTermination, boolean checkInboundTermination, boolean stopListener) throws Exception {
String sequenceKey = SandeshaUtil.getUUID();
ServiceClient serviceClient = new ServiceClient (configContext,null);
serviceClient.setOptions(clientOptions);
clientOptions.setAction(echoAction);
clientOptions.setTo(new EndpointReference (to));
clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
if(asyncReply || asyncAcks) {
clientOptions.setUseSeparateListener(true);
if(asyncAcks) {
String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
} else {
String acksTo = AddressingConstants.Final.WSA_ANONYMOUS_URL;
clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
}
}
if(asyncAcks) {
String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
} else {
String acksTo = AddressingConstants.Final.WSA_ANONYMOUS_URL;
clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
}
// Establish a baseline count for inbound sequences
List oldIncomingReports = SandeshaClient.getIncomingSequenceReports(configContext);
TestCallback callback1 = new TestCallback ("Callback 1");
serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo1",sequenceKey),callback1);
TestCallback callback2 = new TestCallback ("Callback 2");
serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo2",sequenceKey),callback2);
if (!explicitTermination
&&
!Sandesha2Constants.SPEC_VERSIONS.v1_1.equals(clientOptions.getProperty(SandeshaClientConstants.RM_SPEC_VERSION))) {
clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
}
TestCallback callback3 = new TestCallback ("Callback 3");
serviceClient.sendReceiveNonBlocking (getEchoOMBlock("echo3",sequenceKey),callback3);
if (explicitTermination) {
Thread.sleep(10000);
SandeshaClient.terminateSequence(serviceClient);
}
long limit = System.currentTimeMillis() + waitTime;
Error lastError = null;
while(System.currentTimeMillis() < limit) {
Thread.sleep(tickTime); // Try the assertions each tick interval, until they pass or we time out
try {
//assertions for the out sequence.
SequenceReport outgoingSequenceReport = SandeshaClient.getOutgoingSequenceReport(serviceClient);
//System.out.println("Checking Outbound Sequence: " + outgoingSequenceReport.getSequenceID());
assertTrue("Outbound message #1", outgoingSequenceReport.getCompletedMessages().contains(new Long(1)));
assertTrue("Outbound message #2", outgoingSequenceReport.getCompletedMessages().contains(new Long(2)));
assertTrue("Outbound message #3", outgoingSequenceReport.getCompletedMessages().contains(new Long(3)));
assertEquals("Outbound sequence status: TERMINATED", SequenceReport.SEQUENCE_STATUS_TERMINATED, outgoingSequenceReport.getSequenceStatus());
assertEquals("Outbound sequence direction: OUT", SequenceReport.SEQUENCE_DIRECTION_OUT, outgoingSequenceReport.getSequenceDirection());
//assertions for the inbound sequence. The one we care about is a new sequence,
//so it will not exist in the oldSequences list.
List incomingSequences = SandeshaClient.getIncomingSequenceReports(configContext);
SequenceReport incomingSequenceReport = getNewReport(incomingSequences, oldIncomingReports);
//System.out.println("Checking Inbound Sequence: " + incomingSequenceReport.getSequenceID());
String offer = (String) clientOptions.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
if(offer != null) assertEquals("Inbound seq id", offer, incomingSequenceReport.getSequenceID());
assertEquals ("Inbound message count", 3, incomingSequenceReport.getCompletedMessages().size());
assertTrue("Inbound message #1", incomingSequenceReport.getCompletedMessages().contains(new Long(1)));
assertTrue("Inbound message #2", incomingSequenceReport.getCompletedMessages().contains(new Long(2)));
assertTrue("Inbound message #3", incomingSequenceReport.getCompletedMessages().contains(new Long(3)));
if (checkInboundTermination)
assertEquals("Inbound sequence status: TERMINATED", SequenceReport.SEQUENCE_STATUS_TERMINATED, incomingSequenceReport.getSequenceStatus());
assertEquals("Inbound sequence direction: IN", SequenceReport.SEQUENCE_DIRECTION_IN, incomingSequenceReport.getSequenceDirection());
assertTrue("Callback #1", callback1.isComplete());
assertEquals("Callback #1 data", "echo1", callback1.getResult());
assertTrue("Callback #2", callback2.isComplete());
assertEquals("Callback #2 data", "echo1echo2", callback2.getResult());
assertTrue("Callback #3", callback3.isComplete());
assertEquals("Callback #3 data", "echo1echo2echo3", callback3.getResult());
lastError = null;
break;
} catch(Error e) {
//System.out.println("Possible error:" + e);
lastError = e;
}
}
if(lastError != null) throw lastError;
if (stopListener)
configContext.getListenerManager().stop();
serviceClient.cleanup();
}