Search in sources :

Example 56 with MessageGroup

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

the class AbstractCorrelatingMessageHandlerTests method testDontReapIfNewGroupFoundDuringRefetch.

/*
	 * INT-3216 - Verifies we don't complete if it's a completely new group (different timestamp).
	 */
@Test
public void testDontReapIfNewGroupFoundDuringRefetch() throws Exception {
    MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor();
    AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp);
    handler.setReleaseStrategy(group -> true);
    QueueChannel outputChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
    mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"));
    MessageGroup group = new SimpleMessageGroup(mgs.getMessageGroup("foo"));
    mgs = spy(mgs);
    new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs);
    Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
    forceComplete.setAccessible(true);
    MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class).get("foo");
    assertFalse(groupInStore.isComplete());
    assertFalse(group.isComplete());
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(group);
    directFieldAccessor.setPropertyValue("lastModified", groupInStore.getLastModified());
    directFieldAccessor.setPropertyValue("timestamp", groupInStore.getTimestamp() - 1);
    forceComplete.invoke(handler, group);
    verify(mgs).getMessageGroup("foo");
    assertNull(outputChannel.receive(0));
}
Also used : MessageGroupStore(org.springframework.integration.store.MessageGroupStore) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Method(java.lang.reflect.Method) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 57 with MessageGroup

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

the class AbstractCorrelatingMessageHandlerTests method testDontReapIfAlreadyComplete.

@Test
public /* INT-3216 */
void testDontReapIfAlreadyComplete() throws Exception {
    MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor();
    AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp);
    handler.setReleaseStrategy(group -> true);
    QueueChannel outputChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
    mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"));
    mgs.completeGroup("foo");
    mgs = spy(mgs);
    new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs);
    Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
    forceComplete.setAccessible(true);
    MessageGroup group = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class).get("foo");
    assertTrue(group.isComplete());
    forceComplete.invoke(handler, group);
    verify(mgs, never()).getMessageGroup("foo");
    assertNull(outputChannel.receive(0));
}
Also used : MessageGroupStore(org.springframework.integration.store.MessageGroupStore) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 58 with MessageGroup

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

the class AggregatingMessageGroupProcessorHeaderTests method twoMessagesWithConflicts.

private void twoMessagesWithConflicts(MessageGroupProcessor processor) {
    Map<String, Object> headers1 = new HashMap<String, Object>();
    headers1.put("k1", "foo");
    headers1.put("k2", new Integer(123));
    Message<?> message1 = correlatedMessage(1, 2, 1, headers1);
    Map<String, Object> headers2 = new HashMap<String, Object>();
    headers2.put("k1", "bar");
    headers2.put("k2", new Integer(123));
    Message<?> message2 = correlatedMessage(1, 2, 2, headers2);
    List<Message<?>> messages = Arrays.<Message<?>>asList(message1, message2);
    MessageGroup group = new SimpleMessageGroup(messages, 1);
    Object result = processor.processMessageGroup(group);
    assertNotNull(result);
    assertTrue(result instanceof Message<?>);
    Message<?> resultMessage = (Message<?>) result;
    assertNull(resultMessage.getHeaders().get("k1"));
    assertEquals(123, resultMessage.getHeaders().get("k2"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 59 with MessageGroup

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

the class MethodInvokingReleaseStrategyTests method testInvalidParameterTypeUsingMethodName.

@Test(expected = IllegalStateException.class)
public void testInvalidParameterTypeUsingMethodName() {
    class TestReleaseStrategy {

        @SuppressWarnings("unused")
        public boolean invalidParameterType(Date invalid) {
            return true;
        }
    }
    ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "invalidParameterType");
    MessageGroup messages = createListOfMessages(3);
    Assert.assertTrue(adapter.canRelease(messages));
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Date(java.util.Date) Test(org.junit.Test)

Example 60 with MessageGroup

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

the class MethodInvokingReleaseStrategyTests method testAdapterWithWildcardParametrizedMessageBasedMethod.

@Test
public void testAdapterWithWildcardParametrizedMessageBasedMethod() {
    class TestReleaseStrategy {

        @SuppressWarnings("unused")
        public boolean checkCompletenessOnListOfMessagesParametrizedWithWildcard(List<Message<?>> messages) {
            Assert.assertTrue(messages.size() > 0);
            return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
        }
    }
    ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnListOfMessagesParametrizedWithWildcard");
    MessageGroup messages = createListOfMessages(3);
    Assert.assertTrue(adapter.canRelease(messages));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

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