Search in sources :

Example 16 with Statistics

use of org.apache.geode.Statistics in project geode by apache.

the class AtomicStatsJUnitTest method testConcurrentGets.

/**
   * Test for bug 41340. Do two gets at the same time of a dirty stat, and make sure we get the
   * correct value for the stat.
   * 
   * @throws Throwable
   */
@Test
public void testConcurrentGets() throws Throwable {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    // props.setProperty("statistic-sample-rate", "60000");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "false");
    DistributedSystem ds = DistributedSystem.connect(props);
    String statName = "TestStats";
    String statDescription = "Tests stats";
    final String statDesc = "blah blah blah";
    StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
    StatisticsType type = f.createType(statName, statDescription, new StatisticDescriptor[] { f.createIntGauge("stat", statDesc, "bottles of beer on the wall") });
    final int statId = type.nameToId("stat");
    try {
        final AtomicReference<Statistics> statsRef = new AtomicReference<Statistics>();
        final CyclicBarrier beforeIncrement = new CyclicBarrier(3);
        final CyclicBarrier afterIncrement = new CyclicBarrier(3);
        Thread thread1 = new Thread("thread1") {

            public void run() {
                try {
                    while (true) {
                        beforeIncrement.await();
                        statsRef.get().incInt(statId, 1);
                        afterIncrement.await();
                    }
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };
        Thread thread3 = new Thread("thread1") {

            public void run() {
                try {
                    while (true) {
                        beforeIncrement.await();
                        afterIncrement.await();
                        statsRef.get().getInt(statId);
                    }
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };
        thread1.start();
        thread3.start();
        for (int i = 0; i < 5000; i++) {
            Statistics stats = ds.createAtomicStatistics(type, "stats");
            statsRef.set(stats);
            beforeIncrement.await();
            afterIncrement.await();
            assertEquals("On loop " + i, 1, stats.getInt(statId));
            stats.close();
        }
    } finally {
        ds.disconnect();
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) StatisticsType(org.apache.geode.StatisticsType) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Statistics(org.apache.geode.Statistics) CyclicBarrier(java.util.concurrent.CyclicBarrier) StatisticsTypeFactory(org.apache.geode.StatisticsTypeFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with Statistics

use of org.apache.geode.Statistics in project geode by apache.

the class DistributedSystemStatisticsIntegrationTest method setUpLongStatistics.

private Statistics setUpLongStatistics(final int count) {
    String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
    StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
    for (int i = 0; i < count; i++) {
        descriptors[i] = factory().createLongGauge(this.statNames[i], descriptions[i], "x");
    }
    StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
    Statistics stats = factory().createStatistics(type, "Display");
    for (int i = 0; i < count; i++) {
        stats.setLong(this.statNames[i], 0L);
    }
    return stats;
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 18 with Statistics

use of org.apache.geode.Statistics in project geode by apache.

the class DistributedSystemStatisticsIntegrationTest method testAccessingDoubleStat.

/**
   * Tests that accessing an {@code double} stat throws the appropriate exceptions.
   */
@Test
public void testAccessingDoubleStat() {
    Statistics stats = setUpDoubleStatistics(1);
    assertThat(stats.getDouble(this.statName1)).isEqualTo(0.0);
    assertThatThrownBy(() -> stats.getInt(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.getLong(this.statName1)).isExactlyInstanceOf(IllegalArgumentException.class);
    stats.setDouble(this.statName1, 4.0);
    assertThatThrownBy(() -> stats.setInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.setLong(this.statName1, 4L)).isExactlyInstanceOf(IllegalArgumentException.class);
    stats.incDouble(this.statName1, 4.0);
    assertThatThrownBy(() -> stats.incInt(this.statName1, 4)).isExactlyInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> stats.incLong(this.statName1, 4L)).isExactlyInstanceOf(IllegalArgumentException.class);
}
Also used : Statistics(org.apache.geode.Statistics) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 19 with Statistics

use of org.apache.geode.Statistics in project geode by apache.

the class DistributedSystemStatisticsIntegrationTest method setUpIntStatistics.

private Statistics setUpIntStatistics(final int count) {
    String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
    StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
    for (int i = 0; i < count; i++) {
        descriptors[i] = factory().createIntGauge(this.statNames[i], descriptions[i], "x");
    }
    StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
    Statistics stats = factory().createStatistics(type, "Display");
    for (int i = 0; i < count; i++) {
        stats.setInt(this.statNames[i], 0);
    }
    return stats;
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 20 with Statistics

use of org.apache.geode.Statistics in project geode by apache.

the class ClientMembershipDUnitTest method getAcceptsInProgress.

protected int getAcceptsInProgress() {
    StatisticsType st = InternalDistributedSystem.getAnyInstance().findType("CacheServerStats");
    Statistics[] s = InternalDistributedSystem.getAnyInstance().findStatisticsByType(st);
    return s[0].getInt("acceptsInProgress");
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics)

Aggregations

Statistics (org.apache.geode.Statistics)74 StatisticsType (org.apache.geode.StatisticsType)36 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)29 StatisticDescriptor (org.apache.geode.StatisticDescriptor)18 File (java.io.File)17 ArrayList (java.util.ArrayList)12 List (java.util.List)12 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)11 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)10 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)6 LRUStatistics (org.apache.geode.internal.cache.lru.LRUStatistics)6 HashMap (java.util.HashMap)5 LinuxProcFsStatistics (org.apache.geode.internal.statistics.platform.LinuxProcFsStatistics)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 MainWithChildrenRollingFileHandler (org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)3 Before (org.junit.Before)3 IOException (java.io.IOException)2