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 SubtypeInstrumentTestApp extends
21: AbstractErrorCatchingTransparentApp {
22: private final CyclicBarrier barrier;
23: private SubClass root = new SubClass();
24:
25: public SubtypeInstrumentTestApp(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 = SubtypeInstrumentTestApp.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 baseClass = BaseClass.class.getName();
43: String subClass = SubClass.class.getName();
44:
45: config.addIncludePattern(baseClass + "+");
46:
47: // THIS IS INTENTIONALLY COMMENTED OUT TO MAKE SURE
48: // THE TEST STILL PASSES. SEE CDV-144
49: // config.addIncludePattern(subClass);
50:
51: config.addWriteAutolock("* " + baseClass + "*.*(..)");
52: config.addWriteAutolock("* " + subClass + "*.*(..)");
53:
54: }
55:
56: protected void runTest() throws Throwable {
57: if (barrier.barrier() == 0) {
58: root.add("one");
59: root.add("two");
60: }
61:
62: barrier.barrier();
63: Assert.assertEquals(2, root.getSize());
64:
65: }
66:
67: static class BaseClass {
68: protected List list = new ArrayList();
69:
70: public void add(Object o) {
71: synchronized (list) {
72: list.add(o);
73: }
74: }
75:
76: public int getSize() {
77: synchronized (list) {
78: return list.size();
79: }
80: }
81:
82: }
83:
84: static class SubClass extends BaseClass {
85: public Object getFirst() {
86: synchronized (list) {
87: return list.get(0);
88: }
89: }
90: }
91:
92: }
|