KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > ClassInMapTestApp


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.tc.util.Assert;
12 import com.tctest.runner.AbstractTransparentApp;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * This test makes sure that an instance of java/lang/Class can be used as a key in a map.
19  */

20 public class ClassInMapTestApp extends AbstractTransparentApp {
21
22   private final Map JavaDoc map = new HashMap JavaDoc();
23
24   public ClassInMapTestApp(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
25     super(appId, cfg, listenerProvider);
26     if (getParticipantCount() != 2) { throw new IllegalArgumentException JavaDoc("invalid number of participants"); }
27   }
28
29   public void run() {
30     try {
31       run0();
32     } catch (Throwable JavaDoc t) {
33       notifyError(t);
34     }
35   }
36
37   private void run0() throws Exception JavaDoc {
38     synchronized (map) {
39       if (map.isEmpty()) {
40         map.put(this.getClass(), "value");
41         map.put("key", Object JavaDoc.class);
42
43         // make sure we're actually using DSO ;-)
44
while (!map.isEmpty()) {
45           map.wait(120000);
46         }
47       } else {
48         Assert.assertEquals("value", map.get(this.getClass()));
49         Assert.assertEquals(Object JavaDoc.class, map.get("key"));
50         map.remove(this.getClass());
51         map.remove("key");
52         map.notifyAll();
53       }
54     }
55   }
56
57   public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) {
58     String JavaDoc testClass = ClassInMapTestApp.class.getName();
59     TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
60
61     String JavaDoc methodExpression = "* " + testClass + "*.*(..)";
62     config.addWriteAutolock(methodExpression);
63     spec.addRoot("map", "map");
64   }
65
66 }
67
Popular Tags