Package com.sun.sgs.test.util

Examples of com.sun.sgs.test.util.DummyTransaction


    /** Make sure that commits don't timeout. */
    @Test
    public void testCommitNoTimeout() throws Exception {
  txn.commit();
  txn = new DummyTransaction(UsePrepareAndCommit.NO, 1000) {
      public void join(final TransactionParticipant participant) {
    super.join(new TransactionParticipant() {
        public boolean prepare(Transaction txn) throws Exception {
      return participant.prepare(txn);
        }
View Full Code Here


      flag.acquire();
      final int finalI = i;
      class MyRunnable implements Runnable {
    Exception exception2;
    public void run() {
        DummyTransaction txn2 = null;
        try {
      txn2 = createTransaction(
          UsePrepareAndCommit.ARBITRARY, 1000);
      store.getObject(txn2, id2, false);
      flag.release();
      store.getObject(txn2, id, true);
      System.err.println(finalI + " txn2: commit");
      txn2.commit();
        } catch (TransactionAbortedException e) {
      System.err.println(finalI + " txn2: " + e);
      exception2 = e;
        } catch (Exception e) {
      System.err.println(finalI + " txn2: " + e);
      exception2 = e;
      if (txn2 != null) {
          txn2.abort(new RuntimeException("abort"));
      }
        }
    }
      }
      MyRunnable myRunnable = new MyRunnable();
View Full Code Here

    /** Tests running the action in the wrong transaction. */
    void testWrongTxn(Action action) throws Exception {
  action.setUp();
  store.createObject(txn);
  DummyTransaction originalTxn = txn;
  txn = createTransaction(UsePrepareAndCommit.ARBITRARY);
  try {
      action.run();
      fail("Expected IllegalStateException");
  } catch (IllegalStateException e) {
      System.err.println(e);
  } finally {
      originalTxn.abort(new RuntimeException("abort"));
  }
    }
View Full Code Here

    }

    /** Tests running the action in a new transaction while shutting down. */
    void testShuttingDownNewTxn(final Action action) throws Exception {
  action.setUp();
  DummyTransaction originalTxn = txn;
  ShutdownAction shutdownAction = new ShutdownAction();
  shutdownAction.assertBlocked();
  final AtomicReference<Throwable> exceptionHolder =
      new AtomicReference<Throwable>();
  Thread t = new Thread() {
      public void run() {
    txn = createTransaction(UsePrepareAndCommit.ARBITRARY);
    try {
        action.run();
    } catch (Throwable t) {
        exceptionHolder.set(t);
    }
    txn.abort(new RuntimeException("abort"));
    txn = null;
      }
  };
  t.start();
  t.join(1000);
  Throwable exception = exceptionHolder.get();
  assertTrue("Expected IllegalStateException: " + exception,
       exception instanceof IllegalStateException);
  originalTxn.abort(new RuntimeException("abort"));
  assertTrue(shutdownAction.waitForDone());
  store = null;
    }
View Full Code Here

  }
    }

    /** Creates a transaction. */
    protected DummyTransaction createTransaction() {
  return initTransaction(new DummyTransaction());
    }
View Full Code Here

    /** Creates a transaction with explicit use of prepareAndCommit. */
    protected DummyTransaction createTransaction(
  UsePrepareAndCommit usePrepareAndCommit)
    {
  return initTransaction(new DummyTransaction(usePrepareAndCommit));
    }
View Full Code Here

     */
    protected DummyTransaction createTransaction(
  UsePrepareAndCommit usePrepareAndCommit, long timeout)
    {
  return initTransaction(
      new DummyTransaction(usePrepareAndCommit, timeout));
    }
View Full Code Here

  flag.acquire();
  flag2.acquire();
  class MyRunnable implements Runnable {
      Exception exception2;
      public void run() {
    DummyTransaction txn2 = null;
    try {
        txn2 = createTransaction(
      UsePrepareAndCommit.ARBITRARY, 20000);
        /* Get write lock on name-299 and notify txn */
        store.setBinding(txn2, "name-299", id2);
        flag.release();
        /* Wait for txn, then commit */
        flag2.tryAcquire(10000, TimeUnit.MILLISECONDS);
        txn2.commit();
    } catch (TransactionAbortedException e) {
        System.err.println("txn2: " + e);
        exception2 = e;
    } catch (Exception e) {
        System.err.println("txn2: " + e);
        if (txn2 != null) {
      txn2.abort(new RuntimeException("abort txn2"));
        }
    }
      }
View Full Code Here

      flag.acquire();
      final int finalI = i;
      class MyRunnable implements Runnable {
    Exception exception2;
    public void run() {
        DummyTransaction txn2 = null;
        try {
      txn2 = createTransaction(
          UsePrepareAndCommit.ARBITRARY, 1000);
      store.getObject(txn2, id2, false);
      flag.release();
      store.getObject(txn2, id, true);
      System.err.println(finalI + " txn2: commit");
      txn2.commit();
        } catch (TransactionAbortedException e) {
      System.err.println(finalI + " txn2: " + e);
      exception2 = e;
        } catch (Exception e) {
      System.err.println(finalI + " txn2: " + e);
      exception2 = e;
      if (txn2 != null) {
          txn2.abort(new RuntimeException("abort"));
      }
        }
    }
View Full Code Here

TOP

Related Classes of com.sun.sgs.test.util.DummyTransaction

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.