@Test public void testWriteWriteDeadlock() throws Exception {
    System.out.println("testWriteWriteDeadlock constructing deadlock:");


    SimpleAction p1_write = new SimpleAction(p1, Permissions.READ_WRITE);
    SimpleAction p0_write = new SimpleAction(p0, Permissions.READ_WRITE);
    
    
 //    LockGrabber lg1Write0 = startGrabber(tid1, p0, Permissions.READ_WRITE);
//    LockGrabber lg2Write1 = startGrabber(tid2, p1, Permissions.READ_WRITE);
//
//    // allow initial write locks to acquire
//    Thread.sleep(POLL_INTERVAL);
//
//    LockGrabber lg1Write1 = startGrabber(tid1, p1, Permissions.READ_WRITE);
//    LockGrabber lg2Write0 = startGrabber(tid2, p0, Permissions.READ_WRITE);

    LockGrabber lg1 = startGrabber(tid1, new SimpleAction[] {p0_write, p1_write}); 
    LockGrabber lg2 = startGrabber(tid2, new SimpleAction[] {p1_write, p0_write}); 
    
    while (true) 
    {
      Thread.sleep(POLL_INTERVAL);

      assertFalse(lg1.acquired() && lg2.acquired());
      if (lg1.acquired() && !lg2.acquired()) break;
      if (!lg1.acquired() && lg2.acquired()) break;

      if (lg1.getError() != null) {
    	  lg1.stop();
        bp.transactionComplete(tid1);
        Thread.sleep(rand.nextInt(WAIT_INTERVAL));

        tid1 = new TransactionId();
        lg1 = startGrabber(tid1,  new SimpleAction[] {p0_write, p1_write});
      }

      if (lg2.getError() != null) {
        lg2.stop();
        bp.transactionComplete(tid2);
        Thread.sleep(rand.nextInt(WAIT_INTERVAL));

        tid2 = new TransactionId();
        lg2 = startGrabber(tid2, new SimpleAction[] {p1_write, p0_write});
      }
    }

    System.out.println("testWriteWriteDeadlock resolved deadlock");
  }