1 5 package com.tctest; 6 7 import org.apache.commons.lang.builder.EqualsBuilder; 8 import org.apache.commons.lang.builder.HashCodeBuilder; 9 import org.apache.commons.lang.builder.ToStringBuilder; 10 11 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 12 13 import com.tc.object.config.ConfigVisitor; 14 import com.tc.object.config.DSOClientConfigHelper; 15 import com.tc.object.config.TransparencyClassSpec; 16 import com.tc.object.config.spec.CyclicBarrierSpec; 17 import com.tc.simulator.app.ApplicationConfig; 18 import com.tc.simulator.listener.ListenerProvider; 19 import com.tc.util.Assert; 20 import com.tctest.runner.AbstractErrorCatchingTransparentApp; 21 22 import java.util.LinkedHashMap ; 23 import java.util.Map ; 24 25 public class NullLiteralReferencesTest extends TransparentTestBase { 26 27 private static final int NODE_COUNT = 3; 28 29 public void setUp() throws Exception { 30 super.setUp(); 31 getTransparentAppConfig().setClientCount(NODE_COUNT).setIntensity(1); 32 initializeTestRunner(); 33 } 34 35 protected Class getApplicationClass() { 36 return NullLiteralReferencesTestApp.class; 37 } 38 39 public static class NullLiteralReferencesTestApp extends AbstractErrorCatchingTransparentApp { 40 41 private final CyclicBarrier barrier; 42 private final Map root = new LinkedHashMap (); 43 44 public NullLiteralReferencesTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 45 super(appId, cfg, listenerProvider); 46 barrier = new CyclicBarrier(getParticipantCount()); 47 } 48 49 protected void runTest() throws Throwable { 50 int index = barrier.barrier(); 51 52 if (index == 0) { 53 Holder h1 = new Holder(true); 54 Holder h2 = new Holder(false); 55 56 synchronized (root) { 61 root.put("null", h2); 62 } 63 64 synchronized (root) { 65 root.put("not-null", h1); 66 } 67 68 h1.setNonNull(); 69 h2.setNull(); 70 } 71 72 barrier.barrier(); 73 74 Holder compareNull = new Holder(true); 75 Holder compareNotNull = new Holder(false); 76 77 synchronized (root) { 78 Assert.assertEquals(compareNull, root.get("null")); 79 Assert.assertEquals(compareNotNull, root.get("not-null")); 80 } 81 } 82 83 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 84 new CyclicBarrierSpec().visit(visitor, config); 85 86 String testClass; 87 TransparencyClassSpec spec; 88 String methodExpression; 89 90 testClass = Holder.class.getName(); 91 spec = config.getOrCreateSpec(testClass); 92 methodExpression = "* " + testClass + ".*(..)"; 93 config.addWriteAutolock(methodExpression); 94 95 testClass = NullLiteralReferencesTestApp.class.getName(); 96 spec = config.getOrCreateSpec(testClass); 97 methodExpression = "* " + testClass + ".*(..)"; 98 config.addWriteAutolock(methodExpression); 99 spec.addRoot("barrier", "barrier"); 100 spec.addRoot("root", "root"); 101 } 102 } 103 104 private static class Holder { 105 Holder(boolean setNull) { 106 if (setNull) { 107 setNull(); 108 } else { 109 setNonNull(); 110 } 111 } 112 113 Byte byteRef; 114 Boolean booleanRef; 115 Character characterRef; 116 Double doubleRef; 117 Float floatRef; 118 Integer integerRef; 119 Long longRef; 120 Short shortRef; 121 122 Class clazz; 123 StackTraceElement stack; 124 String str; 125 126 byte b = 1; 127 boolean z = true; 128 char c = 'e'; 129 double d = Math.PI; 130 float f = "floater".length(); 131 int i = -9; 132 long l = 2342342344324234L; 133 short s = 3; 134 135 synchronized void setNonNull() { 136 byteRef = new Byte ((byte) 1); 137 booleanRef = new Boolean (true); 138 characterRef = new Character ('q'); 139 doubleRef = new Double (3.14); 140 floatRef = new Float (2.78); 141 integerRef = new Integer (42); 142 longRef = new Long (666); 143 shortRef = new Short ((short) "steve".length()); 144 145 clazz = getClass(); 146 stack = new Throwable ().getStackTrace()[0]; 147 str = "timmy"; 148 } 149 150 synchronized void setNull() { 151 byteRef = null; 152 booleanRef = null; 153 characterRef = null; 154 doubleRef = null; 155 floatRef = null; 156 integerRef = null; 157 longRef = null; 158 shortRef = null; 159 160 clazz = null; 161 stack = null; 162 str = null; 163 } 164 165 public synchronized boolean equals(Object o) { 167 return EqualsBuilder.reflectionEquals(this, o); 168 } 169 170 public synchronized String toString() { 171 return ToStringBuilder.reflectionToString(this); 172 } 173 174 public synchronized int hashCode() { 175 return HashCodeBuilder.reflectionHashCode(this); 176 } 177 178 } 179 180 } 181
| Popular Tags
|