Search in sources :

Example 1 with ObjectStoreIterator

use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.

the class ObjectStoreTest method testIterator.

@Test
public void testIterator() throws Exception {
    Uid u1 = new Uid();
    Uid u2 = new Uid();
    assertTrue(StoreManager.getTxLog().write_committed(u1, "foo", new OutputObjectState()));
    assertTrue(StoreManager.getTxLog().write_committed(u2, "foo", new OutputObjectState()));
    ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), "foo");
    // iteration ordering is not guaranteed.
    List<Uid> uids = new ArrayList<Uid>();
    do {
        Uid uid = iter.iterate();
        if (uid.equals(Uid.nullUid())) {
            break;
        }
        uids.add(uid);
    } while (true);
    boolean foundU1 = false;
    boolean foundU2 = false;
    StringBuffer listOfUids = new StringBuffer("u1:" + u1.stringForm() + "u2:" + u2.stringForm());
    for (Uid uid : uids) {
        if (u1.equals(uid)) {
            foundU1 = true;
        } else if (u2.equals(uid)) {
            foundU2 = true;
        }
        listOfUids.append("1:" + uid.toString());
    }
    assertTrue("U1 search " + listOfUids.toString(), foundU1);
    assertTrue("U2 search " + listOfUids.toString(), foundU2);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator) ArrayList(java.util.ArrayList) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 2 with ObjectStoreIterator

use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.

the class ObjectStoreAPIJMXTest method testIterator.

// @Test
// TODO this test only works on an initially empty store
public void testIterator() throws Exception {
    Uid u1 = new Uid();
    Uid u2 = new Uid();
    prs.write_committed(u1, "foo", new OutputObjectState());
    prs.write_committed(u2, "foo", new OutputObjectState());
    ObjectStoreIterator iter = new ObjectStoreIterator(prs, "foo");
    // iteration ordering is not guaranteed.
    Uid x = iter.iterate();
    assertTrue(x.notEquals(Uid.nullUid()));
    assertTrue(x.equals(u1) || x.equals(u2));
    Uid y = iter.iterate();
    assertTrue(y.notEquals(Uid.nullUid()));
    assertTrue(y.equals(u1) || y.equals(u2));
    assertTrue(iter.iterate().equals(Uid.nullUid()));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 3 with ObjectStoreIterator

use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.

the class LogBrowser method supportedLog.

/*
     * Is this a type/instance in the log that we support?
     */
private final boolean supportedLog(String logID) throws ObjectStoreException, IOException {
    Uid id = new Uid(logID);
    if (id.equals(Uid.nullUid()))
        return false;
    ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), TransactionTypeManager.getInstance().getTransactionType(_transactionType));
    Uid u;
    do {
        u = iter.iterate();
        if (u.equals(id))
            return true;
    } while (Uid.nullUid().notEquals(u));
    return false;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator)

Example 4 with ObjectStoreIterator

use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.

the class ObjStoreBrowser method getUids.

private Collection<Uid> getUids(String type) throws MBeanException {
    Collection<Uid> uids = new ArrayList<Uid>();
    try {
        ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), type);
        while (true) {
            Uid u = iter.iterate();
            if (u == null || Uid.nullUid().equals(u))
                break;
            uids.add(u);
        }
    } catch (ObjectStoreException | IOException e) {
        throw new MBeanException(e);
    }
    return uids;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator) MBeanException(javax.management.MBeanException) IOException(java.io.IOException)

Example 5 with ObjectStoreIterator

use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.

the class XATerminatorImpleUnitTest method testMoveToAssumedComplete.

@Test
public void testMoveToAssumedComplete() throws Exception {
    Implementations.initialise();
    Implementationsx.initialise();
    Uid uid = new Uid();
    Xid xid = XidUtils.getXid(uid, false);
    XATerminatorImple xaTerminator = new XATerminatorImple();
    TransactionImporter importer = SubordinationManager.getTransactionImporter();
    SubordinateTransaction subordinateTransaction = importer.importTransaction(xid);
    Uid subordinateTransactionUid = getImportedSubordinateTransactionUid(subordinateTransaction);
    com.hp.mwtests.ts.jta.subordinate.TestXAResource xares = new com.hp.mwtests.ts.jta.subordinate.TestXAResource();
    xares.setCommitException(new XAException(XAException.XAER_RMFAIL));
    subordinateTransaction.enlistResource(xares);
    subordinateTransaction.doPrepare();
    boolean commitFailed = subordinateTransaction.doCommit();
    Assert.assertFalse("Commit should fail as XAResource defined XAException on commit being thrown", commitFailed);
    int assumedCompletedRetryOriginalValue = jtsPropertyManager.getJTSEnvironmentBean().getCommitedTransactionRetryLimit();
    jtsPropertyManager.getJTSEnvironmentBean().setCommitedTransactionRetryLimit(1);
    try {
        SubordinateTransaction recoveredTxn = importer.recoverTransaction(subordinateTransactionUid);
        Xid xidRecovered = recoveredTxn.baseXid();
        Assert.assertEquals("recovered subordinate xid should be equal to imported one", xid, xidRecovered);
        Runnable runCommitExpectingException = () -> {
            try {
                // importing transaction
                xaTerminator.recover(XAResource.TMSTARTRSCAN);
                xaTerminator.recover(XAResource.TMENDRSCAN);
                // try to commit the imported transaction
                xaTerminator.commit(xid, false);
                Assert.fail("XAException is expected to be thrown as txn was not yet moved to assumed complete state");
            } catch (XAException expected) {
                Assert.assertTrue("Commit expect to throw exception indicating that othe commit call is expected, but error code is " + expected.errorCode, XAException.XA_RETRY == expected.errorCode || XAException.XAER_RMFAIL == expected.errorCode);
            }
        };
        // replay first
        runCommitExpectingException.run();
        // assume completed check first time
        runCommitExpectingException.run();
        // importing transaction
        xaTerminator.recover(XAResource.TMSTARTRSCAN);
        xaTerminator.recover(XAResource.TMENDRSCAN);
        // moving to assumed completed state
        xaTerminator.commit(xid, false);
    } finally {
        jtsPropertyManager.getJTSEnvironmentBean().setCommitedTransactionRetryLimit(assumedCompletedRetryOriginalValue);
    }
    try {
        importer.recoverTransaction(subordinateTransactionUid);
        Assert.fail("Transaction '" + subordinateTransaction + "' should fail to recover as it should be moved " + "to category AssumedCompleteServerTrasactions");
    } catch (IllegalArgumentException expected) {
    }
    ObjectStoreIterator objectStoreIterator = new ObjectStoreIterator(StoreManager.getRecoveryStore(), AssumedCompleteServerTransaction.typeName());
    List<Uid> assumedCompletedUids = new ArrayList<Uid>();
    Uid iteratedUid = objectStoreIterator.iterate();
    while (Uid.nullUid().notEquals(iteratedUid)) {
        assumedCompletedUids.add(iteratedUid);
        iteratedUid = objectStoreIterator.iterate();
    }
    Assert.assertTrue("the subordinate transaction has to be moved under assumed completed in object store", assumedCompletedUids.contains(subordinateTransactionUid));
}
Also used : TestXAResource(com.hp.mwtests.ts.jta.jts.TestXAResource) XAException(javax.transaction.xa.XAException) ObjectStoreIterator(com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator) ArrayList(java.util.ArrayList) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Aggregations

Uid (com.arjuna.ats.arjuna.common.Uid)6 ObjectStoreIterator (com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator)6 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)1 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)1 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)1 IOException (java.io.IOException)1 MBeanException (javax.management.MBeanException)1 XAException (javax.transaction.xa.XAException)1 Xid (javax.transaction.xa.Xid)1