1 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.awt.Color ; 15 16 19 public class GetRootFirstTestApp extends AbstractTransparentApp { 20 public final int participantCount = 2; 21 private Participant participant = new Participant(); 22 private Color color; 23 private static Color staticColor; 24 25 public GetRootFirstTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 26 super(appId, cfg, listenerProvider); 27 } 28 29 public void run() { 30 System.out.println("Starting App:" + this.getApplicationId()); 31 waitForAllParticipants(); 32 synchronized (participant) { 33 if (participant.getStage() == 0) { 34 System.out.println("App:" + this.getApplicationId() + " stage:" + participant.getStage() + " color:" + color 35 + " staticColor:" + staticColor); 36 Assert.eval(color == null); 37 Assert.eval(staticColor == null); 38 color = Color.RED; 39 staticColor = Color.BLUE; 40 participant.incrementStage(); 41 } else { 42 System.out.println("App:" + this.getApplicationId() + " stage:" + participant.getStage() + " color:" + color 43 + " staticColor:" + staticColor); 44 Assert.eval(color.equals(Color.RED)); 45 Assert.eval(staticColor.equals(Color.BLUE)); 46 } 47 } 48 System.out.println("Done App:" + this.getApplicationId()); 49 } 50 51 private void waitForAllParticipants() { 52 synchronized (participant) { 53 participant.incrementCount(); 54 while (participant.getCount() < participantCount) { 55 try { 56 participant.wait(); 57 } catch (InterruptedException ie) { } 59 } 60 participant.notifyAll(); 61 } 62 } 63 64 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 65 String testClass = GetRootFirstTestApp.class.getName(); 66 TransparencyClassSpec spec = config.getOrCreateSpec(testClass); 67 68 String method = "* " + testClass + ".*(..)"; 69 config.addWriteAutolock(method); 70 71 spec.addRoot("color", "color"); 72 spec.addRoot("staticColor", "staticColor"); 73 spec.addRoot("participant", "participant"); 74 75 config.addIncludePattern(Participant.class.getName()); 76 } 77 78 private static class Participant { 79 private int count = 0; 80 private int stage = 0; 81 82 public void incrementStage() { 83 stage++; 84 } 85 86 public int getStage() { 87 return stage; 88 } 89 90 public void incrementCount() { 91 count++; 92 } 93 94 public int getCount() { 95 return count; 96 } 97 } 98 } 99
| Popular Tags
|