use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class TcpReceivingChannelAdapterTests method testException.
@Test
public void testException() throws Exception {
AbstractServerConnectionFactory scf = new TcpNetServerConnectionFactory(0);
noopPublisher(scf);
ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer();
scf.setSerializer(serializer);
scf.setDeserializer(serializer);
TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
adapter.setConnectionFactory(scf);
scf.start();
TestingUtilities.waitListening(scf, null);
int port = scf.getPort();
SubscribableChannel channel = new DirectChannel();
adapter.setOutputChannel(channel);
ServiceActivatingHandler handler = new ServiceActivatingHandler(new FailingService());
channel.subscribe(handler);
QueueChannel errorChannel = new QueueChannel();
adapter.setErrorChannel(errorChannel);
Socket socket = SocketFactory.getDefault().createSocket("localhost", port);
socket.getOutputStream().write("Test1\r\n".getBytes());
socket.getOutputStream().write("Test2\r\n".getBytes());
Message<?> message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
message = errorChannel.receive(10000);
assertNotNull(message);
assertEquals("Failed", ((Exception) message.getPayload()).getCause().getMessage());
scf.stop();
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class FailoverClientConnectionFactoryTests method testFailoverCachedWithGateway.
@SuppressWarnings("unchecked")
@Test
public void testFailoverCachedWithGateway() throws Exception {
final TcpNetServerConnectionFactory server = new TcpNetServerConnectionFactory(0);
server.setBeanName("server");
server.afterPropertiesSet();
DirectChannel inChannel = new DirectChannel();
inChannel.setBeanName("inChannel");
TcpInboundGateway inbound = new TcpInboundGateway();
inbound.setConnectionFactory(server);
inbound.setRequestChannel(inChannel);
inbound.afterPropertiesSet();
inChannel.subscribe(new BridgeHandler());
inbound.start();
TestingUtilities.waitListening(server, 10000L);
int port = server.getPort();
AbstractClientConnectionFactory client = new TcpNetClientConnectionFactory("localhost", port);
client.setBeanName("client");
// Cache
CachingClientConnectionFactory cachingClient = new CachingClientConnectionFactory(client, 2);
cachingClient.setBeanName("cache");
cachingClient.afterPropertiesSet();
// Failover
List<AbstractClientConnectionFactory> clientFactories = new ArrayList<AbstractClientConnectionFactory>();
clientFactories.add(cachingClient);
FailoverClientConnectionFactory failoverClient = new FailoverClientConnectionFactory(clientFactories);
failoverClient.setSingleUse(true);
failoverClient.afterPropertiesSet();
TcpOutboundGateway outbound = new TcpOutboundGateway();
outbound.setConnectionFactory(failoverClient);
QueueChannel replyChannel = new QueueChannel();
replyChannel.setBeanName("replyChannel");
outbound.setReplyChannel(replyChannel);
outbound.setBeanFactory(mock(BeanFactory.class));
outbound.afterPropertiesSet();
outbound.start();
outbound.handleMessage(new GenericMessage<String>("foo"));
Message<byte[]> result = (Message<byte[]>) replyChannel.receive(10000);
assertNotNull(result);
assertEquals("foo", new String(result.getPayload()));
// INT-4024 - second reply had bad connection id
outbound.handleMessage(new GenericMessage<String>("foo"));
result = (Message<byte[]>) replyChannel.receive(10000);
assertNotNull(result);
assertEquals("foo", new String(result.getPayload()));
inbound.stop();
outbound.stop();
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class RedisMessageGroupStoreTests method testWithMessageHistory.
@Test
@RedisAvailable
public void testWithMessageHistory() {
RedisConnectionFactory jcf = getConnectionFactoryForTest();
RedisMessageStore store = new RedisMessageStore(jcf);
Message<?> message = new GenericMessage<>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
barChannel.setBeanName("barChannel");
message = MessageHistory.write(message, fooChannel);
message = MessageHistory.write(message, barChannel);
store.addMessagesToGroup(this.groupId, message);
message = store.getMessageGroup(this.groupId).getMessages().iterator().next();
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class ContinuousQueryMessageProducerTests method setUp.
@Before
public void setUp() {
queryListenerContainer = mock(ContinuousQueryListenerContainer.class);
cqMessageProducer = new ContinuousQueryMessageProducer(queryListenerContainer, "foo");
DirectChannel outputChannel = new DirectChannel();
cqMessageProducer.setOutputChannel(outputChannel);
cqMessageProducer.setBeanFactory(mock(BeanFactory.class));
handler = new CqMessageHandler();
outputChannel.subscribe(handler);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class GemfireMessageStoreTests method testWithMessageHistory.
@Test
public void testWithMessageHistory() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
Message<?> message = new GenericMessage<String>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
barChannel.setBeanName("barChannel");
message = MessageHistory.write(message, fooChannel);
message = MessageHistory.write(message, barChannel);
store.addMessage(message);
message = store.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
}
Aggregations