Search in sources :

Example 31 with StopWatch

use of org.apache.geode.internal.util.StopWatch in project geode by apache.

the class LoggingPerformanceTestCase method performCountBasedIsEnabledTest.

protected long performCountBasedIsEnabledTest(final PerformanceLogger perfLogger) {
    System.out.println("\nBeginning " + getUniqueName());
    final StopWatch stopWatch = new StopWatch(true);
    for (int sets = 0; sets < LOG_SETS; sets++) {
        for (int count = 0; count < LOG_REPETITIONS_PER_SET; count++) {
            perfLogger.isEnabled();
        }
    }
    stopWatch.stop();
    final long millis = stopWatch.elapsedTimeMillis();
    final long seconds = millis / 1000;
    final long minutes = seconds / 60;
    System.out.println(getUniqueName() + " performCountBasedIsEnabledTest");
    System.out.println("Number of isEnabled statements: " + LOG_SETS * LOG_REPETITIONS_PER_SET);
    System.out.println("Total elapsed time in millis: " + millis);
    System.out.println("Total elapsed time in seconds: " + seconds);
    System.out.println("Total elapsed time in minutes: " + minutes);
    return millis;
}
Also used : StopWatch(org.apache.geode.internal.util.StopWatch)

Example 32 with StopWatch

use of org.apache.geode.internal.util.StopWatch in project geode by apache.

the class LoggingPerformanceTestCase method performCountBasedLoggingTest.

protected long performCountBasedLoggingTest(final PerformanceLogger perfLogger) {
    System.out.println("\nBeginning " + getUniqueName());
    final StopWatch stopWatch = new StopWatch(true);
    for (int sets = 0; sets < LOG_SETS; sets++) {
        for (int count = 0; count < LOG_REPETITIONS_PER_SET; count++) {
            perfLogger.log(message);
        // fail("KIRK");
        }
    }
    stopWatch.stop();
    final long millis = stopWatch.elapsedTimeMillis();
    final long seconds = millis / 1000;
    final long minutes = seconds / 60;
    System.out.println(getUniqueName() + " performCountBasedLoggingTest");
    System.out.println("Number of log statements: " + LOG_SETS * LOG_REPETITIONS_PER_SET);
    System.out.println("Total elapsed time in millis: " + millis);
    System.out.println("Total elapsed time in seconds: " + seconds);
    System.out.println("Total elapsed time in minutes: " + minutes);
    return millis;
}
Also used : StopWatch(org.apache.geode.internal.util.StopWatch)

Example 33 with StopWatch

use of org.apache.geode.internal.util.StopWatch in project geode by apache.

the class TXJUnitTest method waitForKeys.

private static void waitForKeys(final Index idx, final int expectedKeys) {
    // DistributedTestCase.WaitCriterion wc = new DistributedTestCase.WaitCriterion() {
    // String excuse;
    // public boolean done() {
    // return idx.getStatistics().getNumberOfKeys() == expectedKeys;
    // }
    //
    // public String description() {
    // return "expectedKeys " + expectedKeys + " but got this "
    // + idx.getStatistics().getNumberOfKeys();
    // }
    // };
    // DistributedTestCase.waitForCriterion(wc, 15 * 1000, 20, true);
    boolean done = false;
    try {
        for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 15 * 1000; done = (idx.getStatistics().getNumberOfKeys() == expectedKeys)) {
            Thread.sleep(20);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    assertTrue("expectedKeys " + expectedKeys + " but got this " + idx.getStatistics().getNumberOfKeys(), done);
}
Also used : StopWatch(org.apache.geode.internal.util.StopWatch)

Example 34 with StopWatch

use of org.apache.geode.internal.util.StopWatch in project geode by apache.

the class AbstractLauncherIntegrationTestCase method assertEventuallyFalse.

protected static void assertEventuallyFalse(final String message, final Callable<Boolean> callable, final int timeout, final int interval) throws Exception {
    boolean done = false;
    for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < timeout; done = (!callable.call())) {
        Thread.sleep(interval);
    }
    assertTrue(message, done);
}
Also used : StopWatch(org.apache.geode.internal.util.StopWatch)

Example 35 with StopWatch

use of org.apache.geode.internal.util.StopWatch in project geode by apache.

the class ProxyJUnitTest method testExpiration.

/**
   * Make sure a proxy region expiration behaves as expected
   */
@Test
public void testExpiration() throws Exception {
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {
        // now make sure they don't on proxy
        {
            AttributesFactory af = new AttributesFactory();
            af.setStatisticsEnabled(true);
            af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.LOCAL_INVALIDATE));
            af.setEntryTimeToLive(new ExpirationAttributes(2, ExpirationAction.LOCAL_DESTROY));
            af.setDataPolicy(DataPolicy.EMPTY);
            try {
                af.create();
                fail("expected IllegalStateException");
            } catch (IllegalStateException expected) {
            }
        }
        // make sure regionIdleTimeout works on proxy
        {
            CacheListener cl1 = new CacheListenerAdapter() {

                public void afterRegionDestroy(RegionEvent e) {
                    clInvokeCount++;
                }

                public void afterRegionInvalidate(RegionEvent e) {
                    clInvokeCount++;
                }
            };
            AttributesFactory af = new AttributesFactory();
            af.setStatisticsEnabled(true);
            final int EXPIRE_MS = 500;
            af.setRegionIdleTimeout(new ExpirationAttributes(EXPIRE_MS, ExpirationAction.LOCAL_DESTROY));
            af.addCacheListener(cl1);
            af.setDataPolicy(DataPolicy.EMPTY);
            clearCallbackState();
            Region r = this.c.createRegion("rEMPTY", af.create());
            assertTrue(clInvokeCount == 0);
            r.put("key", "value");
            long endTime = System.currentTimeMillis() + (EXPIRE_MS * 2);
            do {
                r.get("key");
            } while (System.currentTimeMillis() < endTime);
            assertEquals(0, this.clInvokeCount);
            Thread.sleep(EXPIRE_MS * 2);
            boolean done = false;
            try {
                for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 1000; done = (ProxyJUnitTest.this.clInvokeCount == 1)) {
                    Thread.sleep(200);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            assertTrue("waiting for invocation", done);
        }
        // make sure regionTimeToLive works on proxy
        {
            CacheListener cl1 = new CacheListenerAdapter() {

                public void afterRegionDestroy(RegionEvent e) {
                    clInvokeCount++;
                }

                public void afterRegionInvalidate(RegionEvent e) {
                    clInvokeCount++;
                }
            };
            AttributesFactory af = new AttributesFactory();
            af.setStatisticsEnabled(true);
            final int EXPIRE_MS = 500;
            af.setRegionTimeToLive(new ExpirationAttributes(EXPIRE_MS, ExpirationAction.LOCAL_DESTROY));
            af.addCacheListener(cl1);
            af.setDataPolicy(DataPolicy.EMPTY);
            clearCallbackState();
            Region r = this.c.createRegion("rEMPTY", af.create());
            assertTrue(clInvokeCount == 0);
            r.put("key", "value");
            long endTime = System.currentTimeMillis() + (EXPIRE_MS * 2);
            do {
                r.put("key", "value");
            } while (System.currentTimeMillis() < endTime);
            assertEquals(0, this.clInvokeCount);
            Thread.sleep(EXPIRE_MS * 2);
            boolean done = false;
            try {
                for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 1000; done = (ProxyJUnitTest.this.clInvokeCount == 1)) {
                    Thread.sleep(200);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            assertTrue("waiting for invocation", done);
        }
    } finally {
        System.clearProperty(LocalRegion.EXPIRY_MS_PROPERTY);
        assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
    }
}
Also used : CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) StopWatch(org.apache.geode.internal.util.StopWatch) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StopWatch (org.apache.geode.internal.util.StopWatch)37 Test (org.junit.Test)13 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Statistics (org.apache.geode.Statistics)2 Region (org.apache.geode.cache.Region)2 FailureTracker (org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 MemberMXBean (org.apache.geode.management.MemberMXBean)2 CliMetaData (org.apache.geode.management.cli.CliMetaData)2 MXBeanProvider.getMemberMXBean (org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2