1 4 package com.tctest; 5 6 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 7 8 import com.tc.object.config.ConfigVisitor; 9 import com.tc.object.config.DSOClientConfigHelper; 10 import com.tc.object.config.TransparencyClassSpec; 11 import com.tc.object.config.spec.CyclicBarrierSpec; 12 import com.tc.simulator.app.ApplicationConfig; 13 import com.tc.simulator.listener.ListenerProvider; 14 import com.tc.util.Assert; 15 import com.tctest.runner.AbstractErrorCatchingTransparentApp; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 public class OnLoadTestApp extends AbstractErrorCatchingTransparentApp { 21 private final CyclicBarrier barrier; 22 23 private MyObject root; 24 private MyObject1 root1; 25 private MyObject2 root2; 26 private MyObject3 root3; 27 28 public OnLoadTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 29 super(appId, cfg, listenerProvider); 30 this.barrier = new CyclicBarrier(getParticipantCount()); 31 } 32 33 protected void runTest() throws Throwable { 34 boolean creator = (barrier.barrier() == 0); 36 37 if (creator) { 38 createRoots(); 39 } 40 41 barrier.barrier(); 42 43 synchronized (root) { 44 Assert.eval(root.getSize() == 0); 45 Assert.eval(root.ok); 46 47 Assert.eval(root1.getSize() == 0); 48 49 try { 50 root2.getSize(); 51 Assert.eval(creator); 52 } catch (NullPointerException npe) { 53 Assert.eval(!creator); 54 System.out.println("YEAH! GOT NPE"); 56 } 57 } 58 59 synchronized (root3) { 61 try { 62 root3.getSize(); 63 Assert.eval(creator); 64 } catch (NullPointerException npe) { 65 Assert.eval(!creator); 66 System.out.println("YEAH! GOT NPE"); 68 } 69 } 70 } 71 72 private void createRoots() { 73 root = new MyObject(null); 74 root1 = new MyObject1(null); 75 root2 = new MyObject2(null); 76 root3 = new MyObject3(); 77 } 78 79 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 80 new CyclicBarrierSpec().visit(visitor, config); 81 82 String testClass = OnLoadTestApp.class.getName(); 83 TransparencyClassSpec spec = config.getOrCreateSpec(MyObject.class.getName()); 84 spec.setHonorTransient(true); 85 spec 87 .setExecuteScriptOnLoad("if(self.mine == null){self.ok = false;}else{self.ok = true;} self.list = new ArrayList();"); 88 89 spec = config.getOrCreateSpec(MyObject1.class.getName()); 90 spec.setHonorTransient(true); 91 spec.setCallMethodOnLoad("initialize"); 92 93 spec = config.getOrCreateSpec(MyObject2.class.getName()); 94 spec.setHonorTransient(true); 95 96 spec = config.getOrCreateSpec(MyObject3.class.getName()); 97 spec.setHonorTransient(true); 98 spec.setExecuteScriptOnLoad("<![CDATA[***********;]]>"); 99 100 spec = config.getOrCreateSpec(testClass); 101 102 String methodExpression = "* " + testClass + "*.*(..)"; 103 config.addWriteAutolock(methodExpression); 104 spec.addRoot("root", "root"); 105 spec.addRoot("root1", "root1"); 106 spec.addRoot("root2", "root2"); 107 spec.addRoot("root3", "root3"); 108 spec.addRoot("barrier", "barrier"); 109 } 110 111 private static class MyObject { 112 private transient List list = new ArrayList (); 113 private MyObject1 mine = new MyObject1(null); 114 public volatile transient boolean ok = true; 115 116 public MyObject(Object o) { 117 System.out.println(mine); 119 } 120 121 public int getSize() { 122 return list.size(); 123 } 124 125 } 126 127 private static class MyObject1 { 128 private transient List list; 129 130 public MyObject1(Object o) { 131 initialize(); 132 } 133 134 public void initialize() { 135 list = new ArrayList (); 136 } 137 138 public int getSize() { 139 return list.size(); 140 } 141 } 142 143 private static class MyObject2 { 144 private transient List list = new ArrayList (); 145 146 public MyObject2(Object o) { 147 } 149 150 public int getSize() { 151 return list.size(); 152 } 153 } 154 155 158 private static class MyObject3 { 159 private transient List list = new ArrayList (); 160 public volatile transient boolean ok = true; 161 162 public MyObject3() { 163 super(); 164 } 165 166 public int getSize() { 167 return list.size(); 168 } 169 170 } 171 } 172
| Popular Tags
|