[infinispan-commits] Infinispan SVN: r996 - trunk/core/src/test/java/org/infinispan/profiling.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Fri Oct 23 12:43:24 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-10-23 12:43:24 -0400 (Fri, 23 Oct 2009)
New Revision: 996
Modified:
trunk/core/src/test/java/org/infinispan/profiling/AbstractProfileTest.java
trunk/core/src/test/java/org/infinispan/profiling/ProfileTest.java
trunk/core/src/test/java/org/infinispan/profiling/ProfileTestSlave.java
Log:
Enhanced tests, also allow to be run on the cmd line
Modified: trunk/core/src/test/java/org/infinispan/profiling/AbstractProfileTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/profiling/AbstractProfileTest.java 2009-10-23 16:42:35 UTC (rev 995)
+++ trunk/core/src/test/java/org/infinispan/profiling/AbstractProfileTest.java 2009-10-23 16:43:24 UTC (rev 996)
@@ -1,27 +1,76 @@
package org.infinispan.profiling;
import org.infinispan.config.Configuration;
+import static org.infinispan.config.Configuration.CacheMode.*;
import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.executors.ExecutorFactory;
import org.infinispan.manager.CacheManager;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.util.concurrent.WithinThreadExecutor;
import org.testng.annotations.Test;
- at Test(groups = "profiling", enabled = false, testName = "profiling.SingleCacheManagerTest")
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+
+ at Test(groups = "profiling", enabled = false, testName = "profiling.AbstractProfileTest")
public abstract class AbstractProfileTest extends SingleCacheManagerTest {
protected static final String LOCAL_CACHE_NAME = "local";
protected static final String REPL_SYNC_CACHE_NAME = "repl_sync";
+ protected static final String REPL_ASYNC_CACHE_NAME = "repl_async";
+ protected static final String DIST_SYNC_L1_CACHE_NAME = "dist_sync_l1";
+ protected static final String DIST_ASYNC_L1_CACHE_NAME = "dist_async_l1";
+ protected static final String DIST_SYNC_CACHE_NAME = "dist_sync";
+ protected static final String DIST_ASYNC_CACHE_NAME = "dist_async";
+ boolean startedInCmdLine = false;
+ String clusterNameOverride = null;
+
+ protected void initTest() throws Exception {
+ System.out.println("Setting up test params!");
+ if (startedInCmdLine) cacheManager = createCacheManager();
+ }
+
+ private Configuration getBaseCfg() {
+ Configuration cfg = new Configuration();
+ cfg.setConcurrencyLevel(5000);
+ return cfg;
+ }
+
+ private Configuration getClusteredCfg(Configuration.CacheMode mode, boolean l1) {
+ Configuration cfg = getBaseCfg();
+ cfg.setLockAcquisitionTimeout(60000);
+ cfg.setSyncReplTimeout(60000);
+ cfg.setCacheMode(mode);
+ cfg.setFetchInMemoryState(false);
+ if (mode.isDistributed()) {
+ cfg.setL1CacheEnabled(l1);
+ cfg.setL1Lifespan(120000);
+ }
+ return cfg;
+ }
+
protected CacheManager createCacheManager() throws Exception {
- Configuration cfg = new Configuration();
- cfg.setConcurrencyLevel(2000);
- cacheManager = new DefaultCacheManager(GlobalConfiguration.getClusteredDefault());
- cacheManager.defineConfiguration(LOCAL_CACHE_NAME, cfg);
- Configuration replCfg = cfg.clone();
- replCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
- replCfg.setFetchInMemoryState(false);
- cacheManager.defineConfiguration(REPL_SYNC_CACHE_NAME, replCfg);
+ GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
+ gc.setAsyncTransportExecutorFactoryClass(WTE.class.getName());
+ cacheManager = new DefaultCacheManager(gc);
+
+ cacheManager.defineConfiguration(LOCAL_CACHE_NAME, getBaseCfg());
+
+ cacheManager.defineConfiguration(REPL_SYNC_CACHE_NAME, getClusteredCfg(REPL_SYNC, false));
+ cacheManager.defineConfiguration(REPL_ASYNC_CACHE_NAME, getClusteredCfg(REPL_ASYNC, false));
+ cacheManager.defineConfiguration(DIST_SYNC_CACHE_NAME, getClusteredCfg(DIST_SYNC, false));
+ cacheManager.defineConfiguration(DIST_ASYNC_CACHE_NAME, getClusteredCfg(DIST_ASYNC, false));
+ cacheManager.defineConfiguration(DIST_SYNC_L1_CACHE_NAME, getClusteredCfg(DIST_SYNC, true));
+ cacheManager.defineConfiguration(DIST_ASYNC_L1_CACHE_NAME, getClusteredCfg(DIST_ASYNC, true));
+
return cacheManager;
}
+
+ public static class WTE implements ExecutorFactory {
+ public ExecutorService getExecutor(Properties p) {
+ return new WithinThreadExecutor();
+ }
+ }
}
Modified: trunk/core/src/test/java/org/infinispan/profiling/ProfileTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/profiling/ProfileTest.java 2009-10-23 16:42:35 UTC (rev 995)
+++ trunk/core/src/test/java/org/infinispan/profiling/ProfileTest.java 2009-10-23 16:43:24 UTC (rev 996)
@@ -32,15 +32,38 @@
protected static final int MAX_OVERALL_KEYS = 2000;
protected static final int WARMUP_LOOPS = 20000;
protected static final boolean USE_SLEEP = false; // throttle generation a bit
+ protected static final boolean SKIP_WARMUP = true;
private List<Object> keys = new ArrayList<Object>(MAX_OVERALL_KEYS);
+ public static void main(String[] args) throws Exception {
+ ProfileTest pst = new ProfileTest();
+ pst.startedInCmdLine = true;
+
+ String mode = args[0];
+ try {
+ if (args.length > 1) pst.clusterNameOverride = args[1];
+ pst.testWith(mode);
+ } finally {
+ pst.destroyAfterMethod();
+ pst.destroyAfterClass();
+ }
+ }
+
+ protected void testWith(String cachename) throws Exception {
+ log.warn("Starting profile test, cache name = {0}", cachename);
+ initTest();
+ cache = cacheManager.getCache(cachename);
+ runCompleteTest(cachename);
+ }
+
+
@Test(enabled = false)
public void testLocalMode() throws Exception {
runCompleteTest(LOCAL_CACHE_NAME);
}
- @Test(enabled = false)
+ @Test(enabled = true)
public void testReplMode() throws Exception {
runCompleteTest(REPL_SYNC_CACHE_NAME);
}
@@ -72,7 +95,7 @@
while (keys.contains(key));
if (i % 10 == 0) {
- log.warn("Generated " + i + " keys");
+ log.trace("Generated " + i + " keys");
}
keys.add(key);
}
@@ -91,8 +114,12 @@
}
private void warmup() throws InterruptedException {
+ if (SKIP_WARMUP) {
+ log.info("Skipping warmup");
+ return;
+ }
long startTime = System.currentTimeMillis();
- TaskRunner exec = new TaskRunner(NUM_THREADS);
+ TaskRunner exec = new TaskRunner(NUM_THREADS, true);
log.warn("Starting warmup");
for (final Object key : keys) {
exec.execute(new Runnable() {
@@ -189,27 +216,31 @@
AtomicLong duration;
public void run() {
- Object key = Generator.getRandomElement(keys);
- long d = 0, st = 0;
- switch (mode) {
- case PUT:
- Object value = Generator.getRandomString();
- st = System.nanoTime();
- cache.put(key, value);
- d = System.nanoTime() - st;
- break;
- case GET:
- st = System.nanoTime();
- cache.get(key);
- d = System.nanoTime() - st;
- break;
- case REMOVE:
- st = System.nanoTime();
- cache.remove(key);
- d = System.nanoTime() - st;
- break;
+ try {
+ Object key = Generator.getRandomElement(keys);
+ long d = 0, st = 0;
+ switch (mode) {
+ case PUT:
+ Object value = Generator.getRandomString();
+ st = System.nanoTime();
+ cache.put(key, value);
+ d = System.nanoTime() - st;
+ break;
+ case GET:
+ st = System.nanoTime();
+ cache.get(key);
+ d = System.nanoTime() - st;
+ break;
+ case REMOVE:
+ st = System.nanoTime();
+ cache.remove(key);
+ d = System.nanoTime() - st;
+ break;
+ }
+ duration.getAndAdd(d);
+ } catch (Exception e) {
+ log.error("Caught ", e);
}
- duration.getAndAdd(d);
}
}
Modified: trunk/core/src/test/java/org/infinispan/profiling/ProfileTestSlave.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/profiling/ProfileTestSlave.java 2009-10-23 16:42:35 UTC (rev 995)
+++ trunk/core/src/test/java/org/infinispan/profiling/ProfileTestSlave.java 2009-10-23 16:43:24 UTC (rev 996)
@@ -4,10 +4,60 @@
@Test(groups = "profiling", enabled = false, testName = "profiling.ProfileTestSlave")
public class ProfileTestSlave extends AbstractProfileTest {
- @Test(enabled = true)
- public void testReplMode() throws Exception {
- cache = cacheManager.getCache(REPL_SYNC_CACHE_NAME);
- System.out.println("Waiting for test completion. Hit any key when done.");
+
+ public static void main(String[] args) throws Exception {
+ ProfileTestSlave pst = new ProfileTestSlave();
+ pst.startedInCmdLine = true;
+
+ String mode = args[0];
+ try {
+ if (args.length > 1) pst.clusterNameOverride = args[1];
+ pst.testWith(mode);
+ } finally {
+ pst.destroyAfterMethod();
+ pst.destroyAfterClass();
+ }
+ }
+
+ public void testReplSync() throws Exception {
+ testWith(REPL_SYNC_CACHE_NAME);
+ }
+
+ public void testReplAsync() throws Exception {
+ testWith(REPL_ASYNC_CACHE_NAME);
+ }
+
+ public void testDistSync() throws Exception {
+ testWith(DIST_SYNC_CACHE_NAME);
+ }
+
+ public void testDistAsync() throws Exception {
+ testWith(DIST_ASYNC_CACHE_NAME);
+ }
+
+ public void testDistSyncL1() throws Exception {
+ testWith(DIST_SYNC_L1_CACHE_NAME);
+ }
+
+ public void testDistAsyncL1() throws Exception {
+ testWith(DIST_ASYNC_L1_CACHE_NAME);
+ }
+
+ private void waitForTest() throws Exception {
+ System.out.println("Slave listening for remote connections. Hit Enter when done.");
System.in.read();
}
+
+ private void doTest() {
+ // trigger for JProfiler
+ }
+
+ protected void testWith(String cachename) throws Exception {
+ log.warn("Starting slave, cache name = {0}", cachename);
+ initTest();
+ cache = cacheManager.getCache(cachename);
+ System.out.println("Waiting for test completion. Hit any key when done.");
+ doTest();
+ waitForTest();
+ }
}
More information about the infinispan-commits
mailing list