Search in sources :

Example 1 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
@MongoDbAvailable
public void testNonExistingEmptyMessageGroup() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = getMessageGroupStore();
    store.addMessagesToGroup(1, new GenericMessage<Object>("foo"));
    MessageGroup messageGroup = store.getMessageGroup(1);
    assertNotNull(messageGroup);
    assertThat(messageGroup.getClass().getName(), containsString("PersistentMessageGroup"));
    assertEquals(1, messageGroup.size());
}
Also used : MongoClient(com.mongodb.MongoClient) 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 2 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader.

@Test
@MongoDbAvailable
public void testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    MessageStore messageStore = this.getMessageStore();
    Object id = UUID.randomUUID();
    MessageGroup messageGroup = store.getMessageGroup(id);
    UUID uuidA = UUID.randomUUID();
    Message<?> messageA = MessageBuilder.withPayload("A").setHeader("foo", uuidA).build();
    UUID uuidB = UUID.randomUUID();
    Message<?> messageB = MessageBuilder.withPayload("B").setHeader("foo", uuidB).build();
    store.addMessagesToGroup(id, messageA);
    messageGroup = store.addMessageToGroup(id, messageB);
    assertNotNull(messageGroup);
    assertEquals(2, messageGroup.size());
    Message<?> retrievedMessage = messageStore.getMessage(messageA.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals(retrievedMessage.getHeaders().getId(), messageA.getHeaders().getId());
    // ensure that 'message_group' header that is only used internally is not propagated
    assertNull(retrievedMessage.getHeaders().get("message_group"));
    Object fooHeader = retrievedMessage.getHeaders().get("foo");
    assertTrue(fooHeader instanceof UUID);
    assertEquals(uuidA, fooHeader);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) 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) UUID(java.util.UUID) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 3 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testWithMessageHistory.

@Test
@MongoDbAvailable
public void testWithMessageHistory() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    store.getMessageGroup(1);
    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.addMessagesToGroup(1, message);
    MessageGroup group = store.getMessageGroup(1);
    assertNotNull(group);
    Collection<Message<?>> messages = group.getMessages();
    assertTrue(!messages.isEmpty());
    message = messages.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 : MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageGroup(org.springframework.integration.store.MessageGroup) Properties(java.util.Properties) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 4 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testSameMessageMultipleGroupsPoll.

@Test
@MongoDbAvailable
public void testSameMessageMultipleGroupsPoll() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    Message<?> messageA = new GenericMessage<String>("A");
    store.addMessagesToGroup(1, messageA);
    store.addMessagesToGroup(2, messageA);
    store.addMessagesToGroup(3, messageA);
    store.addMessagesToGroup(4, messageA);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(1, store.messageGroupSize(3));
    assertEquals(1, store.messageGroupSize(4));
    store.pollMessageFromGroup(3);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(1, store.messageGroupSize(4));
    store.pollMessageFromGroup(4);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.pollMessageFromGroup(2);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(0, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.pollMessageFromGroup(1);
    assertEquals(0, store.messageGroupSize(1));
    assertEquals(0, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
}
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) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 5 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testCountMessagesInGroup.

@Test
@MongoDbAvailable
public void testCountMessagesInGroup() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    Message<?> messageA = new GenericMessage<String>("A");
    Message<?> messageB = new GenericMessage<String>("B");
    store.addMessagesToGroup(1, messageA, messageB);
    assertEquals(2, store.messageGroupSize(1));
}
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) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

Test (org.junit.Test)70 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)70 MongoClient (com.mongodb.MongoClient)28 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)28 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)27 GenericMessage (org.springframework.messaging.support.GenericMessage)20 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)19 LiteralExpression (org.springframework.expression.common.LiteralExpression)17 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)17 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)17 MessageStore (org.springframework.integration.store.MessageStore)14 BeanFactory (org.springframework.beans.factory.BeanFactory)13 MessageGroup (org.springframework.integration.store.MessageGroup)13 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 Expression (org.springframework.expression.Expression)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)6 MessageChannel (org.springframework.messaging.MessageChannel)6 PollableChannel (org.springframework.messaging.PollableChannel)6