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.tc.util.Assert;
12: import com.tctest.runner.AbstractTransparentApp;
13:
14: import gnu.trove.THashSet;
15:
16: import java.util.HashSet;
17: import java.util.Iterator;
18: import java.util.Set;
19:
20: public class TransparentTHashSetTestApp extends AbstractTransparentApp {
21:
22: private THashSet tsetroot = new THashSet();
23: private Set steps = new HashSet();
24:
25: public TransparentTHashSetTestApp(String appId,
26: ApplicationConfig cfg, ListenerProvider listenerProvider) {
27: super (appId, cfg, listenerProvider);
28:
29: }
30:
31: public void run() {
32: System.out.println("Running...");
33: synchronized (tsetroot) {
34: switch (steps.size()) {
35: case 0:
36: stage1();
37: break;
38: case 1:
39: stage2();
40: break;
41: }
42: steps.add(new Object());
43: System.out.println("Stage:" + steps.size());
44: }
45: }
46:
47: private void stage2() {
48: for (Iterator i = tsetroot.iterator(); i.hasNext();) {
49: System.out.println(i.next());
50: }
51: Assert.assertEquals(1, tsetroot.size());
52: }
53:
54: private void stage1() {
55: TestObject to1 = new TestObject("1");
56: tsetroot.add(to1);
57: tsetroot.add(new TestObject("1"));
58: tsetroot.add(new TestObject("4"));
59: tsetroot.remove(new TestObject("4"));
60: }
61:
62: public static void visitL1DSOConfig(ConfigVisitor visitor,
63: DSOClientConfigHelper config) {
64: String testClass = TransparentTHashSetTestApp.class.getName();
65: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
66:
67: String methodExpression = "* " + testClass + "*.*(..)";
68: config.addWriteAutolock(methodExpression);
69: spec.addRoot("tsetroot", "tsetroot");
70: spec.addRoot("steps", "steps");
71:
72: config.addIncludePattern(TestObject.class.getName());
73: }
74:
75: private static class TestObject {
76: private String value;
77:
78: public TestObject(String value) {
79: this .value = value;
80: }
81:
82: public int hashCode() {
83: return value.hashCode();
84: }
85:
86: public boolean equals(Object obj) {
87: if (obj instanceof TestObject) {
88: TestObject to = (TestObject) obj;
89: return this .value.equals(to.value);
90: }
91: return false;
92: }
93:
94: public String toString() {
95: return value;
96: }
97: }
98: }
|