Example usage for org.springframework.integration.store MessageGroupQueue size

List of usage examples for org.springframework.integration.store MessageGroupQueue size

Introduction

In this page you can find the example usage for org.springframework.integration.store MessageGroupQueue size.

Prototype

@Override
    public int size() 

Source Link

Usage

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

@Test
public void testSize() throws Exception {
    MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), "FOO");
    queue.put(new GenericMessage<String>("foo"));
    assertEquals(1, queue.size());
    queue.poll(100, TimeUnit.MILLISECONDS);
    assertEquals(0, queue.size());//w w w .j  ava 2 s.  c om
}

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

private void doTestConcurrentAccess(int concurrency, final int maxPerTask, final Set<String> set)
        throws Exception {

    SimpleMessageStore messageGroupStore = new SimpleMessageStore();
    final MessageGroupQueue queue = new MessageGroupQueue(messageGroupStore, "FOO");
    ExecutorService executorService = Executors.newCachedThreadPool();
    CompletionService<Boolean> completionService = new ExecutorCompletionService<Boolean>(executorService);

    for (int i = 0; i < concurrency; i++) {

        final int big = i;

        completionService.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
                boolean result = true;
                for (int j = 0; j < maxPerTask; j++) {
                    result &= queue.add(new GenericMessage<String>("count=" + big + ":" + j));
                    if (!result) {
                        logger.warn("Failed to add");
                    }//from   w  w  w  .  j  a va  2  s .co m
                }
                return result;
            }
        });

        completionService.submit(new Callable<Boolean>() {
            public Boolean call() throws Exception {
                boolean result = true;
                for (int j = 0; j < maxPerTask; j++) {
                    @SuppressWarnings("unchecked")
                    Message<String> item = (Message<String>) queue.poll(10, TimeUnit.SECONDS);
                    result &= item != null;
                    if (!result) {
                        logger.warn("Failed to poll");
                    } else if (set != null) {
                        synchronized (set) {
                            set.add(item.getPayload());
                        }
                    }
                }
                return result;
            }
        });

        messageGroupStore.expireMessageGroups(-10000);

    }

    for (int j = 0; j < 2 * concurrency; j++) {
        assertTrue(completionService.take().get());
    }

    if (set != null) {
        // Ensure all items polled are unique
        assertEquals(concurrency * maxPerTask, set.size());
    }

    assertEquals(0, queue.size());
    messageGroupStore.expireMessageGroups(-10000);
    assertEquals(Integer.MAX_VALUE, queue.remainingCapacity());

    executorService.shutdown();

}