01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest;
05:
06: import com.tc.object.config.ConfigVisitor;
07: import com.tc.object.config.DSOClientConfigHelper;
08: import com.tc.object.config.TransparencyClassSpec;
09: import com.tc.simulator.app.ApplicationConfig;
10: import com.tc.simulator.listener.ListenerProvider;
11: import com.tctest.runner.AbstractTransparentApp;
12:
13: import java.util.HashMap;
14: import java.util.Map;
15: import java.util.Random;
16:
17: public class CacheLoadPerformanceTestApp extends AbstractTransparentApp {
18: private Map cache = new HashMap();
19: private final static int CACHE_COUNT = 8;
20: private final static int ENTRIES = 500;
21: private final static int BATCH_SIZE = 100;
22:
23: public CacheLoadPerformanceTestApp(String appId,
24: ApplicationConfig cfg, ListenerProvider listenerProvider) {
25: super (appId, cfg, listenerProvider);
26: }
27:
28: public void run() {
29: Random r = new Random();
30: synchronized (cache) {
31: for (int i = 0; i < CACHE_COUNT; i++) {
32: cache.put(new Integer(i), new HashMap());
33: }
34: }
35: long start = System.currentTimeMillis();
36: int added = 0;
37: while (added < ENTRIES) {
38: synchronized (cache) {
39: for (int i = 0; i < BATCH_SIZE; i++) {
40: Integer cid = new Integer(r.nextInt(CACHE_COUNT));
41: Map m = (Map) cache.get(cid);
42: m.put(new TestKey(), new TestValue());
43: added++;
44: }
45: }
46: }
47: System.out.println("Total time:"
48: + (System.currentTimeMillis() - start));
49: }
50:
51: private class TestKey {
52: public Object o = new Object();
53: public String s = "Steve " + System.currentTimeMillis();
54: }
55:
56: private class TestValue {
57: public Object o = new Object();
58: public String s = "Steve " + System.currentTimeMillis();
59: }
60:
61: public static void visitL1DSOConfig(ConfigVisitor visitor,
62: DSOClientConfigHelper config) {
63: String testClass = CacheLoadPerformanceTestApp.class.getName();
64: String methodExpression = "* " + testClass + ".*(..)";
65: config.addWriteAutolock(methodExpression);
66: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
67: spec.addRoot("cache", "cache");
68: config.addIncludePattern(TestKey.class.getName());
69: config.addIncludePattern(TestValue.class.getName());
70: }
71:
72: }
|