1 4 package com.tctest; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOClientConfigHelper; 8 import com.tc.simulator.app.ApplicationConfig; 9 import com.tc.simulator.listener.ListenerProvider; 10 import com.tc.util.Assert; 11 import com.tctest.runner.AbstractTransparentApp; 12 13 import java.util.HashMap ; 14 15 public class TransparentWaitNotifyApp extends AbstractTransparentApp { 16 private static final String DONE = "done Biatch!"; 17 18 private static final int INITIAL_STAGE = 0; 19 private static final int ABOUT_TO_WAIT = 1; 20 private static final int WAIT_COMPLETE = 2; 21 22 private final HashMap sharedRoot = new HashMap (); 23 24 public TransparentWaitNotifyApp(String globalId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 25 super(globalId, cfg, listenerProvider); 26 27 if ((getIntensity() != 1) || (getParticipantCount() != 2)) { 28 throw Assert.failure("Invalid parameters"); 30 } 31 32 } 33 34 public void run() { 35 if ((new Integer (this.getApplicationId()).intValue() % 2) == 0) { 36 testWaiter(); 37 } else { 38 testNotify(); 39 } 40 notifyResult(Boolean.TRUE); 41 } 42 43 private void testNotify() { 44 moveToStage(INITIAL_STAGE); 45 moveToStageAndWait(ABOUT_TO_WAIT); 46 47 synchronized (sharedRoot) { 48 System.err.println("NOTIFY"); 49 sharedRoot.notify(); 50 } 51 52 moveToStageAndWait(WAIT_COMPLETE); 53 54 synchronized (sharedRoot) { 55 Assert.eval("key not in map", sharedRoot.containsKey(DONE)); 56 } 57 } 58 59 private void testWaiter() { 60 moveToStage(INITIAL_STAGE); 61 62 synchronized (sharedRoot) { 63 moveToStage(ABOUT_TO_WAIT); 64 65 System.err.println("WAIT"); 66 67 try { 68 sharedRoot.wait(); 69 System.err.println("NOTIFIED"); 70 } catch (InterruptedException e) { 71 throw new RuntimeException (e); 72 } 73 74 75 sharedRoot.put(DONE, null); 76 } 77 78 moveToStage(WAIT_COMPLETE); 79 } 80 81 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 82 String testClassName = TransparentWaitNotifyApp.class.getName(); 83 config.addRoot(testClassName, "sharedRoot", "sharedRootLock", true); 84 String methodExpression = "* " + testClassName + ".*(..)"; 85 System.err.println("Adding autolock for: " + methodExpression); 86 config.addWriteAutolock(methodExpression); 87 } 88 } | Popular Tags |