SCMessage response = null;
sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
msgCallback1 = new MsgCallback(sessionService1);
response = sessionService1.createSession(request, msgCallback1);
SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
MsgCallback msgCallback2 = new MsgCallback(sessionService1);
sessionService2.setEchoIntervalSeconds(10);
response = sessionService2.createSession(request, msgCallback2);
// session service starts storing message with cacheId 700
request.setData("cacheWait15sec");
request.setCacheId("700");
request.setMessageInfo(TestConstants.cacheCmd);
sessionService1.send(60, request);
// to assure service1 started loading cache
Thread.sleep(10);
// session service2 starts getting large message from cache with cacheId 700
request.setData(TestConstants.pangram);
request.setCacheId("700");
request.setMessageInfo(TestConstants.cacheCmd);
for (int i = 0; i < 12; i++) {
try {
response = sessionService2.execute(request);
Assert.fail("Should throw an exception but did not.");
} catch (SCServiceException e) {
Assert.assertEquals(SCMPError.CACHE_LOADING.getErrorCode(), e.getSCErrorCode());
}
Thread.sleep(1000);
}
Thread.sleep(5000);
// get response from sessionService1 request
msgCallback1.waitForMessage(60);
response = msgCallback1.getResponse();
SCMessage response2 = sessionService2.execute(request);
Assert.assertEquals("cacheWait15sec", response.getData());
}