Search in sources :

Example 81 with MessageGroup

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

the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupMarkingMessage.

@Test
@MongoDbAvailable
public void testMessageGroupMarkingMessage() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> messageA = new GenericMessage<String>("A");
    Message<?> messageB = new GenericMessage<String>("B");
    store.addMessagesToGroup(1, messageA);
    messageGroup = store.addMessageToGroup(1, messageB);
    assertNotNull(messageGroup);
    assertEquals(2, messageGroup.size());
    store.removeMessagesFromGroup(1, messageA);
    messageGroup = store.getMessageGroup(1);
    assertEquals(1, messageGroup.size());
    // validate that the updates were propagated to Mongo as well
    store = this.getMessageGroupStore();
    messageGroup = store.getMessageGroup(1);
    assertEquals(1, messageGroup.size());
}
Also used : MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 82 with MessageGroup

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

the class MySqlJdbcMessageStoreTests method testRemoveMessageGroup.

@Test
@Transactional
public void testRemoveMessageGroup() throws Exception {
    JdbcTemplate template = new JdbcTemplate(dataSource);
    template.afterPropertiesSet();
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(groupId, message);
    messageStore.removeMessageGroup(groupId);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
    String uuidGroupId = UUIDConverter.getUUID(groupId).toString();
    assertTrue(template.queryForList("SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = '" + uuidGroupId + "'").size() == 0);
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 83 with MessageGroup

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

the class MySqlJdbcMessageStoreTests method testAddAndRemoveMessageFromMessageGroup.

@Test
@Transactional
public void testAddAndRemoveMessageFromMessageGroup() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 84 with MessageGroup

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

the class MySqlJdbcMessageStoreTests method testCompleteMessageGroup.

@Test
@Transactional
public void testCompleteMessageGroup() throws Exception {
    String groupId = "X";
    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 85 with MessageGroup

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

the class MySqlJdbcMessageStoreTests method testOrderInMessageGroup.

@Test
@Transactional
public void testOrderInMessageGroup() throws Exception {
    String groupId = "X";
    messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("foo").setCorrelationId(groupId).build());
    Thread.sleep(1);
    messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(2, group.size());
    assertEquals("foo", messageStore.pollMessageFromGroup(groupId).getPayload());
    assertEquals("bar", messageStore.pollMessageFromGroup(groupId).getPayload());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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