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 SyntheticFaultTestApp extends AbstractTransparentApp { 17 18 private CyclicBarrier barrier; 19 private MyIntfRoot root = new MyIntfRoot(); 20 21 public SyntheticFaultTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 22 super(appId, cfg, listenerProvider); 23 this.barrier = new CyclicBarrier(getParticipantCount()); 24 } 25 26 public void run() { 27 try { 28 int index = barrier.barrier(); 29 30 if (index == 0) { 31 MyIntf f = foo("test"); 32 root.setF(f); 33 root.setS("Test String"); 34 } 35 36 barrier.barrier(); 37 38 if (index == 1) { 39 MyIntf f = root.getF(); 40 root.getS(); 41 f.f(); 42 } 43 44 barrier.barrier(); 45 } catch (Throwable t) { 46 notifyError(t); 47 } 48 } 49 50 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 51 String testClass = SyntheticFaultTestApp.class.getName(); 52 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 53 spec.addRoot("barrier", "barrier"); 54 spec.addRoot("root", "root"); 55 config.addIncludePattern("*"+testClass+"$*"); 56 59 String methodExpression = "* " + testClass + "*.*(..)"; 60 config.addWriteAutolock(methodExpression); 61 new CyclicBarrierSpec().visit(visitor, config); 62 63 } 64 65 private static class MyIntfRoot { 66 MyIntf f; 67 String s; 68 69 public MyIntfRoot() { 70 super(); 71 } 72 73 public synchronized void setF(MyIntf f) { 74 this.f = f; 75 } 76 77 public synchronized MyIntf getF() { 78 return f; 79 } 80 81 public synchronized String getS() { 82 return s; 83 } 84 85 public synchronized void setS(String s) { 86 this.s = s; 87 } 88 } 89 90 MyIntf foo(final String f) { 91 return new MyIntf() { 92 public String f() { 93 return f.toString(); 94 } 95 }; 96 } 97 98 interface MyIntf { 99 String f(); 100 } 101 102 } 103 | Popular Tags |