01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest;
06:
07: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
08:
09: import com.tc.object.config.ConfigVisitor;
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.tc.util.Assert;
15: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
16:
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: public class InterfaceInstrumentTestApp extends
21: AbstractErrorCatchingTransparentApp {
22: private final CyclicBarrier barrier;
23: private MyInterface root = new MyConcrete();
24:
25: public InterfaceInstrumentTestApp(String appId,
26: ApplicationConfig cfg, ListenerProvider listenerProvider) {
27: super (appId, cfg, listenerProvider);
28: barrier = new CyclicBarrier(getParticipantCount());
29: }
30:
31: public static void visitL1DSOConfig(ConfigVisitor visitor,
32: com.tc.object.config.DSOClientConfigHelper config) {
33: String testClass = InterfaceInstrumentTestApp.class.getName();
34: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
35:
36: String methodExpression = "* " + testClass + "*.*(..)";
37: config.addWriteAutolock(methodExpression);
38: spec.addRoot("barrier", "barrier");
39: spec.addRoot("root", "root");
40: new CyclicBarrierSpec().visit(visitor, config);
41:
42: String concreteClass = MyConcrete.class.getName();
43: String interfaceName = MyInterface.class.getName();
44:
45: config.addIncludePattern(interfaceName + "+");
46:
47: // THIS IS INTENTIONALLY COMMENTED OUT TO MAKE SURE
48: // THE TEST STILL PASSES. SEE CDV-144
49: // config.addIncludePattern(concreteClass);
50:
51: config.addWriteAutolock("* " + concreteClass + "*.*(..)");
52: }
53:
54: protected void runTest() throws Throwable {
55: if (barrier.barrier() == 0) {
56: root.add("one");
57: root.add("two");
58: }
59:
60: barrier.barrier();
61: Assert.assertEquals(2, root.getSize());
62:
63: }
64:
65: static interface MyInterface {
66: int getSize();
67:
68: void add(Object o);
69: }
70:
71: static class MyConcrete implements MyInterface {
72: protected List list = new ArrayList();
73:
74: public void add(Object o) {
75: synchronized (list) {
76: list.add(o);
77: }
78: }
79:
80: public int getSize() {
81: synchronized (list) {
82: return list.size();
83: }
84: }
85: }
86:
87: }
|