1 4 package com.tctest; 5 6 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 7 8 import com.tc.object.config.ConfigLockLevel; 9 import com.tc.object.config.ConfigVisitor; 10 import com.tc.object.config.DSOClientConfigHelper; 11 import com.tc.object.config.LockDefinition; 12 import com.tc.object.config.TransparencyClassSpec; 13 import com.tc.simulator.app.ApplicationConfig; 14 import com.tc.simulator.listener.ListenerProvider; 15 import com.tc.util.Assert; 16 import com.tctest.runner.AbstractTransparentApp; 17 18 public class InstrumentedConstructorTestApp extends AbstractTransparentApp { 19 20 private final CyclicBarrier barrier; 21 private final DataRoot dataRoot = new DataRoot(); 22 23 public InstrumentedConstructorTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 24 super(appId, cfg, listenerProvider); 25 barrier = new CyclicBarrier(getParticipantCount()); 26 } 27 28 public void run() { 29 try { 30 int index = barrier.barrier(); 31 32 TestConstructorClass c = new TestConstructorClass(); 33 testShared(index, c); 34 35 c = new TestConstructorClass(10L); 36 testShared(index, c); 37 38 } catch (Throwable t) { 39 notifyError(t); 40 } 41 } 42 43 private void testShared(int index, TestConstructorClass c) throws Exception { 44 if (index == 0) { 45 synchronized(dataRoot) { 46 dataRoot.setC1(c); 47 } 48 } 49 50 barrier.barrier(); 51 52 Assert.assertNotNull(dataRoot.getC1()); 53 54 barrier.barrier(); 55 } 56 57 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 58 TransparencyClassSpec spec = config.getOrCreateSpec(CyclicBarrier.class.getName()); 59 config.addWriteAutolock("* " + CyclicBarrier.class.getName() + "*.*(..)"); 60 61 String testClass = InstrumentedConstructorTestApp.class.getName(); 62 spec = config.getOrCreateSpec(testClass); 63 config.addIncludePattern(testClass + "$*"); 64 65 String methodExpression = "* " + testClass + "$TestConstructorClass.*(..)"; 66 LockDefinition definition = new LockDefinition("nameLock", ConfigLockLevel.WRITE); 67 definition.commit(); 68 config.addLock(methodExpression, definition); 69 70 methodExpression = "* " + testClass + "*.*(..)"; 71 config.addWriteAutolock(methodExpression); 72 73 spec.addRoot("barrier", "barrier"); 74 spec.addRoot("dataRoot", "dataRoot"); 75 } 76 77 private static class DataRoot { 78 private TestConstructorClass c1; 79 80 public DataRoot() { 81 super(); 82 } 83 84 public void setC1(TestConstructorClass c1) { 85 this.c1 = c1; 86 } 87 88 public TestConstructorClass getC1() { 89 return c1; 90 } 91 } 92 93 private static class TestConstructorSuperClass { 94 private String s; 95 96 public TestConstructorSuperClass() { 97 } 99 100 public TestConstructorSuperClass(String s) { 101 this.s = s; 102 } 103 104 public String getS() { 105 return s; 106 } 107 } 108 109 private static class TestConstructorClass extends TestConstructorSuperClass { 110 public TestConstructorClass() { 111 super(new StringBuffer ("testString").toString()); 112 } 113 114 public TestConstructorClass(TestConstructorClass c) { 115 } 117 118 public TestConstructorClass(long k) { 119 this(new TestConstructorClass()); 120 } 121 } 122 123 } 124
| Popular Tags
|