1 24 25 package org.objectweb.perseus.concurrency.distributed.globallock; 26 27 28 import junit.framework.TestCase; 29 import org.objectweb.perseus.concurrency.lib.RWLockValue; 30 import org.objectweb.perseus.concurrency.distributed.globallock.api.GlobalLockManager; 31 import org.objectweb.perseus.concurrency.distributed.globallock.lib.GlobalLockCoordinatorFactory; 32 import org.objectweb.perseus.concurrency.distributed.globallock.lib.BasicGlobalLockManager; 33 import org.objectweb.perseus.distribution.api.DistResControllerService; 34 import org.objectweb.perseus.distribution.api.DistResServiceManager; 35 import org.objectweb.perseus.distribution.api.DistResUserService; 36 import org.objectweb.perseus.distribution.jgroups.JGroupsServiceManager; 37 import org.objectweb.perseus.distribution.lib.BasicSerializer; 38 import org.objectweb.perseus.concurrency.distributed.util.RelativeTime; 39 import org.objectweb.perseus.concurrency.distributed.util.CoordInterceptorFactory; 40 import org.objectweb.perseus.concurrency.distributed.util.ServiceManagerInterceptor; 41 import org.objectweb.perseus.concurrency.distributed.util.MessageObserver; 42 import org.objectweb.perseus.concurrency.distributed.util.MessageEventListenerRegistry; 43 import org.objectweb.perseus.concurrency.distributed.util.action.Action; 44 import org.objectweb.perseus.concurrency.distributed.util.action.MoveCoord; 45 import org.objectweb.perseus.concurrency.distributed.util.action.RunnableActions; 46 import org.objectweb.perseus.concurrency.distributed.util.action.ThrownException; 47 import org.objectweb.perseus.concurrency.distributed.util.action.AbstractBlockingAction; 48 import org.objectweb.perseus.concurrency.distributed.util.event.EventManager; 49 import org.jgroups.log.Trace; 50 51 import java.util.LinkedList ; 52 import java.util.List ; 53 import java.util.Random ; 54 55 56 public class TestGlobalLock extends TestCase { 57 58 static final byte nbNodes = 4; 60 static final long standardRunTime = 0; static final long deadlockTimeout = 0; static final int nbIterations = 10; 71 72 GlobalLockInterceptor[] h = new GlobalLockInterceptor[nbNodes]; 73 GlobalLockManagerInterceptor[] glm = new GlobalLockManagerInterceptor[nbNodes]; 74 String r1 = "r1"; 75 EventManager em; 76 MessageObserver msgObs; 77 MessageEventListenerRegistry reg; 78 ThrownException te; 79 Object [] node = new Object [nbNodes]; 80 81 DistResUserService[] drus = new DistResUserService[nbNodes]; 82 DistResServiceManager drsm; 83 CoordInterceptorFactory glcf; 84 85 static final long moveCoordPeriod = 0; 88 static final int moveCoordPrintPeriod = 1; 89 boolean stopMoveCoord = false; 90 Object moveCoordMutex = new Object (); 91 Thread moveCoordThread; 92 93 List performers; 94 95 96 static final byte P = AbstractBlockingAction.PARALLEL; 98 static final byte S = AbstractBlockingAction.SEQUENTIAL; 99 static final byte UG = AbstractBlockingAction.GRANTED_BYUSER; 100 static final byte CG = AbstractBlockingAction.GRANTED_BYCOORD; 101 static final byte UQ = AbstractBlockingAction.QUEUED_BYUSER; 102 static final byte CQ = AbstractBlockingAction.QUEUED_BYCOORD; 103 104 static final byte R = RWLockValue.READ; 105 static final byte W = RWLockValue.WRITE; 106 static final byte N = RWLockValue.NOLOCK; 107 static GlobalLockInterceptor GL1, GL2, GL3, GL4; 108 static Object N1, N2, N3, N4; 109 110 public TestGlobalLock(String s) throws Exception { 111 super(s); 112 } 113 114 protected void setUp() throws Exception { 115 trace("setting Up:"); 116 Trace.init(); 118 msgObs = new MessageObserver(); 119 reg = new MessageEventListenerRegistry(); 120 121 glcf = new CoordInterceptorFactory( 122 new GlobalLockCoordinatorFactory(new RWLockValue()), 123 msgObs); 124 125 drsm = new ServiceManagerInterceptor(new JGroupsServiceManager(), 126 msgObs, reg); 127 128 drsm.setSerializer(new BasicSerializer()); 129 130 for (int cpt = nbNodes -1; cpt >= 0; cpt--) { 132 trace("Creating node :" + cpt); 133 glm[cpt] = new GlobalLockManagerInterceptor(drsm, glcf, reg); 134 node[cpt] = glm[cpt].getNodeId(); 135 drus[cpt] = drsm.getUserService(node[cpt]); 136 h[cpt] = (GlobalLockInterceptor) glm[cpt].getGlobalLock(r1, true); 137 h[cpt].setName("" + (cpt +1)); 138 } 139 N1 = node[0]; N2 = node[1]; N3 = node[2]; N4 = node[3]; 140 GL1 = h[0]; GL2 = h[1]; GL3 = h[2]; GL4 = h[3]; 141 142 performers = new LinkedList (); 143 em = new EventManager(); 145 te = new ThrownException(); 146 AbstractBlockingAction.init(em, te, reg); 147 } 148 149 150 protected void cleanUp() { 151 trace("Cleaning up:"); 152 if (moveCoordPeriod != 0) { 153 trace("Stopping move coord"); 154 stopMoveCoord = true; 155 try { 156 moveCoordThread.join(4000); 157 } catch (InterruptedException e) { 158 moveCoordThread.interrupt(); 159 } 160 trace("Stopping move coord done"); 161 } 162 163 for (int cpt = 0; cpt < nbNodes; cpt++) { 165 trace("Stopping node " + cpt); 166 ((JGroupsServiceManager) 167 ((ServiceManagerInterceptor) drsm).getIntercepted()) 168 .stopLocalNode(node[cpt]); 169 } 170 for (int cpt = 0; cpt < nbNodes; cpt++) { 171 trace("Removing node " + cpt); 172 drsm.removeLocalNode(node[cpt]); 173 } 174 } 175 176 private void trace(String s) { 177 System.out.println(s); 178 } 179 private void go() throws Exception { 180 go(standardRunTime, nbIterations); 181 } 182 private void go(long maxTime, int nbIterations) throws Exception { 183 184 em.start(); 185 te.clearExceptions(); 186 187 if (moveCoordPeriod != 0) moveCoordThread = startMoveCoordThread(); 188 190 try { 191 for (int cpt = 0; cpt < nbIterations; cpt++) { 192 193 trace("TEST #" + cpt); 194 195 List threads = new LinkedList (); 196 trace("\nExpected:\n" + em.printSchedule(em.expected)); 197 198 RelativeTime.startTime(0); 199 201 for (int i=0; i < performers.size(); i++) { 202 Thread t = new Thread ((Runnable ) performers.get(i), 203 "___ THREAD " + i); 204 trace("Start :" + performers.get(i)); 205 threads.add(t); 206 t.start(); 207 } 208 209 try { 210 for (int i=0; i < threads.size(); i++) { 211 212 trace("Wait for thread " + i); 213 ((Thread ) threads.get(i)).join(maxTime); 214 215 if (te.hasExceptions()) { 216 trace("Some exceptions have been thrown: " + te); 217 throw te; 218 } 219 220 if (((Thread ) threads.get(i)).isAlive()) { 221 trace("Thread " + i + " is blocked"); 222 em.expected.resetElements(); 224 trace("\nExpected:\n" + em.printSchedule(em.expected)); 225 trace("Observed:\n" + em.printSchedule(em.observed)); 226 fail("There are blocked threads"); 227 } 228 229 } 230 231 trace("Observed:\n" + em.printSchedule(em.observed)); 232 trace("END"); 233 } catch (InterruptedException e) { 234 e.printStackTrace(); 235 } 236 msgObs.waitEmpty(); 237 em.reset(); 238 for (int n = 0; n < nbNodes; n++) 240 h[n].uncache(); 241 } 243 } finally { 244 cleanUp(); 245 } 246 } 247 248 private Thread startMoveCoordThread() { 249 Thread t = new Thread (new Runnable () { 250 public void run() { 251 DistResControllerService drcs0 = drsm.getControllerService(node[0]); 252 try { 253 int numMove = 0; 255 Random rand = new Random (); 256 stopMoveCoord = false; 257 while(true) synchronized (moveCoordMutex) { 258 if (stopMoveCoord) break; 259 int dest; 260 do { 261 dest = rand.nextInt(nbNodes); 262 } while (drcs0.getCoordinators(r1).contains(node[dest])); 263 264 DistResControllerService drcs = 265 drsm.getControllerService(node[dest]); 266 Action a = new MoveCoord(drcs, r1, em); 267 if (numMove % moveCoordPrintPeriod == 0) 268 trace("===MOVE=== (" + numMove + ")"); 269 a.perform(); 270 if (numMove % moveCoordPrintPeriod == 0) 271 trace("===MOVE DONE=== (" + numMove + ")"); 272 if (moveCoordPeriod > 0) Thread.sleep(moveCoordPeriod); 273 numMove++; 274 } 275 Thread.sleep(1000); 276 } catch (Exception e) { 277 e.printStackTrace(); 278 } 279 } 280 }, "___MoveCoord"); 281 t.start(); 282 return t; 283 } 284 285 300 301 302 public void testMultipleRBlockOneW() throws Exception { 303 trace("testMultipleRBlockOneW"); 304 305 Action UR1 = new Upgrade(GL1, CG, S, R, false); 306 Action UR2 = new Upgrade(GL2, CG, P, R, false); 307 Action UR3 = new Upgrade(GL3, CG, P, R, false); 308 Action UW4 = new Upgrade(GL4, CQ, S, W, false); Action DN1 = new Downgrade(GL1, S, N); 310 Action DN2 = new Downgrade(GL2, P, N); 311 Action DN3 = new Downgrade(GL3, S, N); 312 em.addExpectedEvent(UW4.endEvent(), true); Action DN4 = new Downgrade(GL4, S, N); 314 315 List a1 = new LinkedList (); a1.add(UR1); a1.add(DN1); 316 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 317 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 318 List a4 = new LinkedList (); a4.add(UW4); a4.add(DN4); 319 320 performers.add(new RunnableActions("GL1(t1)", a1, te)); 321 performers.add(new RunnableActions("GL2(t2)", a2, te)); 322 performers.add(new RunnableActions("GL3(t3)", a3, te)); 323 performers.add(new RunnableActions("GL4(t4)", a4, te)); 324 go(); 325 326 } 327 328 344 345 public void testOneWBlocksMultipleR_R() throws Exception { 346 trace("testOneWBlocksMultipleR_R"); 347 348 Action UW1 = new Upgrade(GL1, CG, S, W, false); 349 Action UR2 = new Upgrade(GL2, CQ, S, R, false); Action UR3 = new Upgrade(GL3, CQ, P, R, false); Action UR4 = new Upgrade(GL4, CQ, P, R, false); Action DR1 = new Downgrade(GL1, S, R); 353 em.addExpectedEvent(UR2.endEvent(), true); em.addExpectedEvent(UR3.endEvent(), true); em.addExpectedEvent(UR4.endEvent(), true); Action DN1 = new Downgrade(GL1, S, N); 357 Action DN2 = new Downgrade(GL2, P, N); 358 Action DN3 = new Downgrade(GL3, P, N); 359 Action DN4 = new Downgrade(GL4, P, N); 360 361 List a1 = new LinkedList (); a1.add(UW1); a1.add(DR1); a1.add(DN1); 362 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 363 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 364 List a4 = new LinkedList (); a4.add(UR4); a4.add(DN4); 365 366 performers.add(new RunnableActions("GL1(t1)", a1, te)); 367 performers.add(new RunnableActions("GL2(t2)", a2, te)); 368 performers.add(new RunnableActions("GL3(t3)", a3, te)); 369 performers.add(new RunnableActions("GL4(t4)", a4, te)); 370 go(); 371 372 373 } 374 390 391 public void testOneWBlocksMultipleR_N() throws Exception { 392 trace("testOneWBlocksMultipleR_N"); 393 394 Action UW1 = new Upgrade(GL1, CG, S, W, false); 395 Action UR2 = new Upgrade(GL2, CQ, S, R, false); Action UR3 = new Upgrade(GL3, CQ, P, R, false); Action UR4 = new Upgrade(GL4, CQ, P, R, false); Action DN1 = new Downgrade(GL1, S, N); 399 em.addExpectedEvent(UR2.endEvent(), true); em.addExpectedEvent(UR3.endEvent(), true); em.addExpectedEvent(UR4.endEvent(), true); Action DN2 = new Downgrade(GL2, S, N); 403 Action DN3 = new Downgrade(GL3, P, N); 404 Action DN4 = new Downgrade(GL4, P, N); 405 406 List a1 = new LinkedList (); a1.add(UW1); a1.add(DN1); 407 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 408 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 409 List a4 = new LinkedList (); a4.add(UR4); a4.add(DN4); 410 411 performers.add(new RunnableActions("GL1(t1)", a1, te)); 412 performers.add(new RunnableActions("GL2(t2)", a2, te)); 413 performers.add(new RunnableActions("GL3(t3)", a3, te)); 414 performers.add(new RunnableActions("GL4(t4)", a4, te)); 415 go(); 416 417 418 419 } 420 434 public void testOneWBlocksMultipleW() throws Exception { 435 trace("testOneWBlocksMultipleW"); 436 437 Action UW1 = new Upgrade(GL1, CG, S, W, false); 438 Action UW2 = new Upgrade(GL2, CQ, S, W, false); Action UW3 = new Upgrade(GL3, CQ, S, W, false); Action UW4 = new Upgrade(GL4, CQ, S, W, false); Action DN1 = new Downgrade(GL1, S, N); 442 em.addExpectedEvent(UW2.endEvent(), true); Action DN2 = new Downgrade(GL2, S, N); 444 em.addExpectedEvent(UW3.endEvent(), true); Action DN3 = new Downgrade(GL3, S, N); 446 em.addExpectedEvent(UW4.endEvent(), true); Action DN4 = new Downgrade(GL4, S, N); 448 449 List a1 = new LinkedList (); a1.add(UW1); a1.add(DN1); 450 List a2 = new LinkedList (); a2.add(UW2); a2.add(DN2); 451 List a3 = new LinkedList (); a3.add(UW3); a3.add(DN3); 452 List a4 = new LinkedList (); a4.add(UW4); a4.add(DN4); 453 454 performers.add(new RunnableActions("GL1(t1)", a1, te)); 455 performers.add(new RunnableActions("GL2(t2)", a2, te)); 456 performers.add(new RunnableActions("GL3(t3)", a3, te)); 457 performers.add(new RunnableActions("GL4(t4)", a4, te)); 458 go(); 459 460 461 } 462 478 public void test_FIFO_Nodes_R1W2R3R4() throws Exception { 479 trace("test_FIFO_Nodes_R1W2R3R4"); 480 481 Action UR1 = new Upgrade(GL1, CG, S, R, false); 482 Action UW2 = new Upgrade(GL2, CQ, S, W, false); Action UR3 = new Upgrade(GL3, CQ, S, R, false); Action UR4 = new Upgrade(GL4, CQ, P, R, false); Action DN1 = new Downgrade(GL1, S, N); 486 em.addExpectedEvent(UW2.endEvent(), true); Action DN2 = new Downgrade(GL2, S, N); 488 em.addExpectedEvent(UR3.endEvent(), true); em.addExpectedEvent(UR4.endEvent(), true); Action DN3 = new Downgrade(GL3, S, N); 492 Action DN4 = new Downgrade(GL4, P, N); 493 494 List a1 = new LinkedList (); a1.add(UR1); a1.add(DN1); 495 List a2 = new LinkedList (); a2.add(UW2); a2.add(DN2); 496 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 497 List a4 = new LinkedList (); a4.add(UR4); a4.add(DN4); 498 499 performers.add(new RunnableActions("GL1(t1)", a1, te)); 500 performers.add(new RunnableActions("GL2(t2)", a2, te)); 501 performers.add(new RunnableActions("GL3(t3)", a3, te)); 502 performers.add(new RunnableActions("GL4(t4)", a4, te)); 503 go(); 504 } 505 506 507 508 524 525 public void test_FIFO_Nodes_W1R2R3W4() throws Exception { 526 trace("test_FIFO_Nodes_W1R2R3W4"); 527 Action UW1 = new Upgrade(GL1, CG, S, W, false); 528 Action UR2 = new Upgrade(GL2, CQ, S, R, false); Action UR3 = new Upgrade(GL3, CQ, P, R, false); Action UW4 = new Upgrade(GL4, CQ, S, W, false); Action DN1 = new Downgrade(GL1, S, N); 532 em.addExpectedEvent(UR2.endEvent(), true); em.addExpectedEvent(UR3.endEvent(), true); Action DN2 = new Downgrade(GL2, S, N); 535 Action DN3 = new Downgrade(GL3, S, N); 536 em.addExpectedEvent(UW4.endEvent(), true); Action DN4 = new Downgrade(GL4, S, N); 538 539 List a1 = new LinkedList (); a1.add(UW1); a1.add(DN1); 540 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 541 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 542 List a4 = new LinkedList (); a4.add(UW4); a4.add(DN4); 543 544 performers.add(new RunnableActions("GL1(t1)", a1, te)); 545 performers.add(new RunnableActions("GL2(t2)", a2, te)); 546 performers.add(new RunnableActions("GL3(t3)", a3, te)); 547 performers.add(new RunnableActions("GL4(t4)", a4, te)); 548 go(); 549 } 550 551 567 568 public void test_FIFO_Nodes_W1R2R3W4_2() throws Exception { 569 trace("test_FIFO_Nodes_W1R2R3W4_2"); 570 Action UW1 = new Upgrade(GL1, CG, S, W, false); 571 Action UR2 = new Upgrade(GL2, CQ, S, R, false); Action UR3 = new Upgrade(GL3, CQ, P, R, false); Action UW4 = new Upgrade(GL4, CQ, S, W, false); Action DR1 = new Downgrade(GL1, S, R); 575 em.addExpectedEvent(UR2.endEvent(), true); em.addExpectedEvent(UR3.endEvent(), true); Action DN2 = new Downgrade(GL2, S, N); 578 Action DN3 = new Downgrade(GL3, S, N); 579 Action DN1 = new Downgrade(GL1, S, N); 580 em.addExpectedEvent(UW4.endEvent(), true); Action DN4 = new Downgrade(GL4, S, N); 582 583 List a1 = new LinkedList (); a1.add(UW1); a1.add(DR1); a1.add(DN1); 584 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 585 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 586 List a4 = new LinkedList (); a4.add(UW4); a4.add(DN4); 587 588 performers.add(new RunnableActions("GL1(t1)", a1, te)); 589 performers.add(new RunnableActions("GL2(t2)", a2, te)); 590 performers.add(new RunnableActions("GL3(t3)", a3, te)); 591 performers.add(new RunnableActions("GL4(t4)", a4, te)); 592 go(); 593 } 594 595 618 619 public void test_FIFO_Nodes_W1W2W3W4R1() throws Exception { 620 trace("test_FIFO_Nodes_W1W2W3W4R1"); 621 622 Action UW1 = new Upgrade(GL1, CG, S, W, false); 623 Action UW2 = new Upgrade(GL2, CQ, S, W, false); Action UW3 = new Upgrade(GL3, CQ, S, W, false); Action UW4 = new Upgrade(GL4, CQ, S, W, false); Action DR1 = new Downgrade(GL1, S, R); 627 Action DN1 = new Downgrade(GL1, S, N); 628 em.addExpectedEvent(UW2.endEvent(), true); Action UR1 = new Upgrade(GL1, CQ, S, R, true); Action DR2 = new Downgrade(GL2, P, R); 631 Action DN2 = new Downgrade(GL2, S, N); 632 em.addExpectedEvent(UW3.endEvent(), true); Action DR3 = new Downgrade(GL3, S, R); 634 Action DN3 = new Downgrade(GL3, S, N); 635 em.addExpectedEvent(UW4.endEvent(), true); Action DR4 = new Downgrade(GL4, S, R); 637 em.addExpectedEvent(UR1.endEvent(), true); 639 Action DN1b = new Downgrade(GL1, S, N); 640 Action DN4 = new Downgrade(GL4, P, N); 641 642 List a1 = new LinkedList (); a1.add(UW1); a1.add(DR1); a1.add(DN1); 643 a1.add(UR1); a1.add(DN1b); 644 List a2 = new LinkedList (); a2.add(UW2); a2.add(DR2); a2.add(DN2); 645 List a3 = new LinkedList (); a3.add(UW3); a2.add(DR3); a3.add(DN3); 646 List a4 = new LinkedList (); a4.add(UW4); a2.add(DR4); a4.add(DN4); 647 648 performers.add(new RunnableActions("GL1(t1)", a1, te)); 649 performers.add(new RunnableActions("GL2(t2)", a2, te)); 650 performers.add(new RunnableActions("GL3(t3)", a3, te)); 651 performers.add(new RunnableActions("GL4(t4)", a4, te)); 652 go(); 653 } 654 655 656 678 679 public void test_FIFO_Threads_R1W2R1R2() throws Exception { 680 trace("test_FIFO_Threads_R1W2R1R2"); 681 Action UR1a = new Upgrade(GL1, CG, S, R, false); 682 Action UW2a = new Upgrade(GL2, CQ, S, W, false); 683 Action UR1b = new Upgrade(GL1, CQ, S, R, true); Action UR2b = new Upgrade(GL2, UQ, S, R, false); 685 Action DR1a = new Downgrade(GL1, S, R); 686 Action DN1a = new Downgrade(GL1, S, N); 687 em.addExpectedEvent(UW2a.endEvent(), true); 688 em.addExpectedEvent(UR2b.endEvent(), true); 689 Action DR2a = new Downgrade(GL2, S, R); 690 em.addExpectedEvent(UR1b.endEvent(), true); 691 Action DN1b = new Downgrade(GL1, S, N); 692 Action DN2b = new Downgrade(GL2, P, N); 693 694 List a1 = new LinkedList (); a1.add(UR1a); a1.add(DR1a); a1.add(DN1a); 695 List a2 = new LinkedList (); a2.add(UR1b); a2.add(DN1b); 696 List a3 = new LinkedList (); a3.add(UW2a); a3.add(DR2a); 697 List a4 = new LinkedList (); a4.add(UR2b); a4.add(DN2b); 698 699 performers.add(new RunnableActions("GL1(t1)", a1, te)); 700 performers.add(new RunnableActions("GL1(t2)", a2, te)); 701 performers.add(new RunnableActions("GL2(t3)", a3, te)); 702 performers.add(new RunnableActions("GL2(t4)", a4, te)); 703 go(); 704 705 706 } 707 708 727 public void test_FIFO_Threads_W1W2R1R2() throws Exception { 728 trace("test_FIFO_Threads_W1W2R1R2"); 729 730 Action UW1a = new Upgrade(GL1, CG, S, W, false); 731 Action UW2a = new Upgrade(GL2, CQ, S, W, false); 732 Action UR1b = new Upgrade(GL1, CQ, S, R, true); Action UR2b = new Upgrade(GL2, UQ, S, R, false); 734 Action DR1a = new Downgrade(GL1, S, R); 735 Action DN1a = new Downgrade(GL1, S, N); 736 em.addExpectedEvent(UW2a.endEvent(), true); 737 em.addExpectedEvent(UR2b.endEvent(), true); 738 Action DR2a = new Downgrade(GL2, S, R); 739 em.addExpectedEvent(UR1b.endEvent(), true); 740 Action DN1b = new Downgrade(GL1, S, N); 741 Action DN2b = new Downgrade(GL2, P, N); 742 743 List a1 = new LinkedList (); a1.add(UW1a); a1.add(DR1a); a1.add(DN1a); 744 List a2 = new LinkedList (); a2.add(UR1b); a2.add(DN1b); 745 List a3 = new LinkedList (); a3.add(UW2a); a3.add(DR2a); 746 List a4 = new LinkedList (); a4.add(UR2b); a4.add(DN2b); 747 748 performers.add(new RunnableActions("GL1(t1)", a1, te)); 749 performers.add(new RunnableActions("GL1(t2)", a2, te)); 750 performers.add(new RunnableActions("GL2(t3)", a3, te)); 751 performers.add(new RunnableActions("GL2(t4)", a4, te)); 752 go(); 753 754 755 756 } 757 758 775 public void test_FIFO_Threads_R1W2W1R2() throws Exception { 776 trace("test_FIFO_Threads_R1W2W1R2"); 777 778 Action UR1a = new Upgrade(GL1, CG, S, R, false); 779 Action UW2a = new Upgrade(GL2, CQ, S, W, false); 780 Action UR1b = new Upgrade(GL1, CQ, S, R, true); Action UR2b = new Upgrade(GL2, UQ, S, R, false); 782 Action DN1a = new Downgrade(GL1, S, N); 783 em.addExpectedEvent(UW2a.endEvent(), true); 784 em.addExpectedEvent(UR2b.endEvent(), true); 785 Action DR2a = new Downgrade(GL2, S, R); 786 Action DN2b = new Downgrade(GL2, S, N); 787 em.addExpectedEvent(UR1b.endEvent(), true); 788 Action DN1b = new Downgrade(GL1, S, N); 789 790 List a1 = new LinkedList (); a1.add(UR1a); a1.add(DN1a); 791 List a2 = new LinkedList (); a2.add(UR1b); a2.add(DN1b); 792 List a3 = new LinkedList (); a3.add(UW2a); a3.add(DR2a); 793 List a4 = new LinkedList (); a4.add(UR2b); a4.add(DN2b); 794 795 performers.add(new RunnableActions("GL1(t1)", a1, te)); 796 performers.add(new RunnableActions("GL2(t2)", a2, te)); 797 performers.add(new RunnableActions("GL1(t3)", a3, te)); 798 performers.add(new RunnableActions("GL2(t4)", a4, te)); 799 go(); 800 801 802 } 803 804 821 public void test_Failure1() throws Exception { 822 trace("test_Failure1"); 823 Action UW1 = new Upgrade(GL1, CG, S, W, false); 824 Action UR2 = new Upgrade(GL2, CQ, S, R, false); 825 Action UR3 = new Upgrade(GL3, CQ, P, R, false); 826 Action KN4 = new KillNodeAndWait("KN4", drsm, N4, r1); 827 Action DN1 = new Downgrade(GL1, S, N); 828 em.addExpectedEvent(UR2.endEvent(), true); 829 em.addExpectedEvent(UR3.endEvent(), true); 830 Action DN2 = new Downgrade(GL2, S, N); 831 Action DN3 = new Downgrade(GL3, P, N); 832 833 List a1 = new LinkedList (); a1.add(UW1); a1.add(DN1); 834 List a2 = new LinkedList (); a2.add(UR2); a2.add(DN2); 835 List a3 = new LinkedList (); a3.add(UR3); a3.add(DN3); 836 List a4 = new LinkedList (); a4.add(KN4); 837 838 performers.add(new RunnableActions("GL1(t1)", a1, te)); 839 performers.add(new RunnableActions("GL2(t2)", a2, te)); 840 performers.add(new RunnableActions("GL3(t3)", a3, te)); 841 performers.add(new RunnableActions("GL4(t4)", a4, te)); 842 go(standardRunTime, 1); 843 844 } 845 846 } 847 848 849 | Popular Tags |