Search in sources :

Example 11 with StatisticsType

use of org.apache.geode.StatisticsType 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 12 with StatisticsType

use of org.apache.geode.StatisticsType 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 13 with StatisticsType

use of org.apache.geode.StatisticsType 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 14 with StatisticsType

use of org.apache.geode.StatisticsType 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)

Example 15 with StatisticsType

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

the class ClientHealthMonitorJUnitTest method testDeadClientRemovalByServer.

/**
   * This test performs the following:<br>
   * 1)create server<br>
   * 2)initialize proxy object and create region for client<br>
   * 3)perform a PUT on client by acquiring Connection through proxy<br>
   * 4)stop server monitor threads in client to ensure that server treats this as dead client <br>
   * 5)wait for some time to allow server to clean up the dead client artifacts<br>
   * 6)again perform a PUT on client through same Connection and verify after the put that the
   * Connection object used was new one.
   */
@Test
public void testDeadClientRemovalByServer() throws Exception {
    PORT = createServer();
    createProxyAndRegionForClient();
    // String connection2String = null;
    StatisticsType st = this.system.findType("CacheServerStats");
    final Statistics s = this.system.findStatisticsByType(st)[0];
    assertEquals(0, s.getInt("currentClients"));
    assertEquals(0, s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("beforeAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    Connection connection1 = proxy.acquireConnection();
    this.system.getLogWriter().info("afterAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("acquired connection " + connection1);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") != 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 20 * 1000, 200, true);
    assertEquals(1, s.getInt("currentClients"));
    assertEquals(1, s.getInt("currentClientConnections"));
    // String connection1String = connection1.toString();
    ServerRegionProxy srp = new ServerRegionProxy("region1", proxy);
    srp.putOnForTestsOnly(connection1, "key-1", "value-1", new EventID(new byte[] { 1 }, 1, 1), null);
    this.system.getLogWriter().info("did put 1");
    // proxy.testfinalizeServerConnectionMonitor();
    ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") == 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, TIME_BETWEEN_PINGS * 5, 200, true);
    {
        this.system.getLogWriter().info("currentClients=" + s.getInt("currentClients") + " currentClientConnections=" + s.getInt("currentClientConnections"));
        assertEquals(0, s.getInt("currentClients"));
        assertEquals(0, s.getInt("currentClientConnections"));
    }
    addExceptions();
    // the connection should now fail since the server timed it out
    try {
        srp.putOnForTestsOnly(connection1, "key-1", "fail", new EventID(new byte[] { 1 }, 1, 2), null);
        fail("expected EOF");
    } catch (ServerConnectivityException expected) {
    }
// The rest of this test no longer works.
// connection1.finalizeConnection();
// proxy.release();
// connection1 = proxy.acquireConnection();
// connection2String = connection1.toString();
// this.system.getLogWriter().info("connection is now " + connection2String);
// if (connection1String.equals(connection2String)) {
// fail("New connection object was not obtained");
// }
// connection1.putObject("region1", "key-1", "value-2", new EventID(new byte[] {1},1,3), null);
// this.system.getLogWriter().info("did put 2");
// assertIndexDetailsEquals(1, s.getInt("currentClients"));
// assertIndexDetailsEquals(1, s.getInt("currentClientConnections"));
// // now lets see what happens when we close our connection
// // note we use a nasty close which just closes the socket instead
// // of sending a nice message to the server telling him we are going away
// ((ConnectionImpl)connection1).finalizeConnection();
// {
// int retry = (TIME_BETWEEN_PINGS*5) / 100;
// while (s.getInt("currentClients") > 0 && retry-- > 0) {
// Thread.sleep(100);
// }
// this.system.getLogWriter().info("currentClients="
// + s.getInt("currentClients")
// + " currentClientConnections="
// + s.getInt("currentClientConnections"));
// assertIndexDetailsEquals(0, s.getInt("currentClients"));
// assertIndexDetailsEquals(0, s.getInt("currentClientConnections"));
// }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) StatisticsType(org.apache.geode.StatisticsType) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) EventID(org.apache.geode.internal.cache.EventID) Statistics(org.apache.geode.Statistics) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StatisticsType (org.apache.geode.StatisticsType)36 Statistics (org.apache.geode.Statistics)34 Test (org.junit.Test)24 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 StatisticDescriptor (org.apache.geode.StatisticDescriptor)18 File (java.io.File)13 List (java.util.List)11 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)11 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)10 Iterator (java.util.Iterator)4 ArrayList (java.util.ArrayList)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 Properties (java.util.Properties)2 StatisticsFactory (org.apache.geode.StatisticsFactory)2 Connection (org.apache.geode.cache.client.internal.Connection)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 ResourceInst (org.apache.geode.internal.statistics.StatArchiveReader.ResourceInst)2 Info (org.apache.geode.internal.statistics.TestSampleHandler.Info)2 ResourceInstanceInfo (org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo)2