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 com.tc.object.config.ConfigLockLevel;
008: import com.tc.object.config.ConfigVisitor;
009: import com.tc.object.config.DSOClientConfigHelper;
010: import com.tc.object.config.TransparencyClassSpec;
011: import com.tc.object.tx.UnlockedSharedObjectException;
012: import com.tc.simulator.app.ApplicationConfig;
013: import com.tc.simulator.listener.ListenerProvider;
014: import com.tctest.runner.AbstractTransparentApp;
015: import com.tctest.transparency.MatchingAutolockedSubclass;
016: import com.tctest.transparency.MatchingSubclass1;
017: import com.tctest.transparency.MatchingSubclass2;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: /**
023: * @author Eugene Kuleshov
024: */
025: public class SubtypeMatchingTestApp extends AbstractTransparentApp {
026:
027: private List list = new ArrayList();
028:
029: public SubtypeMatchingTestApp(String appId, ApplicationConfig cfg,
030: ListenerProvider listenerProvider) {
031: super (appId, cfg, listenerProvider);
032: }
033:
034: public void run() {
035: testHonorTransient();
036: testAutolock();
037: }
038:
039: private void testHonorTransient() {
040: MatchingSubclass1 c1 = new MatchingSubclass1();
041: MatchingSubclass2 c2 = new MatchingSubclass2();
042: synchronized (list) {
043: list.add(c1);
044: list.add(c2);
045: }
046:
047: c1.setBoo1("boo1");
048: c1.setBoo("boo1");
049:
050: c2.setBoo("boo2");
051:
052: try {
053: c2.setFoo("foo");
054: throw new RuntimeException(
055: "Should not allow to change MatchingSubclass2.foo without lock");
056: } catch (UnlockedSharedObjectException e) {
057: //
058: }
059:
060: try {
061: c1.setFoo("foo");
062: throw new RuntimeException(
063: "Should not allow to change MatchingSubclass1.foo without lock");
064: } catch (UnlockedSharedObjectException e) {
065: //
066: }
067:
068: try {
069: c1.setFoo1("foo1");
070: throw new RuntimeException(
071: "Should not allow to change MatchingClass.foo1 without lock");
072: } catch (UnlockedSharedObjectException e) {
073: //
074: }
075: }
076:
077: private void testAutolock() {
078: MatchingAutolockedSubclass c1 = new MatchingAutolockedSubclass();
079: synchronized (list) {
080: list.add(c1);
081: }
082: c1.setMoo("moo1");
083:
084: MatchingAutolockedSubclass c2 = new MatchingAutolockedSubclass(
085: list);
086: c2.setMoo("moo2");
087: }
088:
089: public static void visitL1DSOConfig(ConfigVisitor visitor,
090: DSOClientConfigHelper config) {
091: String testClass = SubtypeMatchingTestApp.class.getName();
092: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
093: spec.addRoot("list", "list");
094:
095: config.addWriteAutolock("* " + testClass + "*.*(..)");
096:
097: config.addIncludePattern(
098: "com.tctest.transparency.MarkerInterface+", true);
099: config.addIncludePattern(
100: "com.tctest.transparency.MatchingClass+", true);
101:
102: config.addAutolock(
103: "* com.tctest.transparency.MatchingClass+.set*(..)",
104: ConfigLockLevel.WRITE);
105: config
106: .addAutolock(
107: "* com.tctest.transparency.MatchingClass+.__INIT__(..)",
108: ConfigLockLevel.WRITE);
109: // config.addAutolock("* " + MatchingAutolockedSubclass.class.getName() + ".*(..)", ConfigLockLevel.WRITE);
110: }
111:
112: }
|