Search in sources :

Example 6 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddAndGetStringMessage.

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testAddAndGetStringMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    store.addMessage(stringMessage);
    Message<String> retrievedMessage = (Message<String>) store.getMessage(stringMessage.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals("Hello Redis", retrievedMessage.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 7 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testAddAndRemoveStringMessage.

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testAddAndRemoveStringMessage() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<String> stringMessage = new GenericMessage<String>("Hello Redis");
    store.addMessage(stringMessage);
    Message<String> retrievedMessage = (Message<String>) store.removeMessage(stringMessage.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals("Hello Redis", retrievedMessage.getPayload());
    assertNull(store.getMessage(stringMessage.getHeaders().getId()));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 8 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testGetMessageCountWhenEmpty.

@Test
@RedisAvailable
public void testGetMessageCountWhenEmpty() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    assertEquals(0, store.getMessageCount());
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 9 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisMessageStoreTests method testWithMessageHistory.

@Test
@RedisAvailable
public void testWithMessageHistory() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    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"));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 10 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisChannelParserTests method testPubSubChannelConfig.

@Test
@RedisAvailable
public void testPubSubChannelConfig() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("RedisChannelParserTests-context.xml", this.getClass());
    SubscribableChannel redisChannel = context.getBean("redisChannel", SubscribableChannel.class);
    RedisConnectionFactory connectionFactory = TestUtils.getPropertyValue(redisChannel, "connectionFactory", RedisConnectionFactory.class);
    RedisSerializer<?> redisSerializer = TestUtils.getPropertyValue(redisChannel, "serializer", RedisSerializer.class);
    assertEquals(connectionFactory, context.getBean("redisConnectionFactory"));
    assertEquals(redisSerializer, context.getBean("redisSerializer"));
    assertEquals("si.test.topic.parser", TestUtils.getPropertyValue(redisChannel, "topicName"));
    assertEquals(Integer.MAX_VALUE, TestUtils.getPropertyValue(TestUtils.getPropertyValue(redisChannel, "dispatcher"), "maxSubscribers", Integer.class).intValue());
    redisChannel = context.getBean("redisChannelWithSubLimit", SubscribableChannel.class);
    assertEquals(1, TestUtils.getPropertyValue(redisChannel, "dispatcher.maxSubscribers", Integer.class).intValue());
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    assertSame(mbf, TestUtils.getPropertyValue(redisChannel, "messageBuilderFactory"));
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SubscribableChannel(org.springframework.messaging.SubscribableChannel) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)99 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)99 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)62 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)28 GenericMessage (org.springframework.messaging.support.GenericMessage)24 BeanFactory (org.springframework.beans.factory.BeanFactory)23 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)16 MessageGroup (org.springframework.integration.store.MessageGroup)15 ArrayList (java.util.ArrayList)14 Lock (java.util.concurrent.locks.Lock)13 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)13 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 Message (org.springframework.messaging.Message)13 QueueChannel (org.springframework.integration.channel.QueueChannel)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8