Package com.arjuna.ats.arjuna.coordinator

Examples of com.arjuna.ats.arjuna.coordinator.TransactionReaper


    }
   
    public void testReaperForce () throws Exception
    {
        TransactionReaper.create(5000);
        TransactionReaper reaper = TransactionReaper.transactionReaper();

        // give the reaper worker time to start too

        Thread.sleep(1000);

        // create slow reapables some of which will not respond immediately
        // to cancel requests and ensure that they get cancelled
        // and that the reaper does not get wedged

        SlowReapable reapable1 = new SlowReapable(new Uid(), 2000, 0, true, true);
        SlowReapable reapable2 = new SlowReapable(new Uid(), 0, 0, true, true);
        SlowReapable reapable3 = new SlowReapable(new Uid(), 100, 2000, false, true);
        SlowReapable reapable4 = new SlowReapable(new Uid(), 1000, 1000, false, false);

        // insert reapables so they timeout at 1 second intervals then
        // check progress of cancellations and rollbacks

        assertTrue(reaper.insert(reapable1, 1));

        assertTrue(reaper.insert(reapable2, 2));

        assertTrue(reaper.insert(reapable3, 3));

        assertTrue(reaper.insert(reapable4, 4));

        // make sure they were all registered

        assertEquals(4, reaper.numberOfTransactions());
        assertEquals(4, reaper.numberOfTimeouts());

        // force a termination and don't wait for the normal timeout periods
       
        TransactionReaper.terminate(false);
       
        assertEquals(0, reaper.numberOfTransactions());
       
        assertTrue(reapable1.getCancelTried());
        assertTrue(reapable2.getCancelTried());
        assertTrue(reapable3.getCancelTried());
        assertTrue(reapable4.getCancelTried());
View Full Code Here


  public void testReaper() throws Exception {

    // test set+readback of interval
    TransactionReaper.create(100);
    TransactionReaper reaper = TransactionReaper.transactionReaper();
        // set value is ignored in default DYNAMIC mode, it uses max long instead.
        assertEquals(Long.MAX_VALUE, reaper.checkingPeriod());


    Reapable reapable = new MockReapable(new Uid());
    Reapable reapable2 = new MockReapable(new Uid());
    Reapable reapable3 = new MockReapable(new Uid());

    ReaperElement reaperElement = new ReaperElement(reapable, 30);
    ReaperElement reaperElement2 = new ReaperElement(reapable2, 20);
    ReaperElement reaperElement3 = new ReaperElement(reapable3, 10);

    // test that ordering is by timeout, regardless of insertion order
    SortedSet sortedSet = new TreeSet();
    sortedSet.add(reaperElement);
    sortedSet.add(reaperElement3);
    sortedSet.add(reaperElement2);

    assertEquals(sortedSet.first(), reaperElement3);
    assertEquals(sortedSet.last(), reaperElement);

    // test insertion of timeout=0 is a nullop
    assertTrue(reaper.insert(reapable, 0));
    assertEquals(0, reaper.numberOfTransactions());
                assertEquals(0, reaper.numberOfTimeouts());
    assertFalse(reaper.remove(reapable));

    // test that duplicate insertion fails
    assertTrue(reaper.insert(reapable, 10));
    assertFalse(reaper.insert(reapable, 10));
    assertEquals(1, reaper.numberOfTransactions());
                assertEquals(1, reaper.numberOfTimeouts());
    assertTrue(reaper.remove(reapable));
    assertEquals(0, reaper.numberOfTransactions());
                assertEquals(0, reaper.numberOfTimeouts());

    // test that timeout change fails
    assertTrue(reaper.insert(reapable, 10));
    assertFalse(reaper.insert(reapable, 20));
    assertEquals(1, reaper.numberOfTransactions());
                assertEquals(1, reaper.numberOfTimeouts());
                assertEquals(10, reaper.getTimeout(reapable));
    assertTrue(reaper.remove(reapable));
                assertEquals(0, reaper.numberOfTransactions());
                assertEquals(0, reaper.numberOfTimeouts());

    // test reaping
    reaper.insert(reapable, 1); // seconds
    reaper.insert(reapable2, 5);
                assertEquals(2, reaper.numberOfTransactions());
                assertEquals(2, reaper.numberOfTimeouts());
    reaper.check();
                assertEquals(2, reaper.numberOfTransactions());
    Thread.sleep(2*1000);
    reaper.check();
                assertEquals(1, reaper.numberOfTransactions());
                assertEquals(1, reaper.numberOfTimeouts());
    Thread.sleep(4*1000);
    reaper.check();
                assertEquals(0, reaper.numberOfTransactions());
                assertEquals(0, reaper.numberOfTimeouts());

  }
View Full Code Here

    }

    public void testReaper() throws Exception
    {
  TransactionReaper.create(500);
  TransactionReaper reaper = TransactionReaper.transactionReaper();

  // give the reaper worker time to start too

  Thread.sleep(1000);

  // create slow reapables some of which will not respond immediately
        // to cancel requests and ensure that they get cancelled
        // and that the reaper does not get wedged

  SlowReapable reapable1 = new SlowReapable(new Uid(), 2000, 0, true, true, false);
  SlowReapable reapable2 = new SlowReapable(new Uid(), 0, 0, true, true, false);
  SlowReapable reapable3 = new SlowReapable(new Uid(), 100, 2000, false, true, false);
  SlowReapable reapable4 = new SlowReapable(new Uid(), 1000, 1000, false, false, false);

  // insert reapables so they timeout at 1 second intervals then
  // check progress of cancellations and rollbacks

  assertTrue(reaper.insert(reapable1, 1));

  assertTrue(reaper.insert(reapable2, 2));

  assertTrue(reaper.insert(reapable3, 3));

  assertTrue(reaper.insert(reapable4, 4));

  // make sure they were all registered

  assertEquals(4, reaper.numberOfTransactions());
  assertEquals(4, reaper.numberOfTimeouts());

  // n.b. the reaper will not operate in dynamic mode by default
  // so we have to allow an extra checkPeriod millisecs for it
  // to detect timeouts (it may go back to sleep a few
  // milliseconds before a transaction times out). also by
View Full Code Here

   
    // add this transaction to the reaper list.
   
    if (timeout > 0)
    {
      TransactionReaper reaper = TransactionReaper.transactionReaper(true);
     
      reaper.insert(super.getControlWrapper(), timeout);
    }
  }
View Full Code Here

        /*
         * Currently we do not remove controls from the list once they
         * have terminated. We should to save time and space!
         */

        TransactionReaper reaper = TransactionReaper.transactionReaper();

        if (reaper == null)
          reaper = TransactionReaper.create();

        reaper.insert(new ControlWrapper((ControlImple) tranControl), theTimeout);
      }

      return tranControl;
    }
    catch (OutOfMemoryError e)
View Full Code Here

    else
      info.averageLifetime = (float) 0.0;

    info.numberOfHeuristics = com.arjuna.ats.arjuna.coordinator.TxStats.numberOfHeuristics();

    TransactionReaper reaper = TransactionReaper.transactionReaper();

    if (reaper == null)
      info.reaperTimeout = 0;
    else
      info.reaperTimeout = (int) reaper.checkingPeriod();

    info.defaultTimeout = TxControl.getDefaultTimeout();

    return info;
  }
View Full Code Here

          {
            TransactionInfo info = new TransactionInfo();

            info.currentDepth = ctx.getImplHandle().getHierarchy().depth();

            TransactionReaper reaper = TransactionReaper.transactionReaper();

            /*
             * If the reaper has not been created yet, then all
             * transactions so far must have 0 timeout.
             */

            if (reaper == null)
              info.timeout = 0;
            else
              info.timeout = (int) reaper.getTimeout(ctx);

            info.numberOfThreads = ctx.getImplHandle().activeThreads();

            return info;
          }
View Full Code Here

     * interposition classes we add the hierarchy to the reaper list.
     */

    if ((time_out != 0) && (parentImpl == null))
    {
      TransactionReaper reaper = TransactionReaper.transactionReaper();

      if (reaper == null)
        reaper = TransactionReaper.create();

      reaper.insert(new ServerControlWrapper((ControlImple) tranControl), time_out);
    }

    return tranControl;
  }
View Full Code Here

        /*
         * Currently we do not remove controls from the list once they
         * have terminated. We should to save time and space!
         */

        TransactionReaper reaper = TransactionReaper.transactionReaper();

        reaper.insert(new ControlWrapper((ControlImple) tranControl), theTimeout);
      }

      return tranControl;
    }
    catch (OutOfMemoryError e)
View Full Code Here

    else
      info.averageLifetime = (float) 0.0;

    info.numberOfHeuristics = (int)com.arjuna.ats.arjuna.coordinator.TxStats.getInstance().getNumberOfHeuristics();

    TransactionReaper reaper = TransactionReaper.transactionReaper();

    if (reaper.checkingPeriod() == Long.MAX_VALUE)
      info.reaperTimeout = 0;
    else
      info.reaperTimeout = (int) reaper.checkingPeriod();

    info.defaultTimeout = TxControl.getDefaultTimeout();

    return info;
  }
View Full Code Here

TOP

Related Classes of com.arjuna.ats.arjuna.coordinator.TransactionReaper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.