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: * Ensure that we can use instances of java.lang.Object in DSO managed graphs
19: */
20: public class ShareableJavaLangObjectTestApp extends
21: AbstractTransparentApp {
22:
23: private final Map root = new HashMap();
24: private final Object objectRoot = new Object();
25:
26: public ShareableJavaLangObjectTestApp(String appId,
27: ApplicationConfig cfg, ListenerProvider listenerProvider) {
28: super (appId, cfg, listenerProvider);
29:
30: if (getParticipantCount() < 2) {
31: throw new RuntimeException(
32: "must have at least two participants");
33: }
34: }
35:
36: public static void visitL1DSOConfig(ConfigVisitor visitor,
37: DSOClientConfigHelper config) {
38: String testClass = ShareableJavaLangObjectTestApp.class
39: .getName();
40: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
41:
42: String methodExpression = "* " + testClass + "*.*(..)";
43: config.addWriteAutolock(methodExpression);
44: spec.addRoot("root", "root");
45: spec.addRoot("objectRoot", "objectRoot");
46:
47: config.addIncludePattern(ObjectHolder.class.getName());
48: }
49:
50: public void run() {
51: Object o = objectRoot;
52: Assert.assertNotNull(o);
53:
54: final Object object;
55:
56: synchronized (root) {
57: if (root.size() == 0) {
58: root.put("object", new Object());
59: }
60: object = root.get("object");
61: }
62:
63: // synchronizing on the Object instance will create a transaction in which we can write to root in
64: synchronized (object) {
65: root.put(getApplicationId(), null);
66: }
67:
68: // Also make sure a physical object with an Object reference works okay
69: synchronized (root) {
70: root.put("objectholder", new ObjectHolder());
71: }
72: }
73:
74: private static class ObjectHolder {
75: final Object heldObject = new Object();
76: }
77: }
|