KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > TransparentTHashSetTestApp


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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