001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tctest;
005:
006: import com.tc.object.config.ConfigVisitor;
007: import com.tc.object.config.DSOClientConfigHelper;
008: import com.tc.object.config.TransparencyClassSpec;
009: import com.tc.simulator.app.ApplicationConfig;
010: import com.tc.simulator.listener.ListenerProvider;
011: import com.tc.util.Assert;
012: import com.tctest.runner.AbstractTransparentApp;
013:
014: import java.awt.Color;
015:
016: /**
017: * Test that an individual VM can get a root before a set method is called on it
018: */
019: public class GetRootFirstTestApp extends AbstractTransparentApp {
020: public final int participantCount = 2;
021: private Participant participant = new Participant();
022: private Color color;
023: private static Color staticColor;
024:
025: public GetRootFirstTestApp(String appId, ApplicationConfig cfg,
026: ListenerProvider listenerProvider) {
027: super (appId, cfg, listenerProvider);
028: }
029:
030: public void run() {
031: System.out.println("Starting App:" + this .getApplicationId());
032: waitForAllParticipants();
033: synchronized (participant) {
034: if (participant.getStage() == 0) {
035: System.out.println("App:" + this .getApplicationId()
036: + " stage:" + participant.getStage()
037: + " color:" + color + " staticColor:"
038: + staticColor);
039: Assert.eval(color == null);
040: Assert.eval(staticColor == null);
041: color = Color.RED;
042: staticColor = Color.BLUE;
043: participant.incrementStage();
044: } else {
045: System.out.println("App:" + this .getApplicationId()
046: + " stage:" + participant.getStage()
047: + " color:" + color + " staticColor:"
048: + staticColor);
049: Assert.eval(color.equals(Color.RED));
050: Assert.eval(staticColor.equals(Color.BLUE));
051: }
052: }
053: System.out.println("Done App:" + this .getApplicationId());
054: }
055:
056: private void waitForAllParticipants() {
057: synchronized (participant) {
058: participant.incrementCount();
059: while (participant.getCount() < participantCount) {
060: try {
061: participant.wait();
062: } catch (InterruptedException ie) { // ignore
063: }
064: }
065: participant.notifyAll();
066: }
067: }
068:
069: public static void visitL1DSOConfig(ConfigVisitor visitor,
070: DSOClientConfigHelper config) {
071: String testClass = GetRootFirstTestApp.class.getName();
072: TransparencyClassSpec spec = config.getOrCreateSpec(testClass);
073:
074: String method = "* " + testClass + ".*(..)";
075: config.addWriteAutolock(method);
076:
077: spec.addRoot("color", "color");
078: spec.addRoot("staticColor", "staticColor");
079: spec.addRoot("participant", "participant");
080:
081: config.addIncludePattern(Participant.class.getName());
082: }
083:
084: private static class Participant {
085: private int count = 0;
086: private int stage = 0;
087:
088: public void incrementStage() {
089: stage++;
090: }
091:
092: public int getStage() {
093: return stage;
094: }
095:
096: public void incrementCount() {
097: count++;
098: }
099:
100: public int getCount() {
101: return count;
102: }
103: }
104: }
|