001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest;
005:
006: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
007:
008: import com.tc.object.config.ConfigVisitor;
009: import com.tc.object.config.DSOClientConfigHelper;
010: import com.tc.object.config.TransparencyClassSpec;
011: import com.tc.object.config.spec.CyclicBarrierSpec;
012: import com.tc.simulator.app.ApplicationConfig;
013: import com.tc.simulator.listener.ListenerProvider;
014: import com.tctest.runner.AbstractTransparentApp;
015:
016: public class SyntheticFaultTestApp extends AbstractTransparentApp {
017:
018: private CyclicBarrier barrier;
019: private MyIntfRoot root = new MyIntfRoot();
020:
021: public SyntheticFaultTestApp(String appId, ApplicationConfig cfg,
022: ListenerProvider listenerProvider) {
023: super (appId, cfg, listenerProvider);
024: this .barrier = new CyclicBarrier(getParticipantCount());
025: }
026:
027: public void run() {
028: try {
029: int index = barrier.barrier();
030:
031: if (index == 0) {
032: MyIntf f = foo("test");
033: root.setF(f);
034: root.setS("Test String");
035: }
036:
037: barrier.barrier();
038:
039: if (index == 1) {
040: MyIntf f = root.getF();
041: root.getS();
042: f.f();
043: }
044:
045: barrier.barrier();
046: } catch (Throwable t) {
047: notifyError(t);
048: }
049: }
050:
051: public static void visitL1DSOConfig(ConfigVisitor visitor,
052: DSOClientConfigHelper config) {
053: String testClass = SyntheticFaultTestApp.class.getName();
054: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
055: spec.addRoot("barrier", "barrier");
056: spec.addRoot("root", "root");
057: config.addIncludePattern("*" + testClass + "$*");
058: //spec = config.getOrCreateSpec(MyIntf.class.getName());
059: //spec = config.getOrCreateSpec(MyIntfRoot.class.getName());
060:
061: String methodExpression = "* " + testClass + "*.*(..)";
062: config.addWriteAutolock(methodExpression);
063: new CyclicBarrierSpec().visit(visitor, config);
064:
065: }
066:
067: private static class MyIntfRoot {
068: MyIntf f;
069: String s;
070:
071: public MyIntfRoot() {
072: super ();
073: }
074:
075: public synchronized void setF(MyIntf f) {
076: this .f = f;
077: }
078:
079: public synchronized MyIntf getF() {
080: return f;
081: }
082:
083: public synchronized String getS() {
084: return s;
085: }
086:
087: public synchronized void setS(String s) {
088: this .s = s;
089: }
090: }
091:
092: MyIntf foo(final String f) {
093: return new MyIntf() {
094: public String f() {
095: return f.toString();
096: }
097: };
098: }
099:
100: interface MyIntf {
101: String f();
102: }
103:
104: }
|