Search in sources :

Example 16 with StatisticsType

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

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

Example 18 with StatisticsType

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

the class StatAlertsManager method createMemberStatAlertDefinition.

/**
   * Convert {@link StatAlertDefinition }(Created by client like GFMon2.0) with
   * {@link DummyStatisticInfoImpl} to StatAlertDefinition with {@link StatisticInfoImpl}
   */
private StatAlertDefinition[] createMemberStatAlertDefinition(DistributionManager dm, StatAlertDefinition[] defns) {
    dm.getCancelCriterion().checkCancelInProgress(null);
    Statistics[] statistics;
    StatisticsType type;
    StatisticDescriptor desc;
    String textId;
    boolean skipDefinition = false;
    List result = new ArrayList();
    for (int i = 0; i < defns.length; i++) {
        skipDefinition = false;
        StatAlertDefinition defn = defns[i];
        StatisticInfo[] statInfos = defn.getStatisticInfo();
        for (int ii = 0; ii < statInfos.length && !skipDefinition; ii++) {
            textId = statInfos[ii].getStatisticsTextId();
            // TODO If none by TextID, use StatType and getAll.
            statistics = dm.getSystem().findStatisticsByTextId(textId);
            if (statistics.length == 0) {
                logger.error(LocalizedMessage.create(LocalizedStrings.StatAlertsManager_STATALERTSMANAGER_CREATEMEMBERSTATALERTDEFINITION_STATISTICS_WITH_GIVEN_TEXTID_0_NOT_FOUND, textId));
                skipDefinition = true;
                // To print all errors
                continue;
            }
            type = statistics[0].getType();
            desc = type.nameToDescriptor(statInfos[ii].getStatisticName());
            // Replace the actual StatInfo object
            statInfos[ii] = new StatisticInfoImpl(statistics[0], desc);
            if (logger.isDebugEnabled()) {
                logger.debug("StatAlertsManager.createMemberStatAlertDefinition: created statInfo {}", statInfos[ii]);
            }
        }
        if (!skipDefinition) {
            defn.setStatisticInfo(statInfos);
            result.add(defn);
            if (logger.isDebugEnabled()) {
                logger.debug("StatAlertsManager.createMemberStatAlertDefinition :: {}", defns[i].getStringRepresentation());
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("StatAlertsManager.createMemberStatAlertDefinition :: StatAlertDefinition {} is excluded", defn.getName());
            }
        }
    }
    return (StatAlertDefinition[]) result.toArray(new StatAlertDefinition[result.size()]);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) ArrayList(java.util.ArrayList) StatisticInfo(org.apache.geode.internal.admin.statalerts.StatisticInfo) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) StatisticInfoImpl(org.apache.geode.internal.admin.statalerts.StatisticInfoImpl) DummyStatisticInfoImpl(org.apache.geode.internal.admin.statalerts.DummyStatisticInfoImpl)

Example 19 with StatisticsType

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

the class GemFireStatSamplerIntegrationTest method testSampleRate.

/**
   * Tests the statistics sample rate within an acceptable margin of error.
   */
@Test
public void testSampleRate() throws Exception {
    connect(createGemFireProperties());
    GemFireStatSampler statSampler = getGemFireStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    assertEquals(STAT_SAMPLE_RATE, statSampler.getSampleRate());
    assertTrue(getStatisticsManager().getStatListModCount() > 0);
    List<Statistics> statistics = getStatisticsManager().getStatsList();
    assertNotNull(statistics);
    assertTrue(statistics.size() > 0);
    StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
    Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
    assertEquals(1, statsArray.length);
    final Statistics statSamplerStats = statsArray[0];
    final int initialSampleCount = statSamplerStats.getInt("sampleCount");
    final int expectedSampleCount = initialSampleCount + 2;
    waitForExpectedStatValue(statSamplerStats, "sampleCount", expectedSampleCount, 5000, 10);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with StatisticsType

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

the class GemFireStatSamplerIntegrationTest method testStop.

/**
   * Invokes stop() and then validates that the sampler did in fact stop.
   */
@Test
public void testStop() throws Exception {
    connect(createGemFireProperties());
    GemFireStatSampler statSampler = getGemFireStatSampler();
    assertTrue(statSampler.waitForInitialization(5000));
    // validate the stat sampler is running
    StatisticsType statSamplerType = getStatisticsManager().findType("StatSampler");
    Statistics[] statsArray = getStatisticsManager().findStatisticsByType(statSamplerType);
    assertEquals(1, statsArray.length);
    final Statistics statSamplerStats = statsArray[0];
    final int initialSampleCount = statSamplerStats.getInt("sampleCount");
    final int expectedSampleCount = initialSampleCount + 2;
    waitForStatSample(statSamplerStats, expectedSampleCount, 20000, 10);
    // stop the stat sampler
    statSampler.stop();
    // validate the stat sampler has stopped
    final int stoppedSampleCount = statSamplerStats.getInt("sampleCount");
    // the following should timeout rather than complete
    assertStatValueDoesNotChange(statSamplerStats, "sampleCount", stoppedSampleCount, 5000, 10);
    assertEquals(stoppedSampleCount, statSamplerStats.getInt("sampleCount"));
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) 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