001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.transparency;
006:
007: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
008:
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOClientConfigHelper;
011: import com.tc.object.config.TransparencyClassSpec;
012: import com.tc.object.config.spec.CyclicBarrierSpec;
013: import com.tc.simulator.app.ApplicationConfig;
014: import com.tc.simulator.listener.ListenerProvider;
015: import com.tc.util.Assert;
016: import com.tctest.TransparentTestBase;
017: import com.tctest.TransparentTestIface;
018: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: public class SubclassCloneTest extends TransparentTestBase {
024: private static final int NODE_COUNT = 2;
025:
026: protected Class getApplicationClass() {
027: return SubclassCloneTestApp.class;
028: }
029:
030: public void doSetUp(TransparentTestIface t) throws Exception {
031: t.getTransparentAppConfig().setClientCount(NODE_COUNT)
032: .setIntensity(1);
033: t.initializeTestRunner();
034: }
035:
036: public static class SubclassCloneTestApp extends
037: AbstractErrorCatchingTransparentApp {
038:
039: private final CyclicBarrier barrier;
040: private Map root;
041:
042: public SubclassCloneTestApp(String appId,
043: ApplicationConfig cfg, ListenerProvider listenerProvider) {
044: super (appId, cfg, listenerProvider);
045: barrier = new CyclicBarrier(getParticipantCount());
046: }
047:
048: protected void runTest() throws Throwable {
049: int index = barrier.barrier();
050:
051: if (index == 0) {
052: root = new HashMap();
053: synchronized (root) {
054: root.put("object", new Subclass());
055: }
056: }
057:
058: barrier.barrier();
059:
060: if (index != 0) {
061: Subclass sub;
062: synchronized (root) {
063: sub = (Subclass) root.get("object");
064: }
065:
066: Subclass cloned = (Subclass) sub.clone();
067: Assert.assertNotNull(cloned.getO());
068: }
069: }
070:
071: public static void visitL1DSOConfig(ConfigVisitor visitor,
072: DSOClientConfigHelper config) {
073: String testClass = SubclassCloneTestApp.class.getName();
074: TransparencyClassSpec spec = config
075: .getOrCreateSpec(testClass);
076: String methodExpression = "* " + testClass + "*.*(..)";
077: config.addWriteAutolock(methodExpression);
078: spec.addRoot("root", "root");
079: spec.addRoot("barrier", "barrier");
080:
081: new CyclicBarrierSpec().visit(visitor, config);
082:
083: config.addIncludePattern("*..*", false);
084: }
085:
086: }
087:
088: private static class Base implements Cloneable {
089: private final Object o = this ;
090:
091: public Object getO() {
092: return o;
093: }
094: }
095:
096: private static class Subclass extends Base implements Cloneable {
097:
098: public Object clone() throws CloneNotSupportedException {
099: return super.clone();
100: }
101:
102: }
103:
104: }
|