Search in sources :

Example 66 with MessageGroup

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

the class DelayHandlerTests method testRescheduleForTheDateDelay.

@Test
public void testRescheduleForTheDateDelay() throws Exception {
    this.delayHandler.setDelayExpression(new SpelExpressionParser().parseExpression("payload"));
    this.delayHandler.setOutputChannel(new DirectChannel());
    this.delayHandler.setIgnoreExpressionFailures(false);
    startDelayerHandler();
    Calendar releaseDate = Calendar.getInstance();
    releaseDate.add(Calendar.HOUR, 1);
    this.delayHandler.handleMessage(new GenericMessage<>(releaseDate.getTime()));
    // emulate restart
    this.taskScheduler.destroy();
    MessageGroupStore messageStore = TestUtils.getPropertyValue(this.delayHandler, "messageStore", MessageGroupStore.class);
    MessageGroup messageGroup = messageStore.getMessageGroup(DELAYER_MESSAGE_GROUP_ID);
    Message<?> messageInStore = messageGroup.getMessages().iterator().next();
    Object payload = messageInStore.getPayload();
    DirectFieldAccessor dfa = new DirectFieldAccessor(payload);
    long requestTime = (long) dfa.getPropertyValue("requestDate");
    Calendar requestDate = Calendar.getInstance();
    requestDate.setTimeInMillis(requestTime);
    requestDate.add(Calendar.HOUR, -2);
    dfa.setPropertyValue("requestDate", requestDate.getTimeInMillis());
    this.taskScheduler.afterPropertiesSet();
    this.delayHandler.reschedulePersistedMessages();
    Queue<?> works = TestUtils.getPropertyValue(this.taskScheduler, "scheduledExecutor.workQueue", Queue.class);
    int n = 0;
    while (n++ < 2000 && works.size() == 0) {
        Thread.sleep(10);
    }
    assertEquals(1, works.size());
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) DirectChannel(org.springframework.integration.channel.DirectChannel) Calendar(java.util.Calendar) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test)

Example 67 with MessageGroup

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

the class GemfireGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
public void testNonExistingEmptyMessageGroup() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    assertNotNull(messageGroup);
    assertTrue(messageGroup instanceof SimpleMessageGroup);
    assertEquals(0, messageGroup.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 68 with MessageGroup

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

the class GemfireGroupStoreTests method testRemoveNonExistingMessageFromTheGroup.

@Test
public void testRemoveNonExistingMessageFromTheGroup() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<String>("1"));
    store.removeMessagesFromGroup(1, new GenericMessage<String>("2"));
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 69 with MessageGroup

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

the class GemfireGroupStoreTests method testRemoveMessageGroup.

@Test
public void testRemoveMessageGroup() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("Hello");
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
    assertEquals(1, messageGroup.size());
    store.removeMessageGroup(1);
    MessageGroup messageGroupA = store.getMessageGroup(1);
    assertNotSame(messageGroup, messageGroupA);
    assertEquals(0, messageGroupA.getMessages().size());
    assertEquals(0, messageGroupA.size());
    // make sure the store is properly rebuild from Gemfire
    store = new GemfireMessageStore(region);
    messageGroup = store.getMessageGroup(1);
    assertEquals(0, messageGroup.getMessages().size());
    assertEquals(0, messageGroup.size());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 70 with MessageGroup

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

the class GemfireGroupStoreTests method testLastReleasedSequenceNumber.

@Test
public void testLastReleasedSequenceNumber() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> messageToMark = new GenericMessage<String>("1");
    store.addMessagesToGroup(messageGroup.getGroupId(), messageToMark);
    store.setLastReleasedSequenceNumberForGroup(messageGroup.getGroupId(), 5);
    messageGroup = store.getMessageGroup(1);
    assertEquals(5, messageGroup.getLastReleasedMessageSequenceNumber());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) 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