List of usage examples for org.springframework.integration.store MessageGroupQueue MessageGroupQueue
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId)
From source file:org.springframework.integration.store.MessageGroupQueueTests.java
@Test public void testPutAndPoll() throws Exception { MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), "FOO"); queue.put(new GenericMessage<String>("foo")); Message<?> result = queue.poll(100, TimeUnit.MILLISECONDS); assertNotNull(result);/*from w w w .j a va 2 s .co m*/ }
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());/*from w ww .j a v a2s. c o m*/ queue.poll(100, TimeUnit.MILLISECONDS); assertEquals(0, queue.size()); }
From source file:org.springframework.integration.store.MessageGroupQueueTests.java
@Test public void testPutAndTake() throws Exception { MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), "FOO"); queue.put(new GenericMessage<String>("foo")); Message<?> result = queue.take(); assertNotNull(result);//ww w. jav a2 s . c o m }
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"); }//www . j a va 2 s.c o 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(); }