KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > TransparencyExceptionTestApp


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

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.tctest.runner.AbstractTransparentApp;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
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 AbstractTransparentApp {
20   private Map JavaDoc myRoot = new HashMap JavaDoc();
21   private boolean fail = true;
22
23   public TransparencyExceptionTestApp (String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
24     super(appId, cfg, listenerProvider);
25   }
26   
27   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
28     TransparencyClassSpec spec = config.getOrCreateSpec("com.tctest.TransparencyExceptionTestApp");
29     spec.addRoot("myRoot", "rootBabyRoot");
30     String JavaDoc methodExpression = "void com.tctest.TransparencyExceptionTestApp.test1()";
31     config.addWriteAutolock(methodExpression);
32   }
33   
34   public void run() {
35     test();
36     fail = false;
37     test();
38   }
39
40   public void test() {
41     try {
42       test1();
43     } catch (AssertionError JavaDoc e) {
44       if(fail) {
45         System.out.println("SUCCESS");
46       } else {
47         throw new AssertionError JavaDoc("Failed !!");
48       }
49       return;
50     }
51     if(fail) {
52       throw new AssertionError JavaDoc("Failed !!");
53     } else {
54         System.out.println("SUCCESS");
55     }
56   }
57
58   public void test1() {
59     synchronized (myRoot) {
60       myRoot.put(new Long JavaDoc(1), new Long JavaDoc(1));
61       if(fail) throw new AssertionError JavaDoc("Testing one two three");
62     }
63   }
64
65 }
Popular Tags