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.ConfigLockLevel;
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOClientConfigHelper;
011: import com.tc.object.config.LockDefinition;
012: import com.tc.object.config.LockDefinitionImpl;
013: import com.tc.object.config.TransparencyClassSpec;
014: import com.tc.simulator.app.ApplicationConfig;
015: import com.tc.simulator.listener.ListenerProvider;
016: import com.tc.util.Assert;
017: import com.tctest.runner.AbstractTransparentApp;
018:
019: public class InstrumentedConstructorTestApp extends
020: AbstractTransparentApp {
021:
022: private final CyclicBarrier barrier;
023: private final DataRoot dataRoot = new DataRoot();
024:
025: public InstrumentedConstructorTestApp(String appId,
026: ApplicationConfig cfg, ListenerProvider listenerProvider) {
027: super (appId, cfg, listenerProvider);
028: barrier = new CyclicBarrier(getParticipantCount());
029: }
030:
031: public void run() {
032: try {
033: int index = barrier.barrier();
034:
035: TestConstructorClass c = new TestConstructorClass();
036: testShared(index, c);
037:
038: c = new TestConstructorClass(10L);
039: testShared(index, c);
040:
041: } catch (Throwable t) {
042: notifyError(t);
043: }
044: }
045:
046: private void testShared(int index, TestConstructorClass c)
047: throws Exception {
048: if (index == 0) {
049: synchronized (dataRoot) {
050: dataRoot.setC1(c);
051: }
052: }
053:
054: barrier.barrier();
055:
056: Assert.assertNotNull(dataRoot.getC1());
057:
058: barrier.barrier();
059: }
060:
061: public static void visitL1DSOConfig(ConfigVisitor visitor,
062: DSOClientConfigHelper config) {
063: TransparencyClassSpec spec = config
064: .getOrCreateSpec(CyclicBarrier.class.getName());
065: config.addWriteAutolock("* " + CyclicBarrier.class.getName()
066: + "*.*(..)");
067:
068: String testClass = InstrumentedConstructorTestApp.class
069: .getName();
070: spec = config.getOrCreateSpec(testClass);
071: config.addIncludePattern(testClass + "$*");
072:
073: String methodExpression = "* " + testClass
074: + "$TestConstructorClass.*(..)";
075: LockDefinition definition = new LockDefinitionImpl("nameLock",
076: ConfigLockLevel.WRITE);
077: definition.commit();
078: config.addLock(methodExpression, definition);
079:
080: methodExpression = "* " + testClass + "*.*(..)";
081: config.addWriteAutolock(methodExpression);
082:
083: spec.addRoot("barrier", "barrier");
084: spec.addRoot("dataRoot", "dataRoot");
085: }
086:
087: private static class DataRoot {
088: private TestConstructorClass c1;
089:
090: public DataRoot() {
091: super ();
092: }
093:
094: public void setC1(TestConstructorClass c1) {
095: this .c1 = c1;
096: }
097:
098: public TestConstructorClass getC1() {
099: return c1;
100: }
101: }
102:
103: private static class TestConstructorSuperClass {
104: private String s;
105:
106: public TestConstructorSuperClass() {
107: //
108: }
109:
110: public TestConstructorSuperClass(String s) {
111: this .s = s;
112: }
113:
114: public String getS() {
115: return s;
116: }
117: }
118:
119: private static class TestConstructorClass extends
120: TestConstructorSuperClass {
121: public TestConstructorClass() {
122: super (new StringBuffer("testString").toString());
123: }
124:
125: public TestConstructorClass(TestConstructorClass c) {
126: //
127: }
128:
129: public TestConstructorClass(long k) {
130: this (new TestConstructorClass());
131: }
132: }
133:
134: }
|