Search in sources :

Example 96 with AtomicAction

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

the class CheckedActionTest method testCanChangeCheckedActionFactory.

@Test
public void testCanChangeCheckedActionFactory() {
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory1Called++;
                return null;
            }
        });
        arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(false);
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory3Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 0);
    assertTrue(factory3Called == 1);
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(false);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 0);
    assertTrue(factory3Called == 2);
    arjPropertyManager.getCoordinatorEnvironmentBean().setAllowCheckedActionFactoryOverride(true);
    {
        arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactory(new CheckedActionFactory() {

            @Override
            public CheckedAction getCheckedAction(Uid txId, String actionType) {
                factory2Called++;
                return null;
            }
        });
        AtomicAction A = new AtomicAction();
        A.begin();
        A.commit();
    }
    assertTrue(factory1Called == 2);
    assertTrue(factory2Called == 1);
    assertTrue(factory3Called == 2);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) CheckedActionFactory(com.arjuna.ats.arjuna.coordinator.CheckedActionFactory) Test(org.junit.Test)

Example 97 with AtomicAction

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

the class CheckedActionTest method test.

@Test
public void test() {
    arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactoryClassName(DummyCheckedAction.class.getName());
    DummyCheckedAction.reset();
    assertFalse(DummyCheckedAction.factoryCalled());
    assertFalse(DummyCheckedAction.called());
    AtomicAction A = new AtomicAction();
    A.begin();
    A.commit();
    assertTrue(DummyCheckedAction.factoryCalled());
    assertFalse(DummyCheckedAction.called());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Test(org.junit.Test)

Example 98 with AtomicAction

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

the class CheckedActionTest method testCheckedAction.

@Test
public void testCheckedAction() {
    arjPropertyManager.getCoordinatorEnvironmentBean().setCheckedActionFactoryClassName(DummyCheckedAction.class.getName());
    DummyCheckedAction.reset();
    assertFalse(DummyCheckedAction.factoryCalled());
    assertFalse(DummyCheckedAction.called());
    AtomicAction A = new AtomicAction();
    A.begin();
    /*
         * CheckedAction only called if there are multiple
         * threads active in the transaction. Simulate this.
         */
    A.addChildThread(new Thread());
    A.commit();
    assertTrue(DummyCheckedAction.factoryCalled());
    assertTrue(DummyCheckedAction.called());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Test(org.junit.Test)

Example 99 with AtomicAction

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

the class LastResource method run.

@Test
public void run() {
    AtomicAction A = new AtomicAction();
    OnePhase opRes = new OnePhase();
    A.begin();
    A.add(new LastResourceRecord(opRes));
    A.add(new ShutdownRecord(ShutdownRecord.FAIL_IN_PREPARE));
    A.commit();
    assertEquals(OnePhase.ROLLEDBACK, opRes.status());
    A = new AtomicAction();
    opRes = new OnePhase();
    A.begin();
    A.add(new LastResourceRecord(opRes));
    A.add(new ShutdownRecord(ShutdownRecord.FAIL_IN_COMMIT));
    A.commit();
    assertEquals(OnePhase.COMMITTED, opRes.status());
    A = new AtomicAction();
    A.begin();
    A.add(new LastResourceRecord(new OnePhase()));
    assertEquals(AddOutcome.AR_DUPLICATE, A.add(new LastResourceRecord(new OnePhase())));
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) ShutdownRecord(com.hp.mwtests.ts.arjuna.resources.ShutdownRecord) LastResourceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord) OnePhase(com.hp.mwtests.ts.arjuna.resources.OnePhase) Test(org.junit.Test)

Example 100 with AtomicAction

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

the class ActivationRecordUnitTest method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    AtomicAction B = new AtomicAction();
    A.begin();
    B.begin();
    ActivationRecord cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertEquals((Integer) cr.value(), new Integer(ObjectType.ANDPERSISTENT));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    B.abort();
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new ActivationRecord();
    cr.merge(new ActivationRecord());
    cr.alter(new ActivationRecord());
    assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) 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