use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class PriorityChannelSpec method messageStore.
public PriorityChannelSpec messageStore(PriorityCapableChannelMessageStore messageGroupStore, Object groupId) {
this.messageGroupQueue = new MessageGroupQueue(messageGroupStore, groupId);
this.messageGroupQueue.setPriority(true);
return this;
}
use of org.springframework.integration.store.MessageGroupQueue 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.MessageGroupQueue 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"));
}
use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class MessageGroupQueueTests method testConcurrentReadWrite.
@Test
public void testConcurrentReadWrite() throws Exception {
final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 1);
final AtomicReference<Message<?>> messageHolder = new AtomicReference<Message<?>>();
Thread t1 = new Thread(() -> {
try {
messageHolder.set(queue.poll(1000, TimeUnit.SECONDS));
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue poll failed", e);
}
});
Thread t2 = new Thread(() -> {
try {
queue.offer(new GenericMessage<String>("hello"), 1000, TimeUnit.SECONDS);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
t1.start();
t2.start();
Thread.sleep(1000);
assertTrue(messageHolder.get() instanceof Message);
}
use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class MessageGroupQueueTests method validateMgqInterruptionStoreLock.
@Test
public void validateMgqInterruptionStoreLock() throws Exception {
MessageGroupStore mgs = Mockito.mock(MessageGroupStore.class);
Mockito.doAnswer(invocation -> {
Thread.sleep(5000);
return null;
}).when(mgs).addMessageToGroup(Mockito.any(Integer.class), Mockito.any(Message.class));
MessageGroup mg = Mockito.mock(MessageGroup.class);
Mockito.when(mgs.getMessageGroup(Mockito.any())).thenReturn(mg);
Mockito.when(mg.size()).thenReturn(0);
final MessageGroupQueue queue = new MessageGroupQueue(mgs, 1, 1);
final AtomicReference<InterruptedException> exceptionHolder = new AtomicReference<InterruptedException>();
Thread t1 = new Thread(() -> queue.offer(new GenericMessage<String>("hello")));
t1.start();
Thread.sleep(500);
Thread t2 = new Thread(() -> {
queue.offer(new GenericMessage<String>("hello"));
try {
queue.offer(new GenericMessage<String>("hello"), 100, TimeUnit.SECONDS);
} catch (InterruptedException e) {
exceptionHolder.set(e);
}
});
t2.start();
Thread.sleep(1000);
t2.interrupt();
Thread.sleep(1000);
assertTrue(exceptionHolder.get() instanceof InterruptedException);
}
Aggregations