INT-3099 Add IMAP Idle Application Events
Allow an application to be informed of problems on the IMAP idle thread by emitting an event containing the exception. Introduce IntegrationApplicationEvent hierarchy for all events emitted by SI components. INT-3099 Polishing (PR Comments) Separate TCP events into discrete subclasses.
This commit is contained in:
@@ -30,6 +30,7 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -55,8 +56,6 @@ import org.springframework.integration.ip.tcp.connection.AbstractConnectionFacto
|
||||
import org.springframework.integration.ip.tcp.connection.DefaultTcpNetSSLSocketFactorySupport;
|
||||
import org.springframework.integration.ip.tcp.connection.DefaultTcpNioSSLConnectionSupport;
|
||||
import org.springframework.integration.ip.tcp.connection.DefaultTcpSSLContextSupport;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent.TcpConnectionEventType;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEventListeningMessageProducer;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionSupport;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpMessageMapper;
|
||||
@@ -67,6 +66,8 @@ import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionF
|
||||
import org.springframework.integration.ip.tcp.connection.TcpSSLContextSupport;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpSocketFactorySupport;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpSocketSupport;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionOpenEvent;
|
||||
import org.springframework.integration.ip.udp.DatagramPacketMessageMapper;
|
||||
import org.springframework.integration.ip.udp.MulticastReceivingChannelAdapter;
|
||||
import org.springframework.integration.ip.udp.MulticastSendingMessageHandler;
|
||||
@@ -668,7 +669,7 @@ public class ParserUnitTests {
|
||||
DirectChannel.class).getComponentName());
|
||||
|
||||
TcpConnectionSupport connection = mock(TcpConnectionSupport.class);
|
||||
TcpConnectionEvent event = new TcpConnectionEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
TcpConnectionEvent event = new TcpConnectionOpenEvent(connection, "foo");
|
||||
this.eventAdapter.setEventTypes(new Class[] {TcpConnectionEvent.class});
|
||||
this.eventAdapter.onApplicationEvent(event);
|
||||
assertNull(this.eventChannel.receive(0));
|
||||
@@ -692,16 +693,16 @@ public class ParserUnitTests {
|
||||
@SuppressWarnings("serial")
|
||||
public static class EventSubclass1 extends TcpConnectionEvent {
|
||||
|
||||
public EventSubclass1(TcpConnectionSupport connection, EventType type, String connectionFactoryName) {
|
||||
super(connection, type, connectionFactoryName);
|
||||
public EventSubclass1(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class EventSubclass2 extends TcpConnectionEvent {
|
||||
|
||||
public EventSubclass2(TcpConnectionSupport connection, EventType type, String connectionFactoryName) {
|
||||
super(connection, type, connectionFactoryName);
|
||||
public EventSubclass2(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.springframework.integration.ip.tcp;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
@@ -37,8 +38,10 @@ import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnection;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent.TcpConnectionEventType;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionCloseEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionExceptionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionOpenEvent;
|
||||
import org.springframework.integration.ip.tcp.serializer.ByteArrayRawSerializer;
|
||||
import org.springframework.integration.ip.util.TestingUtilities;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
@@ -114,21 +117,21 @@ public class ConnectionToConnectionTests {
|
||||
while ((eventMessage = (Message<TcpConnectionEvent>) events.receive(1000)) != null) {
|
||||
TcpConnectionEvent event = eventMessage.getPayload();
|
||||
if ("client".equals(event.getConnectionFactoryName())) {
|
||||
if (TcpConnectionEventType.OPEN == event.getType()) {
|
||||
if (event instanceof TcpConnectionOpenEvent) {
|
||||
clientOpens++;
|
||||
}
|
||||
else if (TcpConnectionEventType.CLOSE == event.getType()) {
|
||||
else if (event instanceof TcpConnectionCloseEvent) {
|
||||
clientCloses++;
|
||||
}
|
||||
else if (TcpConnectionEventType.EXCEPTION == event.getType()) {
|
||||
else if (event instanceof TcpConnectionExceptionEvent) {
|
||||
clientExceptions++;
|
||||
}
|
||||
}
|
||||
else if ("server".equals(event.getConnectionFactoryName())) {
|
||||
if (TcpConnectionEventType.OPEN == event.getType()) {
|
||||
if (event instanceof TcpConnectionOpenEvent) {
|
||||
serverOpens++;
|
||||
}
|
||||
else if (TcpConnectionEventType.CLOSE == event.getType()) {
|
||||
else if (event instanceof TcpConnectionCloseEvent) {
|
||||
serverCloses++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.springframework.integration.ip.tcp.connection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -28,9 +28,13 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.core.serializer.Serializer;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionExceptionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionOpenEvent;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
@@ -51,7 +55,8 @@ public class ConnectionEventTests {
|
||||
}
|
||||
}, "foo");
|
||||
assertNotNull(theEvent.get());
|
||||
assertEquals("TcpConnectionEvent [type=OPEN, factory=foo, connectionId=" + conn.getConnectionId() + "]", theEvent.get().toString());
|
||||
assertTrue(theEvent.get() instanceof TcpConnectionOpenEvent);
|
||||
assertTrue(theEvent.get().toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "] **OPENED**"));
|
||||
@SuppressWarnings("unchecked")
|
||||
Serializer<Object> serializer = mock(Serializer.class);
|
||||
RuntimeException toBeThrown = new RuntimeException("foo");
|
||||
@@ -64,13 +69,15 @@ public class ConnectionEventTests {
|
||||
}
|
||||
catch (Exception e) {}
|
||||
assertNotNull(theEvent.get());
|
||||
assertEquals("TcpConnectionEvent [type=EXCEPTION, factory=foo, connectionId=" + conn.getConnectionId() +
|
||||
", Exception=java.lang.RuntimeException: foo]", theEvent.get().toString());
|
||||
assertNotNull(theEvent.get().getThrowable());
|
||||
assertSame(toBeThrown, theEvent.get().getThrowable());
|
||||
assertTrue(theEvent.get() instanceof TcpConnectionExceptionEvent);
|
||||
assertTrue(theEvent.get().toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "]"));
|
||||
assertTrue(theEvent.get().toString().contains("cause=java.lang.RuntimeException: foo]"));
|
||||
TcpConnectionExceptionEvent event = (TcpConnectionExceptionEvent) theEvent.get();
|
||||
assertNotNull(event.getCause());
|
||||
assertSame(toBeThrown, event.getCause());
|
||||
conn.close();
|
||||
assertNotNull(theEvent.get());
|
||||
assertEquals("TcpConnectionEvent [type=CLOSE, factory=foo, connectionId=" + conn.getConnectionId() + "]", theEvent.get().toString());
|
||||
assertTrue(theEvent.get().toString().endsWith("[factory=foo, connectionId=" + conn.getConnectionId() + "] **CLOSED**"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,11 +32,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent.TcpConnectionEventType;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionOpenEvent;
|
||||
import org.springframework.integration.ip.util.TestingUtilities;
|
||||
import org.springframework.integration.test.util.SocketUtils;
|
||||
|
||||
@@ -98,12 +100,12 @@ public class ConnectionFactoryTests {
|
||||
assertEquals(0, clients.size());
|
||||
assertEquals(6, events.size()); // OPEN, CLOSE, EXCEPTION for each side
|
||||
|
||||
FooEvent event = new FooEvent(client, TcpConnectionEventType.OPEN, "foo");
|
||||
FooEvent event = new FooEvent(client, "foo");
|
||||
client.publishEvent(event);
|
||||
assertEquals(7, events.size());
|
||||
|
||||
try {
|
||||
event = new FooEvent(mock(TcpConnectionSupport.class), TcpConnectionEventType.OPEN, "foo");
|
||||
event = new FooEvent(mock(TcpConnectionSupport.class), "foo");
|
||||
client.publishEvent(event);
|
||||
fail("Expected exception");
|
||||
}
|
||||
@@ -113,10 +115,10 @@ public class ConnectionFactoryTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class FooEvent extends TcpConnectionEvent {
|
||||
private class FooEvent extends TcpConnectionOpenEvent {
|
||||
|
||||
public FooEvent(TcpConnectionSupport connection, EventType type, String connectionFactoryName) {
|
||||
super(connection, type, connectionFactoryName);
|
||||
public FooEvent(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent.TcpConnectionEventType;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionCloseEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.util.TestingUtilities;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.SocketUtils;
|
||||
@@ -261,7 +262,7 @@ public class ConnectionTimeoutTests {
|
||||
@Override
|
||||
public void publishEvent(ApplicationEvent event) {
|
||||
TcpConnectionEvent tcpEvent = (TcpConnectionEvent) event;
|
||||
if (tcpEvent.getType() == TcpConnectionEventType.CLOSE) {
|
||||
if (tcpEvent instanceof TcpConnectionCloseEvent) {
|
||||
clientClosedLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,11 @@ import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.ip.tcp.connection.TcpConnectionEvent.TcpConnectionEventType;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionEvent;
|
||||
import org.springframework.integration.ip.tcp.connection.event.TcpConnectionOpenEvent;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
@@ -40,11 +42,11 @@ public class TcpConnectionEventListenerTests {
|
||||
eventProducer.afterPropertiesSet();
|
||||
eventProducer.start();
|
||||
TcpConnectionSupport connection = Mockito.mock(TcpConnectionSupport.class);
|
||||
TcpConnectionEvent event1 = new TcpConnectionEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
TcpConnectionEvent event1 = new TcpConnectionOpenEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event1);
|
||||
FooEvent event2 = new FooEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
FooEvent event2 = new FooEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event2);
|
||||
BarEvent event3 = new BarEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
BarEvent event3 = new BarEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event3);
|
||||
Message<?> message = outputChannel.receive(0);
|
||||
assertNotNull(message);
|
||||
@@ -69,11 +71,11 @@ public class TcpConnectionEventListenerTests {
|
||||
eventProducer.afterPropertiesSet();
|
||||
eventProducer.start();
|
||||
TcpConnectionSupport connection = Mockito.mock(TcpConnectionSupport.class);
|
||||
TcpConnectionEvent event1 = new TcpConnectionEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
TcpConnectionEvent event1 = new TcpConnectionOpenEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event1);
|
||||
FooEvent event2 = new FooEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
FooEvent event2 = new FooEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event2);
|
||||
BarEvent event3 = new BarEvent(connection, TcpConnectionEventType.OPEN, "foo");
|
||||
BarEvent event3 = new BarEvent(connection, "foo");
|
||||
eventProducer.onApplicationEvent(event3);
|
||||
Message<?> message = outputChannel.receive(0);
|
||||
assertNotNull(message);
|
||||
@@ -86,19 +88,19 @@ public class TcpConnectionEventListenerTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class FooEvent extends TcpConnectionEvent {
|
||||
private class FooEvent extends TcpConnectionOpenEvent {
|
||||
|
||||
public FooEvent(TcpConnectionSupport connection, EventType type, String connectionFactoryName) {
|
||||
super(connection, type, connectionFactoryName);
|
||||
public FooEvent(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private class BarEvent extends TcpConnectionEvent {
|
||||
private class BarEvent extends TcpConnectionOpenEvent {
|
||||
|
||||
public BarEvent(TcpConnectionSupport connection, EventType type, String connectionFactoryName) {
|
||||
super(connection, type, connectionFactoryName);
|
||||
public BarEvent(TcpConnectionSupport connection, String connectionFactoryName) {
|
||||
super(connection, connectionFactoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user