List of usage examples for org.springframework.integration.store MessageGroupQueue remainingCapacity
@Override
public int remainingCapacity()
From source file:org.springframework.integration.store.MessageGroupQueueTests.java
@Test public void testCapacityAfterExpiry() throws Exception { SimpleMessageStore messageGroupStore = new SimpleMessageStore(); MessageGroupQueue queue = new MessageGroupQueue(messageGroupStore, "FOO", 2); queue.put(new GenericMessage<String>("foo")); assertEquals(1, queue.remainingCapacity()); queue.put(new GenericMessage<String>("bar")); assertEquals(0, queue.remainingCapacity()); Message<?> result = queue.poll(100, TimeUnit.MILLISECONDS); assertNotNull(result);//from ww w . ja v a 2 s . co m assertEquals(1, queue.remainingCapacity()); }
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 ww. j av a 2s . com*/ } 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(); }