[jboss-cvs] JBossCache/tests/perf/org/jboss/cache/manualtests ...

Manik Surtani msurtani at jboss.com
Wed Oct 25 08:16:58 EDT 2006


  User: msurtani
  Date: 06/10/25 08:16:58

  Added:       tests/perf/org/jboss/cache/manualtests  Tag:
                        Branch_JBossCache_1_4_0 TcpCacheLoaderTest.java
  Log:
  JBCACHE-690
  JBCACHE-800
  JBCACHE-810
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +106 -0    JBossCache/tests/perf/org/jboss/cache/manualtests/Attic/TcpCacheLoaderTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TcpCacheLoaderTest.java
  ===================================================================
  RCS file: TcpCacheLoaderTest.java
  diff -N TcpCacheLoaderTest.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ TcpCacheLoaderTest.java	25 Oct 2006 12:16:58 -0000	1.1.2.1
  @@ -0,0 +1,106 @@
  +package org.jboss.cache.manualtests;
  +
  +import junit.textui.TestRunner;
  +import org.jboss.cache.CacheException;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
  +import org.jboss.cache.loader.JDBCCacheLoaderPerfTest;
  +
  +public class TcpCacheLoaderTest extends AbstractCacheLoaderTestBase
  +{
  +   private TreeCache cache;
  +   private static final int serverPort = 7500;
  +   private static final String serverHost = "127.0.0.1";
  +
  +   protected void setUp() throws Exception
  +   {
  +      cache = new TreeCache();
  +      cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.tcp.TcpDelegatingCacheLoader", "port=" + serverPort + "\nhost=" + serverHost, false, false, false));
  +   }
  +
  +   public void testPerformance() throws Exception
  +   {
  +      int n = 5;
  +      cache.startService();
  +
  +      Runner r = new Runner(cache, n, "RunnerThread");
  +      r.start();
  +      r.join();
  +      cache.stopService();
  +
  +      cache.startService();
  +      for (int i = 0; i < n; i++)
  +      {
  +         System.out.println("Getting " + i);
  +         assertEquals("v", cache.get("/test/fqn/RunnerThread/" + i, "k"));
  +      }
  +      cache.stopService();
  +
  +   }
  +
  +   public void testPerformanceMT() throws Exception
  +   {
  +      int n = 500;
  +      Runner[] r = new Runner[20];
  +      cache.startService();
  +
  +      for (int i = 0; i < r.length; i++)
  +      {
  +         r[i] = new Runner(cache, n, "RunnerThread-" + i);
  +         r[i].start();
  +      }
  +
  +      for (int i = 0; i < r.length; i++) r[i].join();
  +      cache.stopService();
  +
  +      cache.startService();
  +      for (int i = 0; i < n; i++)
  +      {
  +         //System.out.println("Getting " + i);
  +         for (int j = 0; j < r.length; j++) assertEquals("v", cache.get("/test/fqn/RunnerThread-" + j + "/" + i, "k"));
  +      }
  +      cache.stopService();
  +
  +      // metrics
  +      long totalTime = 0;
  +      for (int i = 0; i < r.length; i++) totalTime += r[i].totalTime;
  +
  +      System.out.println("Took " + ((double) totalTime / 1000) + " secs to process " + (n * r.length) + " put operations");
  +   }
  +
  +   private class Runner extends Thread
  +   {
  +      private TreeCache cache;
  +      private int n;
  +      long totalTime;
  +
  +      public Runner(TreeCache cache, int n, String instanceName)
  +      {
  +         super(instanceName);
  +         this.cache = cache;
  +         this.n = n;
  +      }
  +
  +      public void run()
  +      {
  +         long st = System.currentTimeMillis();
  +         for (int i = 0; i < n; i++)
  +         {
  +            try
  +            {
  +               cache.put("/test/fqn/" + getName() + "/" + i, "k", "v");
  +            }
  +            catch (CacheException e)
  +            {
  +            }
  +         }
  +         totalTime = System.currentTimeMillis() - st;
  +      }
  +   }
  +
  +
  +   public static void main(String[] args)
  +   {
  +      TestRunner.run(JDBCCacheLoaderPerfTest.class);
  +   }
  +}
  
  
  



More information about the jboss-cvs-commits mailing list