@ManagedMetric(metricType = MetricType.GAUGE) public int getActiveConsumerCount() { return this.cancellationLock.getCount(); }
@ManagedMetric(metricType = MetricType.GAUGE) public int getActiveConsumerCount() { return this.cancellationLock.getCount(); }
@Test public void testActiveCount() throws Exception { final Object object1 = new Object(); final Object object2 = new Object(); counter.add(object1); counter.add(object2); assertEquals(2, counter.getCount()); counter.release(object2); assertEquals(1, counter.getCount()); counter.release(object1); counter.release(object1); assertEquals(0, counter.getCount()); }
@Test public void testLongLivingConsumerStoppedProperlyAfterContextClose() throws Exception { ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(LongLiveConsumerConfig.class); RabbitTemplate template = createTemplate(1); template.convertAndSend(queue.getName(), "foo"); CountDownLatch consumerLatch = applicationContext.getBean("consumerLatch", CountDownLatch.class); SimpleMessageListenerContainer container = applicationContext.getBean(SimpleMessageListenerContainer.class); assertTrue(consumerLatch.await(10, TimeUnit.SECONDS)); applicationContext.close(); @SuppressWarnings("rawtypes") ActiveObjectCounter counter = TestUtils.getPropertyValue(container, "cancellationLock", ActiveObjectCounter.class); assertTrue(counter.getCount() > 0); int n = 0; while (counter.getCount() > 0 && n++ < 10) { Thread.sleep(500); } assertTrue(n < 10); ((DisposableBean) template.getConnectionFactory()).destroy(); }