Search in sources :

Example 6 with LocalQueueStats

use of com.hazelcast.collection.LocalQueueStats in project hazelcast by hazelcast.

the class QueueResetAgeStatisticsTest method testAgeStatsReset.

@Test
public void testAgeStatsReset() throws ExecutionException, InterruptedException {
    IQueue<String> myQueue = client.getQueue("my-queue");
    assertEquals(Long.MAX_VALUE, member.getQueue("my-queue").getLocalQueueStats().getMinAge());
    myQueue.add("item-1");
    myQueue.add("item-2");
    sleepAtLeastMillis(50);
    myQueue.take();
    myQueue.take();
    LocalQueueStats stats = member.getQueue("my-queue").getLocalQueueStats();
    assertTrue(stats.getMaxAge() > 0);
    assertTrue(stats.getMinAge() > 0);
    assertTrue(stats.getAverageAge() > 0);
    ClientMessage clientMessage = MCResetQueueAgeStatisticsCodec.encodeRequest("my-queue");
    ClientInvocation invocation = new ClientInvocation(client, clientMessage, "my-queue");
    invocation.invoke().get();
    LocalQueueStats statsAfterReset = member.getQueue("my-queue").getLocalQueueStats();
    assertEquals(0, statsAfterReset.getMaxAge());
    assertEquals(Long.MAX_VALUE, statsAfterReset.getMinAge());
    assertEquals(0, statsAfterReset.getAverageAge());
    myQueue.add("item-3");
    myQueue.add("item-4");
    sleepAtLeastMillis(20);
    myQueue.take();
    sleepAtLeastMillis(100);
    Thread.sleep(100);
    myQueue.take();
    LocalQueueStats populatedStatsAfterReset = member.getQueue("my-queue").getLocalQueueStats();
    assertTrue(statsAfterReset.getMinAge() + " is greater than or equal to 20", statsAfterReset.getMinAge() >= 20);
    assertTrue(statsAfterReset.getMaxAge() > 100);
    assertEquals((populatedStatsAfterReset.getMinAge() + populatedStatsAfterReset.getMaxAge()) / 2, populatedStatsAfterReset.getAverageAge());
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with LocalQueueStats

use of com.hazelcast.collection.LocalQueueStats in project hazelcast by hazelcast.

the class QueueStatisticsTest method testPollOperationCount.

@Test
public void testPollOperationCount() throws Exception {
    IQueue<VersionedObject<String>> queue = newQueue();
    for (int i = 0; i < 30; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    for (int i = 0; i < 10; i++) {
        queue.remove();
    }
    for (int i = 0; i < 10; i++) {
        queue.take();
    }
    for (int i = 0; i < 10; i++) {
        queue.poll();
    }
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertTrueEventually(() -> assertEquals(30, stats.getPollOperationCount()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with LocalQueueStats

use of com.hazelcast.collection.LocalQueueStats in project hazelcast by hazelcast.

the class QueueStatisticsTest method testRejectedOfferOperationCount.

@Test
public void testRejectedOfferOperationCount() {
    IQueue<VersionedObject<String>> queue = newQueue(30);
    for (int i = 0; i < 30; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    for (int i = 0; i < 10; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertTrueEventually(() -> assertEquals(10, stats.getRejectedOfferOperationCount()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with LocalQueueStats

use of com.hazelcast.collection.LocalQueueStats in project hazelcast by hazelcast.

the class QueueStatisticsTest method testAge.

@Test
public void testAge() throws InterruptedException {
    IQueue<VersionedObject<String>> queue = newQueue();
    queue.offer(new VersionedObject<>("maxAgeItem", 0));
    queue.offer(new VersionedObject<>("minAgeItem", 1));
    sleepAtLeastMillis(100);
    queue.poll();
    queue.poll();
    QueueService queueService = getNode(instance).nodeEngine.getService(QueueService.SERVICE_NAME);
    LocalQueueStats stats = queueService.getStats().get(queue.getName());
    long maxAge = stats.getMaxAge();
    long minAge = stats.getMinAge();
    long expectedAverageAge = (maxAge + minAge) / 2;
    long avgAge = stats.getAverageAge();
    assertEquals(expectedAverageAge, avgAge);
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with LocalQueueStats

use of com.hazelcast.collection.LocalQueueStats in project hazelcast by hazelcast.

the class QueueStatisticsTest method testEmptyPollOperationCount.

@Test
public void testEmptyPollOperationCount() {
    IQueue<VersionedObject<String>> queue = newQueue();
    for (int i = 0; i < 10; i++) {
        queue.poll();
    }
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertTrueEventually(() -> assertEquals(10, stats.getEmptyPollOperationCount()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

LocalQueueStats (com.hazelcast.collection.LocalQueueStats)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 VersionedObject (com.hazelcast.collection.impl.queue.model.VersionedObject)8 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)1 ArrayList (java.util.ArrayList)1