01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest;
06:
07: import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
08:
09: import com.tc.object.config.ConfigVisitor;
10: import com.tc.object.config.TransparencyClassSpec;
11: import com.tc.object.config.spec.CyclicBarrierSpec;
12: import com.tc.simulator.app.ApplicationConfig;
13: import com.tc.simulator.listener.ListenerProvider;
14: import com.tc.util.Assert;
15: import com.tctest.runner.AbstractErrorCatchingTransparentApp;
16:
17: import java.util.Currency;
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: public class ShareCurrencyTestApp extends
22: AbstractErrorCatchingTransparentApp {
23: private final CyclicBarrier barrier;
24: private final Map mapRoot = new HashMap();
25:
26: public ShareCurrencyTestApp(String appId, ApplicationConfig cfg,
27: ListenerProvider listenerProvider) {
28: super (appId, cfg, listenerProvider);
29: barrier = new CyclicBarrier(getParticipantCount());
30: }
31:
32: public static void visitL1DSOConfig(ConfigVisitor visitor,
33: com.tc.object.config.DSOClientConfigHelper config) {
34: String testClass = ShareCurrencyTestApp.class.getName();
35: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
36:
37: String methodExpression = "* " + testClass + "*.*(..)";
38: config.addWriteAutolock(methodExpression);
39: spec.addRoot("barrier", "barrier");
40: spec.addRoot("mapRoot", "mapRoot");
41: new CyclicBarrierSpec().visit(visitor, config);
42:
43: }
44:
45: protected void runTest() throws Throwable {
46: int index = barrier.barrier();
47:
48: if (index == 0) {
49: synchronized (mapRoot) {
50: mapRoot.put("EUR", Currency.getInstance("EUR"));
51: }
52: }
53:
54: barrier.barrier();
55:
56: synchronized (mapRoot) {
57: Currency cur = (Currency) mapRoot.get("EUR");
58:
59: Assert.assertTrue(cur == Currency.getInstance("EUR"));
60: }
61: }
62:
63: }
|