Search in sources :

Example 6 with SimpleMessageStore

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

the class AggregatorTests method testAggPerfDefaultPartial.

@Test
public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException, TimeoutException {
    AggregatingMessageHandler handler = new AggregatingMessageHandler(new DefaultAggregatingMessageGroupProcessor());
    handler.setCorrelationStrategy(message -> "foo");
    handler.setReleasePartialSequences(true);
    DirectChannel outputChannel = new DirectChannel();
    handler.setOutputChannel(outputChannel);
    final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>();
    outputChannel.subscribe(message -> {
        Collection<?> payload = (Collection<?>) message.getPayload();
        logger.warn("Received " + payload.size());
        resultFuture.complete(payload);
    });
    SimpleMessageStore store = new SimpleMessageStore();
    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE);
    store.setMessageGroupFactory(messageGroupFactory);
    handler.setMessageStore(store);
    StopWatch stopwatch = new StopWatch();
    stopwatch.start();
    for (int i = 0; i < 120000; i++) {
        if (i % 10000 == 0) {
            stopwatch.stop();
            logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
            stopwatch.start();
        }
        handler.handleMessage(MessageBuilder.withPayload("foo").setSequenceSize(120000).setSequenceNumber(i + 1).build());
    }
    stopwatch.stop();
    logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in " + stopwatch.getLastTaskTimeMillis() + "ms)");
    Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(result);
    assertEquals(120000, result.size());
    // actually < 2.0, was many minutes
    assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageGroupFactory(org.springframework.integration.store.SimpleMessageGroupFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) Collection(java.util.Collection) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 7 with SimpleMessageStore

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

the class ResequencerTests method testResequencingWithCapacity.

@Test
public void testResequencingWithCapacity() throws InterruptedException {
    this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
    // INT-3846
    this.resequencer.setMessageStore(new SimpleMessageStore(3, 2));
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message1 = createMessage("123", "ABC", 4, 4, replyChannel);
    Message<?> message2 = createMessage("456", "ABC", 4, 2, replyChannel);
    Message<?> message3 = createMessage("789", "ABC", 4, 1, replyChannel);
    this.resequencer.handleMessage(message1);
    this.resequencer.handleMessage(message2);
    try {
        this.resequencer.handleMessage(message3);
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getMessage(), containsString("out of capacity (2) for group 'ABC'"));
    }
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Example 8 with SimpleMessageStore

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

the class ClaimCheckTransformerTests method unknown.

@Test(expected = MessageTransformationException.class)
public void unknown() {
    MessageStore store = new SimpleMessageStore(10);
    ClaimCheckOutTransformer transformer = new ClaimCheckOutTransformer(store);
    transformer.transform(MessageBuilder.withPayload(UUID.randomUUID()).build());
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) Test(org.junit.Test)

Example 9 with SimpleMessageStore

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

the class MessageGroupQueueTests method validateMgqInterruption.

@Test
public void validateMgqInterruption() throws Exception {
    final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 1);
    final AtomicReference<InterruptedException> exceptionHolder = new AtomicReference<InterruptedException>();
    Thread t = new Thread(() -> {
        queue.offer(new GenericMessage<String>("hello"));
        try {
            queue.offer(new GenericMessage<String>("hello"), 100, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            exceptionHolder.set(e);
        }
    });
    t.start();
    Thread.sleep(1000);
    t.interrupt();
    Thread.sleep(1000);
    assertTrue(exceptionHolder.get() instanceof InterruptedException);
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) MessageGroupQueue(org.springframework.integration.store.MessageGroupQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 10 with SimpleMessageStore

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

the class MessageGroupQueueTests method testConcurrentWriteRead.

@Test
public void testConcurrentWriteRead() throws Exception {
    final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 1);
    final AtomicReference<Message<?>> messageHolder = new AtomicReference<Message<?>>();
    queue.offer(new GenericMessage<String>("hello"), 1000, TimeUnit.SECONDS);
    Thread t1 = new Thread(() -> {
        try {
            queue.offer(new GenericMessage<String>("Hi"), 1000, TimeUnit.SECONDS);
        } catch (Exception e) {
            LogFactory.getLog(getClass()).error("queue offer failed", e);
        }
    });
    Thread t2 = new Thread(() -> {
        try {
            queue.poll(1000, TimeUnit.SECONDS);
            messageHolder.set(queue.poll(1000, TimeUnit.SECONDS));
        } catch (Exception e) {
            LogFactory.getLog(getClass()).error("queue poll failed", e);
        }
    });
    t1.start();
    Thread.sleep(1000);
    t2.start();
    Thread.sleep(1000);
    assertTrue(messageHolder.get().getPayload().equals("Hi"));
}
Also used : SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroupQueue(org.springframework.integration.store.MessageGroupQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)25 Test (org.junit.Test)20 GenericMessage (org.springframework.messaging.support.GenericMessage)10 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)8 Message (org.springframework.messaging.Message)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 MessageGroupQueue (org.springframework.integration.store.MessageGroupQueue)6 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)6 QueueChannel (org.springframework.integration.channel.QueueChannel)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)3 MessageStore (org.springframework.integration.store.MessageStore)3 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutorService (java.util.concurrent.ExecutorService)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 MessageGroup (org.springframework.integration.store.MessageGroup)2 SimpleMessageGroupFactory (org.springframework.integration.store.SimpleMessageGroupFactory)2 StopWatch (org.springframework.util.StopWatch)2 Method (java.lang.reflect.Method)1