Search in sources :

Example 41 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupWithAddedMessagePrimitiveGroupId.

@Test
@MongoDbAvailable
public void testMessageGroupWithAddedMessagePrimitiveGroupId() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    MessageStore messageStore = this.getMessageStore();
    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());
    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"));
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) 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 42 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory 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 43 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testSameMessageMultipleGroupsRemove.

@Test
@MongoDbAvailable
public void testSameMessageMultipleGroupsRemove() 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.removeMessagesFromGroup(3, messageA);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(1, store.messageGroupSize(4));
    store.removeMessagesFromGroup(4, messageA);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.removeMessagesFromGroup(2, messageA);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(0, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.removeMessagesFromGroup(1, messageA);
    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 44 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class AbstractMongoDbMessageGroupStoreTests method testPollMessages.

@Test
@MongoDbAvailable
public void testPollMessages() 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);
    Thread.sleep(10);
    store.addMessagesToGroup(1, messageB);
    assertEquals(2, store.messageGroupSize(1));
    Message<?> out = store.pollMessageFromGroup(1);
    assertNotNull(out);
    assertEquals("A", out.getPayload());
    assertEquals(1, store.messageGroupSize(1));
    out = store.pollMessageFromGroup(1);
    assertEquals("B", out.getPayload());
    assertEquals(0, 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)

Example 45 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class ConfigurableMongoDbMessageGroupStoreTests method testPriorityChannel.

@Test
@MongoDbAvailable
public void testPriorityChannel() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ConfigurableMongoDbMessageStore-CustomConverter.xml", this.getClass());
    context.refresh();
    Object priorityChannel = context.getBean("priorityChannel");
    assertThat(priorityChannel, Matchers.instanceOf(PriorityChannel.class));
    QueueChannel channel = (QueueChannel) priorityChannel;
    Message<String> message = MessageBuilder.withPayload("1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("-1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, -1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("3").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    message = MessageBuilder.withPayload("0").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 0).build();
    channel.send(message);
    message = MessageBuilder.withPayload("2").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 2).build();
    channel.send(message);
    message = MessageBuilder.withPayload("none").build();
    channel.send(message);
    message = MessageBuilder.withPayload("31").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    Message<?> receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("3", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("31", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("2", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("0", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("-1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("none", receive.getPayload());
    context.close();
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PriorityChannel(org.springframework.integration.channel.PriorityChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)51 MongoClient (com.mongodb.MongoClient)38 Test (org.junit.Test)28 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)28 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)16 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)16 GenericMessage (org.springframework.messaging.support.GenericMessage)14 MessageGroup (org.springframework.integration.store.MessageGroup)12 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)10 Bean (org.springframework.context.annotation.Bean)9 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)8 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)8 MessageStore (org.springframework.integration.store.MessageStore)8 MongoClientURI (com.mongodb.MongoClientURI)6 Net (de.flapdoodle.embed.mongo.config.Net)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)4 ClaimCheckOutTransformer (org.springframework.integration.transformer.ClaimCheckOutTransformer)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3