001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest;
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.object.tx.UnlockedSharedObjectException;
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 ShareInnerOfInnerClassTestApp extends
020: AbstractTransparentApp {
021:
022: private OuterClass.InnerClass.InnieClass innieRoot = new OuterClass.InnerClass.InnieClass(
023: "mmkay");
024: private CyclicBarrier barrier;
025: private int[] count = new int[1];
026:
027: private int myId;
028:
029: public ShareInnerOfInnerClassTestApp(String appId,
030: ApplicationConfig cfg, ListenerProvider listenerProvider) {
031: super (appId, cfg, listenerProvider);
032: barrier = new CyclicBarrier(cfg.getGlobalParticipantCount());
033: }
034:
035: public void run() {
036: synchronized (innieRoot) {
037: Assert.assertEquals("mmkay", innieRoot.getString());
038: }
039:
040: try {
041: innieRoot.setString("I am smart. S.M.R.T.");
042: throw new AssertionError(
043: "Supposed to throw UnlockedSharedObjectException error");
044: } catch (UnlockedSharedObjectException e) {
045: // expected
046: }
047:
048: barrier();
049:
050: synchronized (count) {
051: myId = count[0]++;
052:
053: if (myId == 0) {
054: synchronized (innieRoot) {
055: innieRoot.setString("D'oh");
056: }
057: }
058:
059: }
060:
061: barrier();
062:
063: if (myId == 1) {
064: synchronized (innieRoot) {
065: Assert.assertEquals("D'oh", innieRoot.getString());
066: }
067: }
068:
069: }
070:
071: private void barrier() {
072: try {
073: barrier.barrier();
074: } catch (Exception e) {
075: throw new AssertionError(e);
076: }
077: }
078:
079: public static void visitL1DSOConfig(ConfigVisitor visitor,
080: DSOClientConfigHelper config) {
081: String testClass = ShareInnerOfInnerClassTestApp.class
082: .getName();
083: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
084: config.getOrCreateSpec(OuterClass.InnerClass.InnieClass.class
085: .getName());
086:
087: String methodExpression = "* " + testClass + "*.*(..)";
088: config.addWriteAutolock(methodExpression);
089: spec.addRoot("innieRoot", "innieRoot");
090: spec.addRoot("barrier", "barrier");
091: spec.addRoot("count", "count");
092:
093: new CyclicBarrierSpec().visit(visitor, config);
094: }
095:
096: private static class OuterClass {
097: private static class InnerClass {
098: private static class InnieClass {
099: String myString;
100:
101: InnieClass(String s) {
102: myString = s;
103: }
104:
105: public void setString(String s) {
106: myString = s;
107: }
108:
109: public String getString() {
110: return myString;
111: }
112: }
113: }
114: }
115: }
|