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());
}
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()));
}
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()));
}
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);
}
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()));
}
Aggregations