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