[jbosscache-commits] JBoss Cache SVN: r4829 - in core/trunk/src/test/java/org/jboss/cache: profiling and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Dec 11 12:13:57 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-11 12:13:57 -0500 (Tue, 11 Dec 2007)
New Revision: 4829

Added:
   core/trunk/src/test/java/org/jboss/cache/profiling/
   core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java
   core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Added tests to run a profiler on

Added: core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/AbstractProfileTest.java	2007-12-11 17:13:57 UTC (rev 4829)
@@ -0,0 +1,50 @@
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at Test(groups = "profiling")
+public abstract class AbstractProfileTest
+{
+   protected Cache cache;
+
+   @BeforeTest
+   public void setUp()
+   {
+      Configuration cfg = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
+      cache = DefaultCacheFactory.getInstance().createCache(cfg, false);
+   }
+
+   @AfterTest
+   public void tearDown()
+   {
+      cache.stop();
+   }
+
+   public abstract void testReplSync() throws Exception;
+
+   public abstract void testReplAsync() throws Exception;
+
+   public abstract void testReplSyncOptimistic() throws Exception;
+
+   public abstract void testReplAsyncOptimistic() throws Exception;
+
+   public abstract void testReplSyncBR() throws Exception;
+
+   public abstract void testReplAsyncBR() throws Exception;
+
+   public abstract void testReplSyncOptBR() throws Exception;
+
+   public abstract void testReplAsyncOptBR() throws Exception;
+}

Added: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileSlaveTest.java	2007-12-11 17:13:57 UTC (rev 4829)
@@ -0,0 +1,86 @@
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.Test;
+
+/**
+ * Slave to go with ProfileTest.  Should be done in a different VM.  Can be profiled as well to profile receiving
+ * messages.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at Test(groups = "profiling")
+public class ProfileSlaveTest extends AbstractProfileTest
+{
+
+   private void waitForTest() throws Exception
+   {
+      System.out.println("Slave listening for remote connections.  Hit Enter when done.");
+      System.in.read();
+   }
+
+   public void testReplSync() throws Exception
+   {
+      cache.start();
+      waitForTest();
+   }
+
+   public void testReplAsync() throws Exception
+   {
+      cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      cache.start();
+      waitForTest();
+   }
+
+   public void testReplSyncOptimistic() throws Exception
+   {
+      cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      cache.start();
+      waitForTest();
+   }
+
+   public void testReplAsyncOptimistic() throws Exception
+   {
+      cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      cache.start();
+      waitForTest();
+   }
+
+   public void testReplSyncBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplSync();
+   }
+
+   public void testReplAsyncBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplAsync();
+   }
+
+   public void testReplSyncOptBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplSyncOptimistic();
+   }
+
+   public void testReplAsyncOptBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplAsyncOptimistic();
+   }
+}

Added: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java	2007-12-11 17:13:57 UTC (rev 4829)
@@ -0,0 +1,173 @@
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test to use with a profiler to profile replication.  To be used in conjunction with ProfileSlaveTest.
+ * <p/>
+ * Typical usage pattern:
+ * <p/>
+ * 1.  Start a single test method in ProfileSlaveTest.  This will block until you kill it.
+ * 2.  Start the corresponding test in this class, with the same name, in a different JVM, and attached to a profiler.
+ * 3.  Profile away!
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at Test(groups = "profiling")
+public class ProfileTest extends AbstractProfileTest
+{
+   /*
+      Test configuration options
+    */
+   protected static final long DURATION = 2 * 60000;
+   protected static final int NUM_THREADS = 10;
+   protected static final int MAX_RANDOM_SLEEP_MILLIS = 100;
+   protected static final int MAX_DEPTH = 8;
+   protected static final int MAX_OVERALL_NODES = 10000;
+
+
+   private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
+   private Random r = new Random();
+
+   @BeforeTest
+   public void initialiseFqns()
+   {
+      fqns.clear();
+      for (int i = 0; i < MAX_OVERALL_NODES; i++)
+      {
+         Fqn fqn = createRandomFqn(r);
+         while (fqns.contains(fqn)) fqn = createRandomFqn(r);
+         if (i % 100 == 0) System.out.println("Generated " + i + " fqns");
+         fqns.add(fqn);
+      }
+      System.gc();
+      System.out.println("Finished initialising.  Starting test.");
+   }
+
+   private Fqn createRandomFqn(Random r)
+   {
+      String s = "/";
+      int depth = r.nextInt(MAX_DEPTH);
+      for (int i = 0; i < depth; i++)
+      {
+         s += r.nextInt(Integer.MAX_VALUE) + "/";
+      }
+
+      return Fqn.fromString(s);
+   }
+
+   public void testReplSync() throws Exception
+   {
+      cache.start();
+      doTest();
+   }
+
+   public void testReplAsync() throws Exception
+   {
+      cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      cache.start();
+      doTest();
+   }
+
+   public void testReplSyncOptimistic() throws Exception
+   {
+      cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      cache.start();
+      doTest();
+   }
+
+   public void testReplAsyncOptimistic() throws Exception
+   {
+      cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      cache.start();
+      doTest();
+   }
+
+   public void testReplSyncBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplSync();
+   }
+
+   public void testReplAsyncBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplAsync();
+   }
+
+   public void testReplSyncOptBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplSyncOptimistic();
+   }
+
+   public void testReplAsyncOptBR() throws Exception
+   {
+      BuddyReplicationConfig brc = new BuddyReplicationConfig();
+      brc.setEnabled(true);
+      cache.getConfiguration().setBuddyReplicationConfig(brc);
+      testReplAsyncOptimistic();
+   }
+
+   private void doTest() throws Exception
+   {
+      ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
+      long end = System.currentTimeMillis() + DURATION;
+
+      while (System.currentTimeMillis() < end)
+      {
+         exec.execute(new Runnable()
+         {
+            public void run()
+            {
+               String k = getRandomString();
+               String v = getRandomString();
+               cache.put(fqns.get(r.nextInt(MAX_OVERALL_NODES)), k, v);
+            }
+         });
+         TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
+      }
+
+      // wait for executors to complete!
+      exec.shutdown();
+      exec.awaitTermination(10000, TimeUnit.MILLISECONDS);
+
+      System.out.println("Completed Test!");
+   }
+
+   private String getRandomString()
+   {
+      StringBuilder sb = new StringBuilder();
+      int len = r.nextInt(10);
+
+      for (int i = 0; i < len; i++)
+      {
+         sb.append((char) (63 + r.nextInt(26)));
+      }
+      return sb.toString();
+   }
+}




More information about the jbosscache-commits mailing list