1 5 package com.tctest; 6 7 import com.tc.object.config.ConfigVisitor; 8 import com.tc.object.config.DSOClientConfigHelper; 9 import com.tc.object.config.TransparencyClassSpec; 10 import com.tc.simulator.app.ApplicationConfig; 11 import com.tc.simulator.listener.ListenerProvider; 12 import com.tctest.runner.AbstractErrorCatchingTransparentApp; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 import java.util.concurrent.CyclicBarrier ; 17 18 public class MutableInstrumentedEnumTest extends TransparentTestBase { 19 20 private static final int NODE_COUNT = 3; 21 22 public void doSetUp(TransparentTestIface t) throws Exception { 23 t.getTransparentAppConfig().setClientCount(NODE_COUNT); 24 t.initializeTestRunner(); 25 } 26 27 protected Class getApplicationClass() { 28 return MutableInstrumentedEnumTestApp.class; 29 } 30 31 public static class MutableInstrumentedEnumTestApp extends AbstractErrorCatchingTransparentApp { 32 33 private final Map <String , Ref> mapRoot = new HashMap <String , Ref>(); 34 private final CyclicBarrier barrier; 35 36 public MutableInstrumentedEnumTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 37 super(appId, cfg, listenerProvider); 38 barrier = new CyclicBarrier (getParticipantCount()); 39 } 40 41 protected void runTest() throws Throwable { 42 43 int index = barrier.await(); 44 45 MutableEnum e = MutableEnum.THREE; 46 47 if (index == 0) { 48 synchronized (mapRoot) { 49 mapRoot.put("e", new Ref(e)); 50 } 51 } 52 53 barrier.await(); 54 55 if (index == 0) { 56 synchronized (mapRoot) { 57 e.mutate(); 58 } 59 } 60 61 barrier.await(); 62 63 if (index != 0) { 64 synchronized (mapRoot) { 67 mapRoot.clear(); 68 } 69 } 70 71 barrier.await(); 72 73 } 74 75 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 76 String testClass = MutableInstrumentedEnumTestApp.class.getName(); 77 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 78 79 config.getOrCreateSpec(MutableEnum.class.getName()); 80 config.getOrCreateSpec(Ref.class.getName()); 81 82 String methodExpression = "* " + testClass + "*.*(..)"; 83 config.addWriteAutolock(methodExpression); 84 85 spec.addRoot("barrier", "barrier"); 86 spec.addRoot("mapRoot", "mapRoot"); 87 } 88 89 } 90 91 public enum MutableEnum { 92 ONE, TWO, THREE; 93 94 private int mutableState; 95 96 int mutate() { 97 return ++mutableState; 98 } 99 } 100 101 private static class Ref { 102 103 private final Object o; 104 105 Ref(Object o) { 106 this.o = o; 107 } 108 109 Object getO() { 110 return o; 111 } 112 113 } 114 115 } 116 | Popular Tags |