Search in sources :

Example 56 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class OrderedOnePhaseResourcesUnitTest method testOrderedOnePhase.

@Test
public void testOrderedOnePhase() throws Exception {
    System.setProperty("com.arjuna.ats.arjuna.common.propertiesFile", "jbossts-properties.xml");
    Uid firstToCommit = new Uid();
    Uid secondToCommit = new Uid();
    AtomicAction A = new AtomicAction();
    // These user defined records could wrap anything such as 1PC JDBC or messages
    OrderedOnePhaseAbstractRecord rec1 = new OrderedOnePhaseAbstractRecord(secondToCommit);
    OrderedOnePhaseAbstractRecord rec2 = new OrderedOnePhaseAbstractRecord(firstToCommit);
    A.begin();
    // Doesn't matter of the order
    A.add(rec1);
    A.add(rec2);
    // Do some work you could save some concept of the work in the abstract record save_state
    // rec1.sendMessage
    // rec2.doSQL
    // This is just so we can see the opportunity for failure recovery
    rec1.causeTransientFailure();
    // Commit, this would make sure the database (rec2) was committed first
    A.commit();
    // This shows recovery working, we should see Uid2 called again, if you had encoded some information in rec2 you could
    // maybe
    // retry the sending of a message or similar
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @Override
        public int getType() {
            return OrderedOnePhaseAbstractRecord.typeId();
        }

        @Override
        public Class<? extends AbstractRecord> getRecordClass() {
            return OrderedOnePhaseAbstractRecord.class;
        }
    });
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT).addModule(new AtomicActionRecoveryModule());
    RecoveryManager.manager().scan();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) OrderedOnePhaseAbstractRecord(com.hp.mwtests.ts.arjuna.abstractrecords.OrderedOnePhaseAbstractRecord) Test(org.junit.Test)

Example 57 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class TxStatsSystemErrorUnitTest method test.

@Test
public void test() throws Exception {
    final int loopCnt = 100;
    final int sysErrCnt = loopCnt / 10;
    // first loops includes a nested transaction
    final int commitCnt = loopCnt * 2 - sysErrCnt;
    final int abortCnt = 100;
    final int txnCnt = loopCnt * 2 + abortCnt + 1;
    arjPropertyManager.getCoordinatorEnvironmentBean().setEnableStatistics(true);
    ParticipantStore pstore = StoreManager.getParticipantStore();
    UnreliableTestStore store = (UnreliableTestStore) pstore;
    long startTime = System.nanoTime();
    for (int i = 0; i < loopCnt; i++) {
        if (i % 10 == 0)
            store.setWriteError(true);
        AtomicAction A = new AtomicAction();
        AtomicAction B = new AtomicAction();
        A.begin();
        B.begin();
        A.add(new SimpleAbstractRecord());
        A.add(new SimpleAbstractRecord());
        B.commit();
        A.commit();
        if (i % 10 == 0)
            store.setWriteError(false);
    }
    long avgTxnTime = (System.nanoTime() - startTime) / commitCnt;
    for (int i = 0; i < abortCnt; i++) {
        AtomicAction A = new AtomicAction();
        A.begin();
        A.abort();
    }
    AtomicAction B = new AtomicAction();
    B.begin();
    assertTrue(TxStats.enabled());
    assertEquals(abortCnt + sysErrCnt, TxStats.getInstance().getNumberOfAbortedTransactions());
    assertEquals(abortCnt, TxStats.getInstance().getNumberOfApplicationRollbacks());
    assertEquals(sysErrCnt, TxStats.getInstance().getNumberOfSystemRollbacks());
    assertEquals(commitCnt, TxStats.getInstance().getNumberOfCommittedTransactions());
    assertEquals(0, TxStats.getInstance().getNumberOfHeuristics());
    assertEquals(1, TxStats.getInstance().getNumberOfInflightTransactions());
    assertEquals(loopCnt, TxStats.getInstance().getNumberOfNestedTransactions());
    assertEquals(0, TxStats.getInstance().getNumberOfResourceRollbacks());
    assertEquals(0, TxStats.getInstance().getNumberOfTimedOutTransactions());
    assertEquals(txnCnt, TxStats.getInstance().getNumberOfTransactions());
    assertTrue(TxStats.getInstance().getAverageCommitTime() < avgTxnTime);
    PrintWriter pw = new PrintWriter(new StringWriter());
    TxStats.getInstance().printStatus(pw);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) StringWriter(java.io.StringWriter) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 58 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class SynchronizationUnitTest method test.

@Test
public void test() throws Exception {
    AtomicAction A = new AtomicAction();
    SyncRecord sr = new SyncRecord();
    A.begin();
    assertEquals(A.addSynchronization(sr), AddOutcome.AR_ADDED);
    assertEquals(A.getSynchronizations().size(), 1);
    A.commit();
    assertTrue(sr.called());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) SyncRecord(com.hp.mwtests.ts.arjuna.resources.SyncRecord) Test(org.junit.Test)

Example 59 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class SynchronizationUnitTest method testInvalid.

@Test
public void testInvalid() throws Exception {
    AtomicAction A = new AtomicAction();
    A.begin();
    assertEquals(A.addSynchronization(null), AddOutcome.AR_REJECTED);
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Test(org.junit.Test)

Example 60 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class TxStatsUnitTest method test.

@Test
public void test() throws Exception {
    arjPropertyManager.getCoordinatorEnvironmentBean().setEnableStatistics(true);
    for (int i = 0; i < 100; i++) {
        AtomicAction A = new AtomicAction();
        AtomicAction B = new AtomicAction();
        A.begin();
        B.begin();
        B.commit();
        A.commit();
    }
    for (int i = 0; i < 100; i++) {
        AtomicAction A = new AtomicAction();
        A.begin();
        A.abort();
    }
    AtomicAction B = new AtomicAction();
    B.begin();
    assertTrue(TxStats.enabled());
    assertEquals(100, TxStats.getInstance().getNumberOfAbortedTransactions());
    assertEquals(100, TxStats.getInstance().getNumberOfApplicationRollbacks());
    assertEquals(200, TxStats.getInstance().getNumberOfCommittedTransactions());
    assertEquals(0, TxStats.getInstance().getNumberOfHeuristics());
    assertEquals(1, TxStats.getInstance().getNumberOfInflightTransactions());
    assertEquals(100, TxStats.getInstance().getNumberOfNestedTransactions());
    assertEquals(0, TxStats.getInstance().getNumberOfResourceRollbacks());
    assertEquals(0, TxStats.getInstance().getNumberOfTimedOutTransactions());
    assertEquals(301, TxStats.getInstance().getNumberOfTransactions());
    PrintWriter pw = new PrintWriter(new StringWriter());
    TxStats.getInstance().printStatus(pw);
    // https://issues.jboss.org/browse/JBTM-2643
    for (int i = 0; i < 100; i++) {
        final AtomicAction D = new AtomicAction();
        D.begin();
        Thread t1 = new Thread() {

            @Override
            public void run() {
                D.cancel();
            }
        };
        Thread t2 = new Thread() {

            @Override
            public void run() {
                D.abort();
            }
        };
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
    assertEquals(200, TxStats.getInstance().getNumberOfAbortedTransactions());
    assertEquals(200, TxStats.getInstance().getNumberOfApplicationRollbacks());
    assertEquals(401, TxStats.getInstance().getNumberOfTransactions());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

AtomicAction (com.arjuna.ats.arjuna.AtomicAction)179 Test (org.junit.Test)73 Uid (com.arjuna.ats.arjuna.common.Uid)31 TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)30 AtomicObject (com.hp.mwtests.ts.txoj.common.resources.AtomicObject)18 Lock (com.arjuna.ats.txoj.Lock)17 RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7 PrintWriter (java.io.PrintWriter)7 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)5 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)5 Container (org.jboss.stm.Container)5 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)4 BasicRecord (com.hp.mwtests.ts.arjuna.resources.BasicRecord)4 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)3 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)3 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)3 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)3 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)3 EditableAtomicAction (com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction)3