KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > ArrayTestApp


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tctest;
6
7 import com.tc.object.config.ConfigVisitor;
8 import com.tc.object.config.DSOClientConfigHelper;
9 import com.tc.object.config.TransparencyClassSpec;
10 import com.tc.simulator.app.ApplicationConfig;
11 import com.tc.simulator.listener.ListenerProvider;
12 import com.tctest.runner.AbstractTransparentApp;
13
14 import java.util.Random JavaDoc;
15
16 public class ArrayTestApp extends AbstractTransparentApp {
17
18   private String JavaDoc[] myArrayTestRoot;
19
20   public ArrayTestApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
21     super(appId, cfg, listenerProvider);
22     this.myArrayTestRoot = new String JavaDoc[] { "hee", "hoo", "haa" };
23   }
24
25   public void run() {
26     Random JavaDoc rand = new Random JavaDoc();
27     try {
28       synchronized (myArrayTestRoot) {
29         System.out.println(myArrayTestRoot[rand.nextInt(myArrayTestRoot.length)]);
30       }
31       Thread.sleep(1);
32     } catch (Exception JavaDoc e) {
33       e.printStackTrace();
34     }
35
36     arrayIndexTestCase();
37
38     testNullArrayAccess();
39   }
40
41   private void testNullArrayAccess() {
42     Object JavaDoc[] o = null;
43
44     try {
45       if (o[3] == null) { throw new AssertionError JavaDoc(); }
46     } catch (NullPointerException JavaDoc npe) {
47       // expecte
48
}
49   }
50
51   private void arrayIndexTestCase() {
52     // We had a bug where ArrayIndexOutOfBoundsException failed to release a monitor, this is the test case for it
53
try {
54       for (int i = 0; true; i++) {
55         Object JavaDoc o = myArrayTestRoot[i];
56
57         // silence warning about unread local variable
58
if (o == null) {
59           continue;
60         }
61       }
62     } catch (ArrayIndexOutOfBoundsException JavaDoc aioobe) {
63       //
64
}
65
66     try {
67       Object JavaDoc o = myArrayTestRoot[-1];
68       if (true || o == o) { throw new AssertionError JavaDoc(); }
69     } catch (ArrayIndexOutOfBoundsException JavaDoc aioobe) {
70       //
71
}
72
73   }
74
75   public void setArray(String JavaDoc[] blah) {
76     myArrayTestRoot = blah;
77   }
78
79   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
80     String JavaDoc testClass = ArrayTestApp.class.getName();
81     TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
82
83     String JavaDoc methodExpression = "* " + testClass + "*.*(..)";
84     config.addWriteAutolock(methodExpression);
85     spec.addRoot("myArrayTestRoot", "myArrayTestRoot");
86
87   }
88 }
89
Popular Tags