01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest;
05:
06: import com.tc.object.config.ConfigVisitor;
07: import com.tc.object.config.DSOClientConfigHelper;
08: import com.tc.object.config.TransparencyClassSpec;
09: import com.tc.simulator.app.ApplicationConfig;
10: import com.tc.simulator.listener.ListenerProvider;
11: import com.tctest.runner.AbstractTransparentApp;
12:
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: /**
17: * An app that throws an exception in a lock method and makes sure things still work ok
18: */
19: public class TransparencyExceptionTestApp extends
20: AbstractTransparentApp {
21: private Map myRoot = new HashMap();
22: private boolean fail = true;
23:
24: public TransparencyExceptionTestApp(String appId,
25: ApplicationConfig cfg, ListenerProvider listenerProvider) {
26: super (appId, cfg, listenerProvider);
27: }
28:
29: public static void visitL1DSOConfig(ConfigVisitor visitor,
30: DSOClientConfigHelper config) {
31: TransparencyClassSpec spec = config
32: .getOrCreateSpec("com.tctest.TransparencyExceptionTestApp");
33: spec.addRoot("myRoot", "rootBabyRoot");
34: String methodExpression = "void com.tctest.TransparencyExceptionTestApp.test1()";
35: config.addWriteAutolock(methodExpression);
36: }
37:
38: public void run() {
39: test();
40: fail = false;
41: test();
42: }
43:
44: public void test() {
45: try {
46: test1();
47: } catch (AssertionError e) {
48: if (fail) {
49: System.out.println("SUCCESS");
50: } else {
51: throw new AssertionError("Failed !!");
52: }
53: return;
54: }
55: if (fail) {
56: throw new AssertionError("Failed !!");
57: } else {
58: System.out.println("SUCCESS");
59: }
60: }
61:
62: public void test1() {
63: synchronized (myRoot) {
64: myRoot.put(new Long(1), new Long(1));
65: if (fail)
66: throw new AssertionError("Testing one two three");
67: }
68: }
69:
70: }
|