Example usage for org.springframework.integration.store MessageGroupStore getMessageGroup

List of usage examples for org.springframework.integration.store MessageGroupStore getMessageGroup

Introduction

In this page you can find the example usage for org.springframework.integration.store MessageGroupStore getMessageGroup.

Prototype

MessageGroup getMessageGroup(Object groupId);

Source Link

Document

Return all Messages currently in the MessageStore that were stored using #addMessageToGroup(Object,Message) with this group id.

Usage

From source file:org.springframework.integration.jdbc.MessageGroupQueueTests.java

@Test
public void validateMgqInterruptionStoreLock() throws Exception {

    MessageGroupStore mgs = Mockito.mock(MessageGroupStore.class);
    Mockito.doAnswer(invocation -> {/*from   ww  w.  j  av a2s  .c om*/
        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);
}