Search in sources :

Example 1 with RedisInboundChannelAdapter

use of org.springframework.integration.redis.inbound.RedisInboundChannelAdapter in project spring-integration by spring-projects.

the class RedisInboundChannelAdapterParserTests method testInboundChannelAdapterMessaging.

@Test
@RedisAvailable
public void testInboundChannelAdapterMessaging() throws Exception {
    RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class);
    this.awaitContainerSubscribedWithPatterns(TestUtils.getPropertyValue(adapter, "container", RedisMessageListenerContainer.class));
    RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
    connectionFactory.getConnection().publish("foo".getBytes(), "Hello Redis from foo".getBytes());
    connectionFactory.getConnection().publish("bar".getBytes(), "Hello Redis from bar".getBytes());
    QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
    for (int i = 0; i < 3; i++) {
        Message<?> receive = receiveChannel.receive(10000);
        assertNotNull(receive);
        assertThat(receive.getPayload(), Matchers.<Object>isOneOf("Hello Redis from foo", "Hello Redis from bar"));
    }
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) RedisInboundChannelAdapter(org.springframework.integration.redis.inbound.RedisInboundChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 2 with RedisInboundChannelAdapter

use of org.springframework.integration.redis.inbound.RedisInboundChannelAdapter in project spring-integration by spring-projects.

the class RedisInboundChannelAdapterParserTests method validateConfiguration.

@Test
public void validateConfiguration() {
    RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class);
    assertEquals("adapter", adapter.getComponentName());
    assertEquals("redis:inbound-channel-adapter", adapter.getComponentType());
    DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
    Object errorChannelBean = context.getBean("testErrorChannel");
    assertEquals(errorChannelBean, accessor.getPropertyValue("errorChannel"));
    Object converterBean = context.getBean("testConverter");
    assertEquals(converterBean, accessor.getPropertyValue("messageConverter"));
    assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer"));
    Object container = accessor.getPropertyValue("container");
    DirectFieldAccessor containerAccessor = new DirectFieldAccessor(container);
    assertSame(this.executor, containerAccessor.getPropertyValue("taskExecutor"));
    Object bean = context.getBean("withoutSerializer.adapter");
    assertNotNull(bean);
    assertNull(TestUtils.getPropertyValue(bean, "serializer"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RedisInboundChannelAdapter(org.springframework.integration.redis.inbound.RedisInboundChannelAdapter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 RedisInboundChannelAdapter (org.springframework.integration.redis.inbound.RedisInboundChannelAdapter)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1 RedisMessageListenerContainer (org.springframework.data.redis.listener.RedisMessageListenerContainer)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)1