Search in sources :

Example 21 with Statistics

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

Example 22 with Statistics

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

the class PartitionedRegionStatsJUnitTest method validateOverflowStats.

private void validateOverflowStats(PartitionedRegion pr) throws Exception {
    Statistics stats = pr.getPrStats().getStats();
    DiskRegionStats diskStats = pr.getDiskRegionStats();
    assertEquals(0, stats.getLong("dataStoreBytesInUse"));
    assertEquals(0, stats.getInt("dataStoreEntryCount"));
    assertEquals(0, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(0, diskStats.getNumEntriesInVM());
    assertEquals(0, diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    int numEntries = 0;
    pr.put(0, 0);
    numEntries++;
    pr.getDiskStore().flush();
    long singleEntryMemSize = stats.getLong("dataStoreBytesInUse");
    assertEquals(1, stats.getInt("dataStoreEntryCount"));
    assertEquals(0, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals(0, diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    pr.put(1, 1);
    numEntries++;
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(2, stats.getInt("dataStoreEntryCount"));
    long entryOverflowSize = diskStats.getNumOverflowBytesOnDisk();
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals(1, diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    assertTrue(entryOverflowSize > 0);
    for (; numEntries < pr.getTotalNumberOfBuckets() * 5; numEntries++) {
        pr.put(numEntries, numEntries);
    }
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - 1) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - 1), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Update some entries
    for (int i = 0; i < numEntries / 2; i++) {
        pr.put(i, i * 2);
    }
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - 1) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - 1), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Get some entries to trigger evictions
    for (int i = 0; i < numEntries / 2; i++) {
        pr.get(i);
    }
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - 1) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - 1), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Remove some entries
    for (; numEntries > 100; numEntries--) {
        pr.remove(numEntries);
    }
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - 1) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - 1), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Update the same entry twice
    pr.put(5, 5);
    pr.put(5, 6);
    pr.getDiskStore().flush();
    assertEquals(singleEntryMemSize, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - 1) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(1, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - 1), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Put get put - seems to leave entry in memory?
    pr.put(10, 11);
    pr.get(10);
    pr.put(10, 12);
    pr.getDiskStore().flush();
    int entriesInMem = 1;
    assertEquals(singleEntryMemSize * entriesInMem, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - entriesInMem) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(entriesInMem, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - entriesInMem), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
    // Do some random operations
    System.out.println("----Doing random operations");
    Random rand = new Random(12345L);
    for (int i = 0; i < 1000; i++) {
        int key = rand.nextInt(numEntries);
        int op = rand.nextInt(3);
        switch(op) {
            case 0:
                pr.put(key, rand.nextInt());
                break;
            case 1:
                pr.get(key);
                break;
            case 2:
                pr.remove(key);
                break;
        }
    }
    pr.getDiskStore().flush();
    System.out.println("----Done with random operations");
    numEntries = pr.entryCount();
    assertEquals(singleEntryMemSize * entriesInMem, stats.getLong("dataStoreBytesInUse"));
    assertEquals(numEntries, stats.getInt("dataStoreEntryCount"));
    assertEquals((numEntries - entriesInMem) * entryOverflowSize, diskStats.getNumOverflowBytesOnDisk());
    assertEquals(entriesInMem, diskStats.getNumEntriesInVM());
    assertEquals((numEntries - entriesInMem), diskStats.getNumOverflowOnDisk());
    assertEquals(stats.getLong("dataStoreBytesInUse"), getMemBytes(pr));
    assertEquals(diskStats.getNumOverflowBytesOnDisk(), getDiskBytes(pr));
}
Also used : Random(java.util.Random) Statistics(org.apache.geode.Statistics)

Example 23 with Statistics

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

the class Fakes method cache.

/**
   * A fake cache, which contains a fake distributed system, distribution manager, etc.
   */
public static GemFireCacheImpl cache() {
    GemFireCacheImpl cache = mock(GemFireCacheImpl.class);
    InternalDistributedSystem system = mock(InternalDistributedSystem.class);
    DistributionConfig config = mock(DistributionConfig.class);
    DistributionManager distributionManager = mock(DistributionManager.class);
    CancelCriterion systemCancelCriterion = mock(CancelCriterion.class);
    DSClock clock = mock(DSClock.class);
    LogWriter logger = mock(LogWriter.class);
    Statistics stats = mock(Statistics.class);
    InternalDistributedMember member;
    member = new InternalDistributedMember("localhost", 5555);
    when(config.getCacheXmlFile()).thenReturn(new File(""));
    when(config.getDeployWorkingDir()).thenReturn(new File("."));
    when(cache.getDistributedSystem()).thenReturn(system);
    when(cache.getInternalDistributedSystem()).thenReturn(system);
    when(cache.getSystem()).thenReturn(system);
    when(cache.getMyId()).thenReturn(member);
    when(cache.getDistributionManager()).thenReturn(distributionManager);
    when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion);
    when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class));
    when(system.getDistributedMember()).thenReturn(member);
    when(system.getConfig()).thenReturn(config);
    when(system.getDistributionManager()).thenReturn(distributionManager);
    when(system.getCancelCriterion()).thenReturn(systemCancelCriterion);
    when(system.getClock()).thenReturn(clock);
    when(system.getLogWriter()).thenReturn(logger);
    when(system.createAtomicStatistics(any(), any(), anyLong())).thenReturn(stats);
    when(system.createAtomicStatistics(any(), any())).thenReturn(stats);
    when(distributionManager.getId()).thenReturn(member);
    when(distributionManager.getDistributionManagerId()).thenReturn(member);
    when(distributionManager.getConfig()).thenReturn(config);
    when(distributionManager.getSystem()).thenReturn(system);
    when(distributionManager.getCancelCriterion()).thenReturn(systemCancelCriterion);
    return cache;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DSClock(org.apache.geode.distributed.internal.DSClock) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) LogWriter(org.apache.geode.LogWriter) CancelCriterion(org.apache.geode.CancelCriterion) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Statistics(org.apache.geode.Statistics) File(java.io.File)

Example 24 with Statistics

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

the class CacheServerMaxConnectionsJUnitTest method testMaxCnxLimit.

/**
   * 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 testMaxCnxLimit() throws Exception {
    PORT = createServer();
    createProxyAndRegionForClient();
    StatisticsType st = this.system.findType("CacheServerStats");
    final Statistics s = this.system.findStatisticsByType(st)[0];
    assertEquals(0, s.getInt("currentClients"));
    assertEquals(0, s.getInt("currentClientConnections"));
    Connection[] cnxs = new Connection[MAX_CNXS];
    for (int i = 0; i < MAX_CNXS; i++) {
        cnxs[i] = proxy.acquireConnection();
        this.system.getLogWriter().info("acquired connection[" + i + "]=" + cnxs[i]);
    }
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClientConnections") == MAX_CNXS;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 1000, 200, true);
    assertEquals(MAX_CNXS, s.getInt("currentClientConnections"));
    assertEquals(1, s.getInt("currentClients"));
    this.system.getLogWriter().info("<ExpectedException action=add>" + "exceeded max-connections" + "</ExpectedException>");
    try {
        Connection cnx = proxy.acquireConnection();
        if (cnx != null) {
            fail("should not have been able to connect more than " + MAX_CNXS + " times but was able to connect " + s.getInt("currentClientConnections") + " times. Last connection=" + cnx);
        }
        this.system.getLogWriter().info("acquire connection returned null which is ok");
    } catch (NoAvailableServersException expected) {
        // This is expected but due to race conditions in server handshake
        // we may get null back from acquireConnection instead.
        this.system.getLogWriter().info("received expected " + expected.getMessage());
    } catch (Exception ex) {
        fail("expected acquireConnection to throw NoAvailableServersException but instead it threw " + ex);
    } finally {
        this.system.getLogWriter().info("<ExpectedException action=remove>" + "exceeded max-connections" + "</ExpectedException>");
    }
    // now lets see what happens we we close our connections
    for (int i = 0; i < MAX_CNXS; i++) {
        cnxs[i].close(false);
    }
    ev = new WaitCriterion() {

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

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 3 * 1000, 200, true);
    this.system.getLogWriter().info("currentClients=" + s.getInt("currentClients") + " currentClientConnections=" + s.getInt("currentClientConnections"));
    assertEquals(0, s.getInt("currentClientConnections"));
    assertEquals(0, s.getInt("currentClients"));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) StatisticsType(org.apache.geode.StatisticsType) Connection(org.apache.geode.cache.client.internal.Connection) Statistics(org.apache.geode.Statistics) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) IOException(java.io.IOException) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with Statistics

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

the class StatisticInfoImpl method create.

public static StatisticInfoImpl create(String toString, StatisticsFactory f) {
    int startBrack = toString.indexOf("[");
    int endBrack = toString.indexOf("]");
    if (startBrack == -1 || endBrack == -1)
        return null;
    String name = toString.substring(0, startBrack).trim();
    String ids = toString.substring(startBrack + 1, endBrack).trim();
    StatisticsType type = f.findType(name);
    if (type == null)
        return null;
    Statistics[] stats = f.findStatisticsByType(type);
    if (stats.length == 0)
        return null;
    StatisticDescriptor[] descs = type.getStatistics();
    for (int i = 0; i < descs.length; i++) {
        if (descs[i].getName().equalsIgnoreCase(ids))
            return new StatisticInfoImpl(stats[0], descs[i]);
    }
    return null;
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

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