Search in sources :

Example 6 with ParticipantStore

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

the class BasicActionFinalizer method activate.

/**
 * Overloaded version of activate -- sets up the store, performs read_state
 * followed by restore_state. The root of the object store to use is
 * specified in the <code>root</code> parameter.
 *
 * @return <code>true</code> if successful, <code>false</code>
 *         otherwise.
 */
public boolean activate(String root) {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("BasicAction::activate() for action-id " + get_uid());
    }
    boolean restored = false;
    // Set up store
    ParticipantStore aaStore = getStore();
    if (aaStore == null)
        return false;
    try {
        // Read object state
        InputObjectState oState = aaStore.read_committed(getSavingUid(), type());
        if (oState != null) {
            synchronized (this) {
                restored = restore_state(oState, ObjectType.ANDPERSISTENT);
            }
            oState = null;
        } else {
            tsLogger.i18NLogger.warn_coordinator_BasicAction_5(get_uid(), type());
            restored = false;
        }
        return restored;
    } catch (ObjectStoreException e) {
        tsLogger.logger.warn(e);
        return false;
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore)

Example 7 with ParticipantStore

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

the class CadaverActivationUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverActivationRecord cr = new CadaverActivationRecord(new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertFalse(cr.shouldReplace(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject())));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
}
Also used : ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord) Test(org.junit.Test)

Example 8 with ParticipantStore

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

the class CadaverRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverRecord cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.PERSISTENCE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord();
    cr.print(new PrintWriter(new ByteArrayOutputStream()));
    assertFalse(cr.shouldMerge(new DisposeRecord()));
    assertFalse(cr.shouldReplace(new DisposeRecord()));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 9 with ParticipantStore

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

the class DisposeRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    DisposeRecord cr = new DisposeRecord(store, new ExtendedObject());
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.DISPOSE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), true);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord(store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new DisposeRecord();
    assertFalse(cr.shouldAdd(new PersistenceRecord()));
    assertFalse(cr.shouldAlter(new PersistenceRecord()));
    assertFalse(cr.shouldMerge(new PersistenceRecord()));
    assertFalse(cr.shouldReplace(new PersistenceRecord()));
    assertFalse(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) Test(org.junit.Test)

Example 10 with ParticipantStore

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

the class PersistenceTest method test.

@Test
public void test() {
    boolean passed = false;
    boolean threaded = false;
    long stime = Calendar.getInstance().getTime().getTime();
    ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
    for (int i = 0; i < 1000; i++) {
        try {
            ParticipantStore store = null;
            if (!threaded)
                store = new ShadowingStore(objectStoreEnvironmentBean);
            else
                store = new CacheStore(objectStoreEnvironmentBean);
            byte[] data = new byte[10240];
            OutputObjectState state = new OutputObjectState();
            Uid u = new Uid();
            state.packBytes(data);
            if (store.write_committed(u, "/StateManager/LockManager/foo", state)) {
                passed = true;
            } else
                passed = false;
        } catch (ObjectStoreException e) {
            System.out.println(e.getMessage());
            passed = false;
        } catch (IOException ex) {
            ex.printStackTrace();
            passed = false;
        }
    }
    try {
        Thread.currentThread().sleep(1000);
    } catch (Exception ex) {
    }
    long ftime = Calendar.getInstance().getTime().getTime();
    long timeTaken = ftime - stime;
    System.out.println("time for 1000 write transactions is " + timeTaken);
    try {
        Thread.currentThread().sleep(1000);
    } catch (Exception ex) {
    }
    assertTrue(passed);
}
Also used : ObjectStoreEnvironmentBean(com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) IOException(java.io.IOException) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ShadowingStore(com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore) CacheStore(com.arjuna.ats.internal.arjuna.objectstore.CacheStore) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) Test(org.junit.Test)

Aggregations

ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)14 Test (org.junit.Test)9 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)7 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7 Uid (com.arjuna.ats.arjuna.common.Uid)6 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)4 PersistenceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)4 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)4 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)3 CacheStore (com.arjuna.ats.internal.arjuna.objectstore.CacheStore)3 PrintWriter (java.io.PrintWriter)3 SystemException (org.omg.CORBA.SystemException)3 DisposeRecord (com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 CadaverActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)1 CadaverRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)1 ShadowingStore (com.arjuna.ats.internal.arjuna.objectstore.ShadowingStore)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1