001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
006:
007: import com.tc.object.config.ConfigVisitor;
008: import com.tc.object.config.DSOClientConfigHelper;
009: import com.tc.object.config.Root;
010: import com.tc.simulator.app.ApplicationConfig;
011: import com.tc.simulator.listener.ListenerProvider;
012: import com.tctest.runner.AbstractTransparentApp;
013:
014: import java.util.HashMap;
015: import java.util.Map;
016:
017: public class TransparentTransientTestApp extends AbstractTransparentApp {
018: private TestClass1 one = new TestClass1();
019: private TestClass2 two = new TestClass2(new Object());
020: private TestClass3 three = new TestClass3();
021: private TestClass4 four = new TestClass4();
022: private Map sharedState = new HashMap();
023:
024: public TransparentTransientTestApp(String appId,
025: ApplicationConfig cfg, ListenerProvider listenerProvider) {
026: super (appId, cfg, listenerProvider);
027: }
028:
029: public void run() {
030: if (one.getMap() == null) {
031: notifyError("Test class one should never have a null");
032: }
033: synchronized (sharedState) {
034: if (!sharedState.containsKey("two")) {
035: sharedState.put("two", new Integer(0));
036: }
037: if (two.getMap() != null) {
038: int i = ((Integer) sharedState.get("two")).intValue();
039: ++i;
040: System.out.println("PUTTING:" + i);
041: sharedState.put("two", new Integer(i));
042: }
043: int i = ((Integer) sharedState.get("two")).intValue();
044: System.out.println("GOT:" + i);
045: if (i > 1) {
046: notifyError("Illegal value for two:" + i);
047: }
048: }
049:
050: if (four.getMap() == null) {
051: notifyError("Test class one should never have a null");
052: }
053:
054: synchronized (sharedState) {
055: if (!sharedState.containsKey("three")) {
056: sharedState.put("three", new Integer(0));
057: }
058: if (three.getMap() != null) {
059: int i = ((Integer) sharedState.get("three")).intValue();
060: ++i;
061: System.out.println("PUTTING:" + i);
062: sharedState.put("three", new Integer(i));
063: }
064: int i = ((Integer) sharedState.get("three")).intValue();
065: System.out.println("GOT:" + i);
066: if (i > 1) {
067: notifyError("Illegal value for three:" + i);
068: }
069: }
070:
071: }
072:
073: public static class TestClass1 {
074: private transient Map m = new HashMap();
075:
076: public synchronized Map getMap() {
077: return m;
078: }
079: }
080:
081: public class TestClass2 {
082: private transient Map m = new HashMap();
083:
084: public TestClass2() {
085: notifyError("This method should never be called");
086: }
087:
088: public TestClass2(Object r) {
089: //
090: }
091:
092: public synchronized Map getMap() {
093: return m;
094: }
095: }
096:
097: public static class TestClass3 {
098: private Map m = new HashMap();
099:
100: public synchronized Map getMap() {
101: return m;
102: }
103: }
104:
105: public static class TestClass4 {
106: private transient Map m = new HashMap();
107:
108: public synchronized Map getMap() {
109: return m;
110: }
111: }
112:
113: public static void visitL1DSOConfig(ConfigVisitor visitor,
114: DSOClientConfigHelper config) {
115: try {
116: String testClassName = TransparentTransientTestApp.class
117: .getName();
118: config.addRoot(new Root(testClassName, "one", "one"), true);
119: config.addRoot(new Root(testClassName, "two", "two"), true);
120: config.addRoot(new Root(testClassName, "three", "three"),
121: true);
122: config.addRoot(new Root(testClassName, "four", "four"),
123: true);
124: config.addRoot(new Root(testClassName, "sharedState",
125: "sharedState"), true);
126: config.addIncludePattern(TestClass1.class.getName(), false);
127: config.addIncludePattern(TestClass2.class.getName(), true);
128: config.addIncludePattern(TestClass3.class.getName(), true);
129: config.addTransient(TestClass3.class.getName(), "m");
130: config.addIncludePattern(TestClass4.class.getName(), false);
131:
132: String methodExpression = "* " + testClassName + "*.*(..)";
133: System.err.println("Adding autolock for: "
134: + methodExpression);
135: config.addWriteAutolock(methodExpression);
136: } catch (Exception e) {
137: throw new AssertionError(e);
138: }
139: }
140:
141: }
|