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