use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project ocvn by devgateway.
the class MongoTemplateConfig method shadowMongoTemplate.
/**
* Creates a shadow template configuration by adding "-shadow" as postfix of database name.
* This is used to replicate the entire database structure in a shadow/temporary database location
*
* @return
* @throws Exception
*/
@Bean(autowire = Autowire.BY_NAME, name = "shadowMongoTemplate")
public MongoTemplate shadowMongoTemplate() throws Exception {
MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(properties.getUri() + SHADOW_POSTFIX)));
((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
return template;
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testRemoveMessageGroup.
@Test
@MongoDbAvailable
public void testRemoveMessageGroup() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = this.getMessageGroupStore();
MessageStore messageStore = this.getMessageStore();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
UUID id = message.getHeaders().getId();
messageGroup = store.addMessageToGroup(1, message);
assertNotNull(messageGroup);
assertEquals(1, messageGroup.size());
message = messageStore.getMessage(id);
assertNotNull(message);
store.removeMessageGroup(1);
MessageGroup messageGroupA = store.getMessageGroup(1);
assertEquals(0, messageGroupA.size());
assertFalse(messageGroupA.equals(messageGroup));
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupIterator.
@Test
@MongoDbAvailable
public void testMessageGroupIterator() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store1 = this.getMessageGroupStore();
MessageGroupStore store2 = this.getMessageGroupStore();
Message<?> message = new GenericMessage<String>("1");
store2.addMessagesToGroup("1", message);
store1.addMessagesToGroup("2", new GenericMessage<String>("2"));
store2.addMessagesToGroup("3", new GenericMessage<String>("3"));
MessageGroupStore store3 = this.getMessageGroupStore();
Iterator<MessageGroup> iterator = store3.iterator();
assertNotNull(iterator);
int counter = 0;
while (iterator.hasNext()) {
iterator.next();
counter++;
}
assertEquals(3, counter);
store2.removeMessagesFromGroup("1", message);
iterator = store3.iterator();
counter = 0;
while (iterator.hasNext()) {
iterator.next();
counter++;
}
assertEquals(2, counter);
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testWithAggregatorWithShutdown.
// @Test
// @MongoDbAvailable
// public void testConcurrentModifications() throws Exception{
// MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
// final MongoDbMessageStore store1 = new MongoDbMessageStore(mongoDbFactory);
// final MongoDbMessageStore store2 = new MongoDbMessageStore(mongoDbFactory);
//
// final Message<?> message = new GenericMessage<String>("1");
//
// ExecutorService executor = null;
//
// final List<Object> failures = new ArrayList<Object>();
//
// for (int i = 0; i < 100; i++) {
// executor = Executors.newCachedThreadPool();
//
// executor.execute(new Runnable() {
// public void run() {
// MessageGroup group = store1.addMessageToGroup(1, message);
// if (group.getUnmarked().size() != 1){
// failures.add("ADD");
// throw new AssertionFailedError("Failed on ADD");
// }
// }
// });
// executor.execute(new Runnable() {
// public void run() {
// MessageGroup group = store2.removeMessageFromGroup(1, message);
// if (group.getUnmarked().size() != 0){
// failures.add("REMOVE");
// throw new AssertionFailedError("Failed on Remove");
// }
// }
// });
//
// executor.shutdown();
// executor.awaitTermination(10, TimeUnit.SECONDS);
// store2.removeMessageFromGroup(1, message); // ensures that if ADD thread executed after REMOVE, the store is empty for the next cycle
// }
// assertTrue(failures.size() == 0);
// }
protected void testWithAggregatorWithShutdown(String config) throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config, this.getClass());
context.refresh();
MessageChannel input = context.getBean("inputChannel", MessageChannel.class);
QueueChannel output = context.getBean("outputChannel", QueueChannel.class);
Message<?> m1 = MessageBuilder.withPayload("1").setSequenceNumber(1).setSequenceSize(10).setCorrelationId(1).build();
Message<?> m2 = MessageBuilder.withPayload("2").setSequenceNumber(2).setSequenceSize(10).setCorrelationId(1).build();
input.send(m1);
assertNull(output.receive(1000));
input.send(m2);
assertNull(output.receive(1000));
for (int i = 3; i < 10; i++) {
input.send(MessageBuilder.withPayload("" + i).setSequenceNumber(i).setSequenceSize(10).setCorrelationId(1).build());
}
context.close();
context = new ClassPathXmlApplicationContext(config, this.getClass());
input = context.getBean("inputChannel", MessageChannel.class);
output = context.getBean("outputChannel", QueueChannel.class);
Message<?> m10 = MessageBuilder.withPayload("10").setSequenceNumber(10).setSequenceSize(10).setCorrelationId(1).build();
input.send(m10);
assertNotNull(output.receive(2000));
context.close();
}
use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testCompleteMessageGroup.
@Test
@MongoDbAvailable
public void testCompleteMessageGroup() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = this.getMessageGroupStore();
MessageGroup messageGroup = store.getMessageGroup(1);
assertNotNull(messageGroup);
Message<?> message = new GenericMessage<String>("Hello");
store.addMessagesToGroup(messageGroup.getGroupId(), message);
store.completeGroup(messageGroup.getGroupId());
messageGroup = store.getMessageGroup(1);
assertTrue(messageGroup.isComplete());
}
Aggregations