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.tctest.runner.AbstractTransparentApp; 15 16 public class NullLiteralArrayElementRegressionTestApp extends AbstractTransparentApp { 17 18 private final TestObject root = new TestObject(); 19 private final CyclicBarrier barrier; 20 21 public NullLiteralArrayElementRegressionTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 22 super(appId, cfg, listenerProvider); 23 24 if (getParticipantCount() != 3) { 25 throw new RuntimeException ("wrong number of nodes: " + getParticipantCount()); 27 } 28 29 barrier = new CyclicBarrier(getParticipantCount()); 30 } 31 32 public void run() { 33 try { 34 test(); 35 } catch (Throwable t) { 36 notifyError(t); 37 } 38 } 39 40 private void test() throws Exception { 41 TestObject obj = root; 43 44 final boolean creator; 45 synchronized (obj) { 46 if (!obj.hasArray()) { 47 creator = true; 48 obj.setArray(new Object [10]); 49 } else { 50 creator = false; 51 } 52 } 53 54 barrier.barrier(); 55 56 if (creator) { 57 synchronized (obj) { 58 obj.setElement(5, 42L); 59 } 60 } 61 62 barrier.barrier(); 63 64 Object value = obj.getElement(5); 65 66 if (value == null) { throw new NullPointerException ("element is null"); } 67 } 68 69 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 70 String testClass = NullLiteralArrayElementRegressionTestApp.class.getName(); 71 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 72 73 String methodExpression = "* " + testClass + "*.*(..)"; 74 config.addWriteAutolock(methodExpression); 75 spec.addRoot("barrier", "barrier"); 76 spec.addRoot("root", "root"); 77 config.addIncludePattern(TestObject.class.getName()); 78 79 new CyclicBarrierSpec().visit(visitor, config); 80 } 81 82 private static class TestObject { 83 private Object [] array; 84 85 boolean hasArray() { 86 return this.array != null; 87 } 88 89 void setArray(Object [] a) { 90 this.array = a; 91 } 92 93 Object getElement(int index) { 94 return this.array[index]; 95 } 96 97 void setElement(int index, long value) { 99 array[index] = new Long (value); 100 } 101 102 } 103 104 } 105
| Popular Tags
|