Skip to content
Snippets Groups Projects
Commit e62a12ce authored by brinn's avatar brinn
Browse files

Improve test case for server-side timeout.

SVN: 24033
parent ff81abf2
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ public class ServiceConversationTest ...@@ -54,7 +54,7 @@ public class ServiceConversationTest
} }
/** /**
* This object encapsulates the client server connection for test purposes. * This object encapsulates the client server connection for test purposes.
*/ */
private static class TestClientServerConnection implements IRemoteServiceConversationServer, private static class TestClientServerConnection implements IRemoteServiceConversationServer,
IServiceMessageTransport IServiceMessageTransport
...@@ -69,25 +69,25 @@ public class ServiceConversationTest ...@@ -69,25 +69,25 @@ public class ServiceConversationTest
void setResponseMessageTransport(final IServiceMessageTransport responseMessageTransport) void setResponseMessageTransport(final IServiceMessageTransport responseMessageTransport)
{ {
server.addClientResponseTransport("dummyClient", new IServiceMessageTransport() server.addClientResponseTransport("dummyClient", new IServiceMessageTransport()
{
public void send(ServiceMessage message)
{ {
int attempt = 0; public void send(ServiceMessage message)
while (attempt++ < 10)
{ {
try int attempt = 0;
while (attempt++ < 10)
{ {
// Send all messages twice to test detection of duplicate messages. try
responseMessageTransport.send(message); {
responseMessageTransport.send(message); // Send all messages twice to test detection of duplicate messages.
break; responseMessageTransport.send(message);
} catch (Exception ex) responseMessageTransport.send(message);
{ break;
ConcurrencyUtilities.sleep(10); } catch (Exception ex)
{
ConcurrencyUtilities.sleep(10);
}
} }
} }
} });
});
} }
...@@ -230,8 +230,7 @@ public class ServiceConversationTest ...@@ -230,8 +230,7 @@ public class ServiceConversationTest
assertEquals("Three", conversation.receive(String.class)); assertEquals("Three", conversation.receive(String.class));
conversation.terminate(); conversation.terminate();
for (int i = 0; i < 100 for (int i = 0; i < 100 && holder.server.hasConversation(conversation.getId()); ++i)
&& holder.server.hasConversation(conversation.getId()); ++i)
{ {
ConcurrencyUtilities.sleep(10L); ConcurrencyUtilities.sleep(10L);
} }
...@@ -288,53 +287,34 @@ public class ServiceConversationTest ...@@ -288,53 +287,34 @@ public class ServiceConversationTest
@Test @Test
public void testEchoServiceTimeout() throws Exception public void testEchoServiceTimeout() throws Exception
{ {
final ServiceConversationServer conversations = new ServiceConversationServer(100); final ServiceConversationServerAndClientHolder holder =
conversations.addServiceType(new IServiceFactory() createServerAndClient(EchoService.createFactory());
{ final IServiceConversation conversation = holder.client.startConversation("echo");
public IService create() assertTrue(holder.server.hasConversation(conversation.getId()));
{
return new EchoService();
}
public int getClientTimeoutMillis()
{
return 100;
}
public String getServiceTypeId() conversation.send("One");
{ assertEquals("One", conversation.receive(String.class));
return "echo"; conversation.send("Two");
}
});
final BlockingQueue<ServiceMessage> messageQueue =
new LinkedBlockingQueue<ServiceMessage>();
conversations.addClientResponseTransport("dummyClient", new IServiceMessageTransport()
{
public void send(ServiceMessage message)
{
messageQueue.add(message);
}
});
final String id =
conversations.startConversation("echo", "dummyClient").getServiceConversationId();
assertTrue(conversations.hasConversation(id));
int messageIdx = 0;
conversations.getIncomingMessageTransport().send(new ServiceMessage(id, 0, false, "One"));
ServiceMessage m = messageQueue.take();
assertEquals(id, m.getConversationId());
assertEquals(messageIdx++, m.getMessageIdx());
assertEquals("One", m.getPayload());
// Wait for timeout to happen. // Wait for timeout to happen.
for (int i = 0; i < 100 && conversations.hasConversation(id); ++i) for (int i = 0; i < 100 && holder.server.hasConversation(conversation.getId()); ++i)
{ {
ConcurrencyUtilities.sleep(10L); ConcurrencyUtilities.sleep(10L);
} }
assertFalse(conversations.hasConversation(id)); assertFalse(holder.server.hasConversation(conversation.getId()));
m = messageQueue.take();
assertTrue(m.isException()); conversation.send("Three");
assertTrue(m.tryGetExceptionDescription().startsWith( try
"ch.systemsx.cisd.base.exceptions.TimeoutExceptionUnchecked:")); {
conversation.receive(String.class);
fail("Server timeout not signaled to client");
} catch (ServiceExecutionException ex)
{
assertTrue(
ex.getDescription(),
ex.getDescription().startsWith(
"ch.systemsx.cisd.base.exceptions.TimeoutExceptionUnchecked:"));
}
} }
@Test(expectedExceptions = UnknownServiceTypeException.class) @Test(expectedExceptions = UnknownServiceTypeException.class)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment