KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > TransparentTransientTestApp


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.simulator.app.ApplicationConfig;
9 import com.tc.simulator.listener.ListenerProvider;
10 import com.tctest.runner.AbstractTransparentApp;
11
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15 /**
16  * TODO Mar 10, 2005: I, steve, am too lazy to write a single sentence describing what this class is for.
17  */

18 public class TransparentTransientTestApp extends AbstractTransparentApp {
19   private TestClass1 one = new TestClass1();
20   private TestClass2 two = new TestClass2(new Object JavaDoc());
21   private TestClass3 three = new TestClass3();
22   private TestClass4 four = new TestClass4();
23   private Map JavaDoc sharedState = new HashMap JavaDoc();
24
25   public TransparentTransientTestApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
26     super(appId, cfg, listenerProvider);
27   }
28
29   public void run() {
30     if (one.getMap() == null) {
31       notifyError("Test class one should never have a null");
32     }
33     synchronized (sharedState) {
34       if (!sharedState.containsKey("two")) {
35         sharedState.put("two", new Integer JavaDoc(0));
36       }
37       if (two.getMap() != null) {
38         int i = ((Integer JavaDoc) sharedState.get("two")).intValue();
39         ++i;
40         System.out.println("PUTTING:" + i);
41         sharedState.put("two", new Integer JavaDoc(i));
42       }
43       int i = ((Integer JavaDoc) sharedState.get("two")).intValue();
44       System.out.println("GOT:" + i);
45       if (i > 1) {
46         notifyError("Illegal value for two:" + i);
47       }
48     }
49
50     if (four.getMap() == null) {
51       notifyError("Test class one should never have a null");
52     }
53
54     synchronized (sharedState) {
55       if (!sharedState.containsKey("three")) {
56         sharedState.put("three", new Integer JavaDoc(0));
57       }
58       if (three.getMap() != null) {
59         int i = ((Integer JavaDoc) sharedState.get("three")).intValue();
60         ++i;
61         System.out.println("PUTTING:" + i);
62         sharedState.put("three", new Integer JavaDoc(i));
63       }
64       int i = ((Integer JavaDoc) sharedState.get("three")).intValue();
65       System.out.println("GOT:" + i);
66       if (i > 1) {
67         notifyError("Illegal value for three:" + i);
68       }
69     }
70
71   }
72
73   public static class TestClass1 {
74     private transient Map JavaDoc m = new HashMap JavaDoc();
75
76     public synchronized Map JavaDoc getMap() {
77       return m;
78     }
79   }
80
81   public class TestClass2 {
82     private transient Map JavaDoc m = new HashMap JavaDoc();
83
84     public TestClass2() {
85       notifyError("This method should never be called");
86     }
87
88     public TestClass2(Object JavaDoc r) {
89       //
90
}
91
92     public synchronized Map JavaDoc getMap() {
93       return m;
94     }
95   }
96
97   public static class TestClass3 {
98     private Map JavaDoc m = new HashMap JavaDoc();
99
100     public synchronized Map JavaDoc getMap() {
101       return m;
102     }
103   }
104
105   public static class TestClass4 {
106     private transient Map JavaDoc m = new HashMap JavaDoc();
107
108     public synchronized Map JavaDoc getMap() {
109       return m;
110     }
111   }
112
113   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
114     try {
115       String JavaDoc testClassName = TransparentTransientTestApp.class.getName();
116       config.addRoot(testClassName, "one", "one", true);
117       config.addRoot(testClassName, "two", "two", true);
118       config.addRoot(testClassName, "three", "three", true);
119       config.addRoot(testClassName, "four", "four", true);
120       config.addRoot(testClassName, "sharedState", "sharedState", true);
121       config.addIncludePattern(TestClass1.class.getName(), false);
122       config.addIncludePattern(TestClass2.class.getName(), true);
123       config.addIncludePattern(TestClass3.class.getName(), true);
124       config.addTransient(TestClass3.class.getName(), "m");
125       config.addIncludePattern(TestClass4.class.getName(), false);
126
127       String JavaDoc methodExpression = "* " + testClassName + "*.*(..)";
128       System.err.println("Adding autolock for: " + methodExpression);
129       config.addWriteAutolock(methodExpression);
130     } catch (Exception JavaDoc e) {
131       throw new AssertionError JavaDoc(e);
132     }
133   }
134
135 }
Popular Tags