Search in sources :

Example 96 with InputObjectState

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

the class ObjectStoreTest method testTwoVolatileStores.

@Test
public void testTwoVolatileStores() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean1 = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean1.setLocalOSRoot("tmp");
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean2 = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean2.setLocalOSRoot("tmp2");
    objectStoreEnvironmentBean2.setVolatileStoreSupportAllObjUids(true);
    VolatileStore as1 = new VolatileStore(objectStoreEnvironmentBean1);
    VolatileStore as2 = new VolatileStore(objectStoreEnvironmentBean2);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    try {
        as1.allObjUids("", new InputObjectState());
        fail("testTwoVolatileStores: allObjUids should have failed");
    } catch (final Exception ex) {
    }
    try {
        as1.allTypes(new InputObjectState());
        fail("testTwoVolatileStores: allTypes should have failed");
    } catch (final Exception ex) {
    }
    try {
        as2.allObjUids("", new InputObjectState());
    } catch (final Exception ex) {
        fail("testTwoVolatileStores: allObjUids should have passed");
    }
    try {
        as2.allTypes(new InputObjectState());
    } catch (final Exception ex) {
        fail("testTwoVolatileStores: allTypes should have passed");
    }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) VolatileStore(com.arjuna.ats.internal.arjuna.objectstore.VolatileStore) TwoPhaseVolatileStore(com.arjuna.ats.internal.arjuna.objectstore.TwoPhaseVolatileStore) Test(org.junit.Test)

Example 97 with InputObjectState

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

the class AllObjUidsTest method test.

@Test
public void test() throws IOException, ObjectStoreException {
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/DummyAtomicAction";
    InputObjectState ios = new InputObjectState();
    recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN);
    Uid uid = UidHelper.unpackFrom(ios);
    assertEquals(Uid.nullUid(), uid);
    ios = new InputObjectState();
    recoveryStore.allObjUids(type, ios, StateStatus.OS_COMMITTED);
    uid = UidHelper.unpackFrom(ios);
    assertEquals(Uid.nullUid(), uid);
    ios = new InputObjectState();
    recoveryStore.allObjUids(type, ios, StateStatus.OS_UNCOMMITTED);
    uid = UidHelper.unpackFrom(ios);
    assertEquals(Uid.nullUid(), uid);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 98 with InputObjectState

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

the class CachedTest 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)) {
            Thread.yield();
            InputObjectState s = participantStore.read_committed(u, TYPE);
            Thread.yield();
            if (s != null) {
                if (participantStore.remove_committed(u, TYPE))
                    passed = true;
            } else
                System.err.println("No state found while trying to read " + u);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    System.err.println("Thread for " + u + " " + ((passed) ? "succeeded" : "failed"));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState)

Example 99 with InputObjectState

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

the class LogStoreRecoveryTest method test.

@Test
public void test() {
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    final int numberOfTransactions = 1000;
    final Uid[] ids = new Uid[numberOfTransactions];
    final int fakeData = 0xdeedbaaf;
    final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/LogStoreRecoveryTest";
    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();
        }
    }
    for (int i = 0; i < numberOfTransactions / 2; i++) {
        try {
            recoveryStore.remove_committed(ids[i], type);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
    /*
        try {
        */
    /*
                * Give the purger thread a chance to run and delete
                * the entries we've "removed" (really only marked as
                * being removable.)
                */
    /*
            Thread.sleep(12000);
        }
        catch (final Exception ex) {
        }
        */
    /*
           * Now get a list of entries to work on.
           */
    InputObjectState ios = new InputObjectState();
    boolean passed = true;
    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())) {
                    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 == numberOfTransactions / 2) && passed) {
                System.err.println("Would attempt recovery on " + numberOfEntries + " dead transactions.");
            } else {
                passed = false;
                System.err.println("Expected " + (numberOfTransactions / 2) + " 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) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 100 with InputObjectState

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

the class OtherObjectStoreAPIJMXTest method testHashedStore.

@Test
public void testHashedStore() throws Exception {
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    objectStoreEnvironmentBean.setLocalOSRoot("tmp");
    HashedStore as = new HashedStore(objectStoreEnvironmentBean);
    final OutputObjectState buff = new OutputObjectState();
    final String tn = "/StateManager/junit";
    createMBeans(as, as);
    for (int i = 0; i < 10; i++) {
        Uid u = new Uid();
        psProxy.write_uncommitted(u, tn, buff);
        psProxy.commit_state(u, tn);
        assertTrue(rsProxy.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
        InputObjectState ios = new InputObjectState();
        rsProxy.allObjUids("", ios);
        assertTrue(psProxy.read_uncommitted(u, tn) == null);
        rsProxy.write_committed(u, tn, buff);
        rsProxy.read_committed(u, tn);
        assertTrue(!as.remove_uncommitted(u, tn));
        rsProxy.remove_committed(u, tn);
        assertTrue(!rsProxy.hide_state(u, tn));
        assertTrue(!rsProxy.reveal_state(u, tn));
    }
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) HashedStore(com.arjuna.ats.internal.arjuna.objectstore.HashedStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) 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