Search in sources :

Example 1 with LocalTopicStatsImpl

use of com.hazelcast.monitor.impl.LocalTopicStatsImpl in project hazelcast by hazelcast.

the class TopicTest method testTopicStats.

@Test
public void testTopicStats() throws InterruptedException {
    String topicName = "testTopicStats" + generateRandomString(5);
    HazelcastInstance instance = createHazelcastInstance();
    ITopic<String> topic = instance.getTopic(topicName);
    final CountDownLatch latch1 = new CountDownLatch(1000);
    topic.addMessageListener(new MessageListener<String>() {

        public void onMessage(Message msg) {
            latch1.countDown();
        }
    });
    final CountDownLatch latch2 = new CountDownLatch(1000);
    topic.addMessageListener(new MessageListener<String>() {

        public void onMessage(Message msg) {
            latch2.countDown();
        }
    });
    for (int i = 0; i < 1000; i++) {
        topic.publish("sancar");
    }
    assertTrue(latch1.await(1, TimeUnit.MINUTES));
    assertTrue(latch2.await(1, TimeUnit.MINUTES));
    LocalTopicStatsImpl stats = (LocalTopicStatsImpl) topic.getLocalTopicStats();
    assertEquals(1000, stats.getPublishOperationCount());
    assertEquals(2000, stats.getReceiveOperationCount());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Message(com.hazelcast.core.Message) LocalTopicStatsImpl(com.hazelcast.monitor.impl.LocalTopicStatsImpl) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Message (com.hazelcast.core.Message)1 LocalTopicStatsImpl (com.hazelcast.monitor.impl.LocalTopicStatsImpl)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1