Search in sources :

Example 86 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class RecoveryRecord method nestedAbort.

/**
 * nestedAbort causes the restore_state function of the object to be invoked
 * passing it the saved ObjectState.
 */
public int nestedAbort() {
    if (tsLogger.logger.isDebugEnabled()) {
        tsLogger.logger.debug("RecoveryRecord::nestedAbort() for " + order());
    }
    /*
         * First check that we have a state. We won't have for records created
         * by crash recovery.
         */
    forgetAction(false);
    if (state != null) {
        if (state.notempty()) /* anything to restore ? */
        {
            InputObjectState oldState = new InputObjectState(state);
            int result = objectAddr.restore_state(oldState, ObjectType.RECOVERABLE) ? TwoPhaseOutcome.FINISH_OK : TwoPhaseOutcome.FINISH_ERROR;
            if (result == TwoPhaseOutcome.FINISH_ERROR) {
                tsLogger.i18NLogger.warn_RecoveryRecord_2();
            }
            return result;
        }
    }
    return TwoPhaseOutcome.FINISH_OK;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState)

Example 87 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class JDBCStoreTest method testStateMachine.

@Test
public void testStateMachine() throws SQLException, ObjectStoreException, Exception {
    ObjectStoreEnvironmentBean jdbcStoreEnvironmentBean = BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class);
    ObjectStoreAPI api = new JDBCStore(jdbcStoreEnvironmentBean);
    InputObjectState states = new InputObjectState();
    api.allObjUids("typeName", states);
    Uid unpacked = UidHelper.unpackFrom(states);
    if (unpacked.notEquals(Uid.nullUid())) {
        fail("Did not expect uids to start with");
    }
    Uid uid = new Uid();
    assertTrue(api.read_committed(uid, "typeName") == null);
    assertTrue(api.write_uncommitted(uid, "typeName", new OutputObjectState()));
    assertTrue(api.commit_state(uid, "typeName"));
    assertTrue(api.read_committed(uid, "typeName") != null);
    assertFalse(api.commit_state(uid, "typeName"));
    assertTrue(api.hide_state(uid, "typeName"));
    assertTrue(api.reveal_state(uid, "typeName"));
    byte[] buff = new byte[10496000 + 1];
    OutputObjectState outputObjectState = new OutputObjectState(new Uid(), "tName");
    outputObjectState.packBytes(buff);
    assertFalse(api.write_uncommitted(uid, "typeName", outputObjectState));
    String toTest = "Hello - this is a test";
    buff = new String(toTest).getBytes();
    outputObjectState = new OutputObjectState();
    outputObjectState.packBytes(buff);
    assertTrue(api.write_committed(uid, "typeName", outputObjectState));
    InputObjectState read_state = api.read_committed(uid, "typeName");
    assertTrue(new String(read_state.unpackBytes()).equals(toTest));
    assertTrue(read_state.type(), read_state.type().equals("typeName"));
    states = new InputObjectState();
    api.allObjUids("typeName", states);
    boolean foundUid = false;
    do {
        Uid uidFound = UidHelper.unpackFrom(states);
        if (uidFound.notEquals(Uid.nullUid())) {
            assertTrue(uidFound.equals(uid));
            foundUid = true;
        } else {
            if (!foundUid) {
                fail("Did not find the UID");
            }
            break;
        }
    } while (true);
    assertFalse(api.remove_uncommitted(uid, "typeName"));
    assertTrue(api.remove_committed(uid, "typeName"));
    assertFalse(api.remove_committed(uid, "typeName"));
    api.stop();
// }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) JDBCStore(com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore) ObjectStoreAPI(com.arjuna.ats.arjuna.objectstore.ObjectStoreAPI) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 88 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class LogStressTest method test.

@Test
public void test() {
    int threads = 10;
    int work = 100;
    arjPropertyManager.getCoordinatorEnvironmentBean().setCommitOnePhase(false);
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
    // the byteman script will manage this
    // System.setProperty(Environment.TRANSACTION_LOG_PURGE_TIME, "10000");
    StressWorker[] workers = new StressWorker[threads];
    for (int i = 0; i < threads; i++) {
        workers[i] = new StressWorker(work, i);
        workers[i].start();
    }
    for (int j = 0; j < threads; j++) {
        try {
            workers[j].join();
        } catch (final Exception ex) {
        }
    }
    InputObjectState ios = new InputObjectState();
    boolean passed = false;
    try {
        StoreManager.getRecoveryStore().allObjUids(new MyAtomicAction().type(), ios, StateStatus.OS_UNKNOWN);
        Uid tempUid = UidHelper.unpackFrom(ios);
        if (tempUid.equals(Uid.nullUid())) {
            passed = true;
        }
    } catch (final Exception ex) {
    }
    assertTrue(passed);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) LogStore(com.arjuna.ats.internal.arjuna.objectstore.LogStore) Test(org.junit.Test)

Example 89 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class WriteCachedTest method run.

public void run() {
    byte[] data = new byte[1024];
    OutputObjectState state = new OutputObjectState(new Uid(), "type");
    Uid u = new Uid();
    try {
        state.packBytes(data);
        if (participantStore.write_committed(u, TYPE, state)) {
            InputObjectState s = participantStore.read_committed(u, TYPE);
            if (s != null)
                passed = true;
            else
                System.err.println("Could not read state.");
        } else
            System.err.println("Could not write state.");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 90 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class LogStoreTest2 method test.

@Test
public void test() {
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
    // the byteman script will manage this
    // System.setProperty(Environment.TRANSACTION_LOG_PURGE_TIME, "10000");
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    final int numberOfTransactions = 1000;
    final Uid[] ids = new Uid[numberOfTransactions];
    final int fakeData = 0xdeedbaaf;
    // use unique path to prevent pollution from other tests
    final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/TestTest";
    for (int i = 0; i < numberOfTransactions; i++) {
        OutputObjectState dummyState = new OutputObjectState();
        try {
            dummyState.packInt(fakeData);
            ids[i] = new Uid();
            recoveryStore.write_committed(ids[i], type, dummyState);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
    try {
        recoveryStore.remove_committed(ids[0], type);
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    /*
        try {
        */
    /*
                * Give the purger thread a chance to run and delete
                * the entry.
                */
    /*
            Thread.sleep(12000);
        }
        catch (final Exception ex) {
        }
        */
    InputObjectState ios = new InputObjectState();
    boolean passed = false;
    try {
        if (recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN)) {
            Uid id = new Uid(Uid.nullUid());
            int numberOfEntries = 0;
            do {
                try {
                    id = UidHelper.unpackFrom(ios);
                } catch (Exception ex) {
                    id = Uid.nullUid();
                }
                if (id.notEquals(Uid.nullUid())) {
                    passed = true;
                    numberOfEntries++;
                    boolean found = false;
                    for (int i = 0; i < ids.length; i++) {
                        if (id.equals(ids[i]))
                            found = true;
                    }
                    if (passed && !found) {
                        passed = false;
                        System.err.println("Found unexpected transaction!");
                    }
                }
            } while (id.notEquals(Uid.nullUid()));
            if ((numberOfEntries == ids.length - 1) && passed) {
                if (recoveryStore.currentState(ids[0], type) != StateStatus.OS_UNKNOWN)
                    passed = false;
                else {
                    if (recoveryStore.currentState(ids[1], type) != StateStatus.OS_COMMITTED)
                        passed = false;
                }
            } else {
                passed = false;
                System.err.println("Expected " + ids.length + " and got " + numberOfEntries);
            }
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    assertTrue(passed);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) LogStore(com.arjuna.ats.internal.arjuna.objectstore.LogStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Aggregations

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4