1 5 package com.tctest.transparency; 6 7 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 8 9 import com.tc.object.config.ConfigVisitor; 10 import com.tc.object.config.DSOClientConfigHelper; 11 import com.tc.object.config.TransparencyClassSpec; 12 import com.tc.object.config.spec.CyclicBarrierSpec; 13 import com.tc.simulator.app.ApplicationConfig; 14 import com.tc.simulator.listener.ListenerProvider; 15 import com.tc.util.Assert; 16 import com.tctest.TransparentTestBase; 17 import com.tctest.TransparentTestIface; 18 import com.tctest.runner.AbstractErrorCatchingTransparentApp; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 public class SubclassCloneTest extends TransparentTestBase { 24 private static final int NODE_COUNT = 2; 25 26 protected Class getApplicationClass() { 27 return SubclassCloneTestApp.class; 28 } 29 30 public void doSetUp(TransparentTestIface t) throws Exception { 31 t.getTransparentAppConfig().setClientCount(NODE_COUNT).setIntensity(1); 32 t.initializeTestRunner(); 33 } 34 35 public static class SubclassCloneTestApp extends AbstractErrorCatchingTransparentApp { 36 37 private final CyclicBarrier barrier; 38 private Map root; 39 40 public SubclassCloneTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 41 super(appId, cfg, listenerProvider); 42 barrier = new CyclicBarrier(getParticipantCount()); 43 } 44 45 protected void runTest() throws Throwable { 46 int index = barrier.barrier(); 47 48 if (index == 0) { 49 root = new HashMap (); 50 synchronized (root) { 51 root.put("object", new Subclass()); 52 } 53 } 54 55 barrier.barrier(); 56 57 if (index != 0) { 58 Subclass sub; 59 synchronized (root) { 60 sub = (Subclass) root.get("object"); 61 } 62 63 Subclass cloned = (Subclass) sub.clone(); 64 Assert.assertNotNull(cloned.getO()); 65 } 66 } 67 68 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 69 String testClass = SubclassCloneTestApp.class.getName(); 70 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 71 String methodExpression = "* " + testClass + "*.*(..)"; 72 config.addWriteAutolock(methodExpression); 73 spec.addRoot("root", "root"); 74 spec.addRoot("barrier", "barrier"); 75 76 new CyclicBarrierSpec().visit(visitor, config); 77 78 config.addIncludePattern("*..*", false); 79 } 80 81 } 82 83 private static class Base implements Cloneable { 84 private final Object o = this; 85 86 public Object getO() { 87 return o; 88 } 89 } 90 91 private static class Subclass extends Base implements Cloneable { 92 93 public Object clone() throws CloneNotSupportedException { 94 return super.clone(); 95 } 96 97 } 98 99 } 100
| Popular Tags
|