[jboss-cvs] JBossCache/tests/perf/org/jboss/cache/manualtests ...
Manik Surtani
msurtani at jboss.com
Wed Oct 25 08:49:31 EDT 2006
User: msurtani
Date: 06/10/25 08:49:31
Added: tests/perf/org/jboss/cache/manualtests
TcpCacheLoaderTest.java
Log:
JBCACHE-690
JBCACHE-800
JBCACHE-810
Revision Changes Path
1.2 +115 -0 JBossCache/tests/perf/org/jboss/cache/manualtests/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:49:31 -0000 1.2
@@ -0,0 +1,115 @@
+package org.jboss.cache.manualtests;
+
+import junit.textui.TestRunner;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.TreeCache;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
+import org.jboss.cache.loader.JDBCCacheLoaderPerfTest;
+import org.jboss.cache.loader.TcpDelegatingCacheLoader;
+
+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();
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ TcpDelegatingCacheLoader.Config cfg = new TcpDelegatingCacheLoader.Config();
+ cfg.setHost(serverHost);
+ cfg.setPort(serverPort);
+
+ clc.addIndividualCacheLoaderConfig(cfg);
+
+ cache.getConfiguration().setCacheLoaderConfig(clc);
+ }
+
+ public void testPerformance() throws Exception
+ {
+ int n = 5;
+ cache.start();
+
+ Runner r = new Runner(cache, n, "RunnerThread");
+ r.start();
+ r.join();
+ cache.stop();
+
+ cache.start();
+ for (int i = 0; i < n; i++)
+ {
+ System.out.println("Getting " + i);
+ assertEquals("v", cache.get("/test/fqn/RunnerThread/" + i, "k"));
+ }
+ cache.stop();
+
+ }
+
+ public void testPerformanceMT() throws Exception
+ {
+ int n = 500;
+ Runner[] r = new Runner[20];
+ cache.start();
+
+ 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.stop();
+
+ cache.start();
+ 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.stop();
+
+ // 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