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