Search in sources :

Example 1 with JDBCStore

use of com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore 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)

Aggregations

ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)1 Uid (com.arjuna.ats.arjuna.common.Uid)1 ObjectStoreAPI (com.arjuna.ats.arjuna.objectstore.ObjectStoreAPI)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 JDBCStore (com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore)1 Test (org.junit.Test)1