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.HashSet;
14: import java.util.Set;
15:
16: public class BatchRootFaultTestApp extends AbstractTransparentApp {
17: private TestRoot root1;
18: private TestRoot root2;
19: private Set nodes = new HashSet();
20:
21: public BatchRootFaultTestApp(String appId, ApplicationConfig cfg,
22: ListenerProvider listenerProvider) {
23: super (appId, cfg, listenerProvider);
24: }
25:
26: public void run() {
27:
28: synchronized (nodes) {
29:
30: if (nodes.size() == 0) {
31: createBigRoot();
32: } else {
33: long l = System.currentTimeMillis();
34: int count = 0;
35: TestRoot current = root1;
36: while (current != null) {
37: count++;
38: current = current.getNext();
39: }
40: current = root2;
41: while (current != null) {
42: count++;
43: current = current.getNext();
44: }
45: System.out.println("******Took******:"
46: + (System.currentTimeMillis() - l) + " count:"
47: + count);
48: }
49: nodes.add(new Object());
50: }
51: }
52:
53: private void createBigRoot() {
54: root1 = new TestRoot();
55: TestRoot current = root1;
56: for (int i = 0; i < 1000; i++) {
57: current.setNext(new TestRoot());
58: current = current.getNext();
59: }
60: root2 = new TestRoot();
61: root2.setNext(root1);
62: }
63:
64: private static class TestRoot {
65: private TestRoot next;
66:
67: public void setNext(TestRoot m) {
68: this .next = m;
69: }
70:
71: public TestRoot getNext() {
72: return this .next;
73: }
74: }
75:
76: public static void visitL1DSOConfig(ConfigVisitor visitor,
77: DSOClientConfigHelper config) {
78: String testClass = BatchRootFaultTestApp.class.getName();
79: config.getOrCreateSpec(TestRoot.class.getName());
80: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
81:
82: String methodExpression = "* " + testClass + "*.*(..)";
83: config.addWriteAutolock(methodExpression);
84: spec.addRoot("root1", "root1");
85: spec.addRoot("root2", "root2");
86: spec.addRoot("nodes", "nodes");
87: }
88: }
|