1 4 package com.tctest; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOClientConfigHelper; 8 import com.tc.object.config.TransparencyClassSpec; 9 import com.tc.simulator.app.ApplicationConfig; 10 import com.tc.simulator.listener.ListenerProvider; 11 import com.tc.util.Assert; 12 import com.tctest.runner.AbstractTransparentApp; 13 14 17 public class ShadowVariableTestApp extends AbstractTransparentApp { 18 private ShadowSub root; 19 20 public ShadowVariableTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 21 super(appId, cfg, listenerProvider); 22 } 23 24 public void run() { 25 26 root = new ShadowSub(); 27 synchronized (root) { 28 if (root.getBaseMyNumber() == null) { 29 root.setBaseMyNumber(new Integer (1)); 30 root.setSubMyNumber(new Integer (2)); 31 } 32 } 33 34 Assert.assertNotNull(root.getBaseMyNumber()); 35 Assert.assertNotNull(root.getSubMyNumber()); 36 37 Assert.eval(root.getBaseMyNumber().equals(new Integer (1))); 38 Assert.eval(root.getSubMyNumber().equals(new Integer (2))); 39 } 40 41 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 42 String testClass = ShadowVariableTestApp.class.getName(); 43 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 44 config.addIncludePattern(ShadowBase.class.getName()); 45 config.addIncludePattern(ShadowSub.class.getName()); 46 47 String methodExpression = "* " + testClass + "*.*(..)"; 48 config.addWriteAutolock(methodExpression); 49 spec.addRoot("root", "shadowTestRoot"); 50 } 51 52 private static class ShadowBase { 53 private Integer myNumber = null; 55 56 protected final int finalInt = 1; 57 58 public int publicInt = 10; 59 60 public int getFinalInt() { 61 return finalInt; 62 } 63 64 public void setBaseMyNumber(Integer value) { 65 this.myNumber = value; 66 } 67 68 public Integer getBaseMyNumber() { 69 return this.myNumber; 70 } 71 } 72 73 private static class ShadowSub extends ShadowBase { 74 private Integer myNumber = null; 76 77 protected final int finalInt = 2; 78 79 public int publicInt = 20; 80 81 public int getFinalInt() { 82 return finalInt; 83 } 84 85 public void setSubMyNumber(Integer value) { 86 this.myNumber = value; 87 } 88 89 public Integer getSubMyNumber() { 90 return this.myNumber; 91 } 92 93 public int getPublicInt() { 94 return publicInt; 95 } 96 97 public void setPublicInt(int i) { 98 publicInt = i; 99 super.publicInt = i; 100 } 101 } 102 103 } 104
| Popular Tags
|