TCP: Clarify Async Exception Handling
This commit is contained in:
@@ -31,7 +31,7 @@ public class EchoService {
|
||||
if ("FAIL".equals(input)) {
|
||||
throw new RuntimeException("Failure Demonstration");
|
||||
}
|
||||
else if("TIMEOUT_TEST".equals(input)){
|
||||
else if(input.startsWith("TIMEOUT_TEST")) {
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,12 @@ public class EchoService {
|
||||
}
|
||||
|
||||
public MessageTimeoutException noResponse(String input) {
|
||||
return new MessageTimeoutException("No response received for " + input);
|
||||
if ("TIMEOUT_TEST_THROW".equals(input)) {
|
||||
throw new MessageTimeoutException("No response received for " + input);
|
||||
}
|
||||
else {
|
||||
return new MessageTimeoutException("No response received for " + input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.MessageTimeoutException;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||
import org.springframework.integration.ip.util.TestingUtilities;
|
||||
import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -97,12 +97,23 @@ public class TcpClientServerDemoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeout() {
|
||||
public void testTimeoutThrow() {
|
||||
try {
|
||||
gw.send("TIMEOUT_TEST");
|
||||
gw.send("TIMEOUT_TEST_THROW");
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (MessageTimeoutException e) {
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeoutReturn() {
|
||||
try {
|
||||
gw.send("TIMEOUT_TEST_RETURN");
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user