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);
}
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());
}
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());
}
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();
}
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();
}
Aggregations