Search in sources :

Example 46 with MessageGroup

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

the class JdbcMessageStoreTests method testCompleteMessageGroup.

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

Example 47 with MessageGroup

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

the class JdbcMessageStoreTests method testAddAndRemoveMessagesFromMessageGroup.

@Test
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
    String groupId = "X";
    this.messageStore.setRemoveBatchSize(10);
    List<Message<?>> messages = new ArrayList<Message<?>>();
    for (int i = 0; i < 25; i++) {
        Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
        messages.add(message);
    }
    this.messageStore.addMessagesToGroup(groupId, messages.toArray(new Message<?>[messages.size()]));
    MessageGroup group = this.messageStore.getMessageGroup(groupId);
    assertEquals(25, group.size());
    this.messageStore.removeMessagesFromGroup(groupId, messages);
    group = this.messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test)

Example 48 with MessageGroup

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

the class JdbcMessageStoreTests method testAddAndGetMessageGroup.

@Test
public void testAddAndGetMessageGroup() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    long now = System.currentTimeMillis();
    messageStore.addMessagesToGroup(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)

Example 49 with MessageGroup

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

the class JdbcMessageStoreTests method testUpdateLastReleasedSequence.

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

Example 50 with MessageGroup

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

the class JdbcMessageStoreTests method testOrderInMessageGroup.

@Test
public void testOrderInMessageGroup() throws Exception {
    String groupId = "X";
    this.messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("foo").setCorrelationId(groupId).build());
    Thread.sleep(1);
    this.messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
    MessageGroup group = this.messageStore.getMessageGroup(groupId);
    assertEquals(2, group.size());
    assertEquals("foo", this.messageStore.pollMessageFromGroup(groupId).getPayload());
    assertEquals("bar", this.messageStore.pollMessageFromGroup(groupId).getPayload());
}
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