Search in sources :

Example 41 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MySqlJdbcMessageStoreTests method testExpireMessageGroupOnIdleOnly.

@Test
@Transactional
public void testExpireMessageGroupOnIdleOnly() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.setTimeoutOnIdle(true);
    messageStore.addMessageToGroup(groupId, message);
    messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> messageGroupStore.removeMessageGroup(group.getGroupId()));
    Thread.sleep(1000);
    messageStore.expireMessageGroups(2000);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(1, group.size());
    Thread.sleep(2000);
    messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
    group = messageStore.getMessageGroup(groupId);
    assertEquals(2, group.size());
    Thread.sleep(2000);
    messageStore.expireMessageGroups(2000);
    group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MySqlJdbcMessageStoreTests method testExpireMessageGroupOnCreateOnly.

@Test
@Transactional
public void testExpireMessageGroupOnCreateOnly() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(groupId, message);
    messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> messageGroupStore.removeMessageGroup(group.getGroupId()));
    Thread.sleep(1000);
    messageStore.expireMessageGroups(2000);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(1, group.size());
    messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
    Thread.sleep(2001);
    messageStore.expireMessageGroups(2000);
    group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class MySqlJdbcMessageStoreTests method testAddAndGetMessageGroup.

@Test
@Transactional
public void testAddAndGetMessageGroup() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    long now = System.currentTimeMillis();
    messageStore.addMessageToGroup(groupId, message);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(1, group.size());
    assertTrue("Timestamp too early: " + group.getTimestamp() + "<" + now, group.getTimestamp() >= now);
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class JdbcMessageStoreChannelIntegrationTests method clear.

@Before
public void clear() {
    Service.reset(1);
    for (MessageGroup group : messageStore) {
        messageStore.removeMessageGroup(group.getGroupId());
    }
    this.serviceActivator.start();
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Before(org.junit.Before)

Example 45 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class JdbcMessageStoreTests method testAddAndRemoveMessageFromMessageGroup.

@Test
public void testAddAndRemoveMessageFromMessageGroup() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessagesToGroup(groupId, message);
    messageStore.removeMessagesFromGroup(groupId, message);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test)

Aggregations

MessageGroup (org.springframework.integration.store.MessageGroup)98 Test (org.junit.Test)79 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)54 GenericMessage (org.springframework.messaging.support.GenericMessage)36 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)25 Message (org.springframework.messaging.Message)20 ArrayList (java.util.ArrayList)19 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)15 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)14 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)13 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)13 MongoClient (com.mongodb.MongoClient)12 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)12 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 List (java.util.List)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 UUID (java.util.UUID)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HashMap (java.util.HashMap)5