use of org.springframework.integration.ip.tcp.connection.TcpConnectionExceptionEvent in project spring-integration by spring-projects.
the class ConnectionToConnectionTests method testConnectGuts.
@SuppressWarnings("unchecked")
private void testConnectGuts(AbstractClientConnectionFactory client, AbstractServerConnectionFactory server, String gatewayName, boolean expectExceptionOnClose) throws Exception {
TestingUtilities.waitListening(server, null);
client.setPort(server.getPort());
client.start();
for (int i = 0; i < 100; i++) {
TcpConnection connection = client.getConnection();
connection.send(MessageBuilder.withPayload("Test").build());
Message<?> message = serverSideChannel.receive(10000);
assertNotNull(message);
MessageHistory history = MessageHistory.read(message);
// org.springframework.integration.test.util.TestUtils
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, gatewayName, 0);
assertNotNull(componentHistoryRecord);
assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
assertNotNull(message);
assertEquals("Test", new String((byte[]) message.getPayload()));
}
int clientOpens = 0;
int clientCloses = 0;
int serverOpens = 0;
int serverCloses = 0;
int clientExceptions = 0;
Message<TcpConnectionEvent> eventMessage;
int i = 0;
while (i++ < (expectExceptionOnClose ? 600 : 400) && (eventMessage = (Message<TcpConnectionEvent>) events.receive(10000)) != null) {
TcpConnectionEvent event = eventMessage.getPayload();
if (event.getConnectionFactoryName().startsWith("client")) {
if (event instanceof TcpConnectionOpenEvent) {
clientOpens++;
} else if (event instanceof TcpConnectionCloseEvent) {
clientCloses++;
} else if (event instanceof TcpConnectionExceptionEvent) {
clientExceptions++;
}
} else if (event.getConnectionFactoryName().startsWith("server")) {
if (event instanceof TcpConnectionOpenEvent) {
serverOpens++;
} else if (event instanceof TcpConnectionCloseEvent) {
serverCloses++;
}
}
}
assertEquals(100, clientOpens);
assertEquals(100, clientCloses);
if (expectExceptionOnClose) {
assertEquals(100, clientExceptions);
}
assertEquals(100, serverOpens);
assertEquals(100, serverCloses);
}
Aggregations