Search in sources :

Example 31 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory 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"));
}
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 32 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testAddAndRemoveMessagesFromMessageGroup.

@Test
@RedisAvailable
public void testAddAndRemoveMessagesFromMessageGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore messageStore = new RedisMessageStore(jcf);
    List<Message<?>> messages = new ArrayList<Message<?>>();
    for (int i = 0; i < 25; i++) {
        Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(this.groupId).build();
        messageStore.addMessagesToGroup(this.groupId, message);
        messages.add(message);
    }
    MessageGroup group = messageStore.getMessageGroup(this.groupId);
    assertEquals(25, group.size());
    messageStore.removeMessagesFromGroup(this.groupId, messages);
    group = messageStore.getMessageGroup(this.groupId);
    assertEquals(0, group.size());
    messageStore.removeMessageGroup(this.groupId);
}
Also used : ErrorMessage(org.springframework.messaging.support.ErrorMessage) MutableMessage(org.springframework.integration.support.MutableMessage) Message(org.springframework.messaging.Message) AdviceMessage(org.springframework.integration.message.AdviceMessage) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Matchers.containsString(org.hamcrest.Matchers.containsString) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 33 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testMultipleInstancesOfGroupStore.

@Test
@RedisAvailable
public void testMultipleInstancesOfGroupStore() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store1 = new RedisMessageStore(jcf);
    RedisMessageStore store2 = new RedisMessageStore(jcf);
    store1.removeMessageGroup(this.groupId);
    Message<?> message = new GenericMessage<>("1");
    store1.addMessagesToGroup(this.groupId, message);
    MessageGroup messageGroup = store2.addMessageToGroup(this.groupId, new GenericMessage<>("2"));
    assertEquals(2, messageGroup.getMessages().size());
    RedisMessageStore store3 = new RedisMessageStore(jcf);
    store3.removeMessagesFromGroup(this.groupId, message);
    messageGroup = store3.getMessageGroup(this.groupId);
    assertEquals(1, messageGroup.getMessages().size());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 34 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
@RedisAvailable
public void testNonExistingEmptyMessageGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    MessageGroup messageGroup = store.getMessageGroup(this.groupId);
    assertNotNull(messageGroup);
    assertTrue(messageGroup instanceof SimpleMessageGroup);
    assertEquals(0, messageGroup.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 35 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testMessageGroupUpdatedDateChangesWithEachAddedMessage.

@Test
@RedisAvailable
public void testMessageGroupUpdatedDateChangesWithEachAddedMessage() throws Exception {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<?> message = new GenericMessage<>("Hello");
    MessageGroup messageGroup = store.addMessageToGroup(this.groupId, message);
    assertEquals(1, messageGroup.size());
    long createdTimestamp = messageGroup.getTimestamp();
    long updatedTimestamp = messageGroup.getLastModified();
    assertEquals(createdTimestamp, updatedTimestamp);
    Thread.sleep(10);
    message = new GenericMessage<>("Hello");
    messageGroup = store.addMessageToGroup(this.groupId, message);
    createdTimestamp = messageGroup.getTimestamp();
    updatedTimestamp = messageGroup.getLastModified();
    assertTrue(updatedTimestamp > createdTimestamp);
    // make sure the store is properly rebuild from Redis
    store = new RedisMessageStore(jcf);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(2, messageGroup.size());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)100 Test (org.junit.Test)83 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)62 GenericMessage (org.springframework.messaging.support.GenericMessage)22 BeanFactory (org.springframework.beans.factory.BeanFactory)19 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)17 MessageGroup (org.springframework.integration.store.MessageGroup)14 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 ArrayList (java.util.ArrayList)12 Properties (java.util.Properties)10 Message (org.springframework.messaging.Message)10 ApplicationContext (org.springframework.context.ApplicationContext)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 DefaultRedisZSet (org.springframework.data.redis.support.collections.DefaultRedisZSet)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 TypedTuple (org.springframework.data.redis.core.ZSetOperations.TypedTuple)6 LiteralExpression (org.springframework.expression.common.LiteralExpression)6