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 com.tc.object.config.ConfigVisitor;
007: import com.tc.object.config.DSOClientConfigHelper;
008: import com.tc.object.config.TransparencyClassSpec;
009: import com.tc.simulator.app.ApplicationConfig;
010: import com.tc.simulator.listener.ListenerProvider;
011: import com.tc.util.Assert;
012: import com.tctest.runner.AbstractTransparentApp;
013:
014: /**
015: * Test that makes sure "shadowed" variables work correctly with DSO
016: */
017: public class ShadowVariableTestApp extends AbstractTransparentApp {
018: private ShadowSub root;
019:
020: public ShadowVariableTestApp(String appId, ApplicationConfig cfg,
021: ListenerProvider listenerProvider) {
022: super (appId, cfg, listenerProvider);
023: }
024:
025: public void run() {
026:
027: root = new ShadowSub();
028: synchronized (root) {
029: if (root.getBaseMyNumber() == null) {
030: root.setBaseMyNumber(new Integer(1));
031: root.setSubMyNumber(new Integer(2));
032: }
033: }
034:
035: Assert.assertNotNull(root.getBaseMyNumber());
036: Assert.assertNotNull(root.getSubMyNumber());
037:
038: Assert.eval(root.getBaseMyNumber().equals(new Integer(1)));
039: Assert.eval(root.getSubMyNumber().equals(new Integer(2)));
040:
041: Assert.assertEquals(0, root.getPublicInt());
042: }
043:
044: public static void visitL1DSOConfig(ConfigVisitor visitor,
045: DSOClientConfigHelper config) {
046: String testClass = ShadowVariableTestApp.class.getName();
047: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
048: config.addIncludePattern(ShadowBase.class.getName());
049: config.addIncludePattern(ShadowSub.class.getName());
050:
051: String methodExpression = "* " + testClass + "*.*(..)";
052: config.addWriteAutolock(methodExpression);
053: spec.addRoot("root", "shadowTestRoot");
054: }
055:
056: private static class ShadowBase {
057: // NOTE: It is very important that the shadow fields be of the exact same type
058: private Integer myNumber = null;
059:
060: protected final int finalInt = 1;
061:
062: public int publicInt = 10;
063:
064: public int getFinalInt() {
065: return finalInt;
066: }
067:
068: public void setBaseMyNumber(Integer value) {
069: this .myNumber = value;
070: }
071:
072: public Integer getBaseMyNumber() {
073: return this .myNumber;
074: }
075:
076: public int getPublicInt() {
077: return publicInt;
078: }
079:
080: }
081:
082: private static class ShadowSub extends ShadowBase {
083: // NOTE: It is very important that the shadow fields be of the exact same type
084: private Integer myNumber = null;
085:
086: protected final int finalInt = 2;
087:
088: public int publicInt;
089:
090: public int getFinalInt() {
091: return finalInt;
092: }
093:
094: public void setSubMyNumber(Integer value) {
095: this .myNumber = value;
096: }
097:
098: public Integer getSubMyNumber() {
099: return this .myNumber;
100: }
101:
102: public int getPublicInt() {
103: return publicInt;
104: }
105:
106: public void setPublicInt(int i) {
107: publicInt = i;
108: super.publicInt = i;
109: }
110: }
111:
112: }
|