Search in sources :

Example 1 with MeterStats

use of org.apache.jackrabbit.oak.stats.MeterStats in project jackrabbit-oak by apache.

the class MetricStatisticsProviderTest method concurrentAccess.

@Test
public void concurrentAccess() throws Exception {
    //Queue is used to collect instances with minimal overhead in concurrent scenario
    final Queue<MeterStats> statsQueue = new ConcurrentLinkedDeque<MeterStats>();
    List<Thread> threads = Lists.newArrayList();
    int numWorker = 5;
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < numWorker; i++) {
        threads.add(new Thread(new Runnable() {

            @Override
            public void run() {
                Uninterruptibles.awaitUninterruptibly(latch);
                statsQueue.add(statsProvider.getMeter("foo", StatsOptions.DEFAULT));
            }
        }));
    }
    for (Thread t : threads) {
        t.start();
    }
    latch.countDown();
    for (Thread t : threads) {
        t.join();
    }
    //Assert that we get same reference for every call
    Set<MeterStats> statsSet = Sets.newIdentityHashSet();
    for (MeterStats m : statsQueue) {
        statsSet.add(m);
    }
    assertEquals(1, statsSet.size());
}
Also used : MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Example 2 with MeterStats

use of org.apache.jackrabbit.oak.stats.MeterStats in project jackrabbit-oak by apache.

the class MetricStatisticsProviderTest method meter.

@Test
public void meter() throws Exception {
    MeterStats meterStats = statsProvider.getMeter("test", StatsOptions.DEFAULT);
    assertNotNull(meterStats);
    assertNotNull(statsProvider.getRegistry().getMeters().containsKey("test"));
    assertTrue(((CompositeStats) meterStats).isMeter());
}
Also used : MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) Test(org.junit.Test)

Example 3 with MeterStats

use of org.apache.jackrabbit.oak.stats.MeterStats in project jackrabbit-oak by apache.

the class MetricStatisticsProviderTest method timeSeriesIntegration.

@Test
public void timeSeriesIntegration() throws Exception {
    MeterStats meterStats = statsProvider.getMeter(Type.SESSION_COUNT.name(), StatsOptions.DEFAULT);
    meterStats.mark(5);
    assertEquals(5, statsProvider.getRepoStats().getCounter(Type.SESSION_COUNT).get());
}
Also used : MeterStats(org.apache.jackrabbit.oak.stats.MeterStats) Test(org.junit.Test)

Aggregations

MeterStats (org.apache.jackrabbit.oak.stats.MeterStats)3 Test (org.junit.Test)3 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)1 CountDownLatch (java.util.concurrent.CountDownLatch)1