1 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 ; 13 import java.util.Map ; 14 15 18 public class TransparentTransientTestApp extends AbstractTransparentApp { 19 private TestClass1 one = new TestClass1(); 20 private TestClass2 two = new TestClass2(new Object ()); 21 private TestClass3 three = new TestClass3(); 22 private TestClass4 four = new TestClass4(); 23 private Map sharedState = new HashMap (); 24 25 public TransparentTransientTestApp(String 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 (0)); 36 } 37 if (two.getMap() != null) { 38 int i = ((Integer ) sharedState.get("two")).intValue(); 39 ++i; 40 System.out.println("PUTTING:" + i); 41 sharedState.put("two", new Integer (i)); 42 } 43 int i = ((Integer ) 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 (0)); 57 } 58 if (three.getMap() != null) { 59 int i = ((Integer ) sharedState.get("three")).intValue(); 60 ++i; 61 System.out.println("PUTTING:" + i); 62 sharedState.put("three", new Integer (i)); 63 } 64 int i = ((Integer ) 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 m = new HashMap (); 75 76 public synchronized Map getMap() { 77 return m; 78 } 79 } 80 81 public class TestClass2 { 82 private transient Map m = new HashMap (); 83 84 public TestClass2() { 85 notifyError("This method should never be called"); 86 } 87 88 public TestClass2(Object r) { 89 } 91 92 public synchronized Map getMap() { 93 return m; 94 } 95 } 96 97 public static class TestClass3 { 98 private Map m = new HashMap (); 99 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, DSOClientConfigHelper config) { 114 try { 115 String 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 methodExpression = "* " + testClassName + "*.*(..)"; 128 System.err.println("Adding autolock for: " + methodExpression); 129 config.addWriteAutolock(methodExpression); 130 } catch (Exception e) { 131 throw new AssertionError (e); 132 } 133 } 134 135 } | Popular Tags |