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"));
}
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());
}
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));
}
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));
}
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();
}
Aggregations