Search in sources :

Example 1 with ExtendedResourceRecord

use of com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord in project narayana by jbosstm.

the class ExtendedResourceUnitTest method test.

@Test
public void test() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    ArjunaTransactionImple tx = new ArjunaTransactionImple(null);
    ExtendedResourceRecord res1 = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), null, new Uid(), tx);
    ExtendedResourceRecord res2 = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), null, new Uid(), tx);
    assertTrue(res1.resourceHandle() != null);
    assertTrue(res1.value() != null);
    assertFalse(res1.propagateOnAbort());
    assertFalse(res1.propagateOnCommit());
    assertTrue(res1.order().notEquals(Uid.nullUid()));
    assertEquals(res1.typeIs(), 101);
    assertTrue(res1.order() != null);
    res1.setValue(null);
    res1.print(new PrintWriter(new ByteArrayOutputStream()));
    OutputObjectState os = new OutputObjectState();
    assertTrue(res1.save_state(os, ObjectType.ANDPERSISTENT));
    InputObjectState is = new InputObjectState(os);
    assertTrue(res1.restore_state(is, ObjectType.ANDPERSISTENT));
    assertFalse(res2.doSave());
    assertFalse(res1.shouldAdd(res2));
    assertFalse(res1.shouldAlter(res2));
    assertFalse(res1.shouldMerge(res2));
    assertFalse(res1.shouldReplace(res2));
    res1 = new ExtendedResourceRecord();
    assertTrue(res1.getRCUid().notEquals(res2.getRCUid()));
    res1.alter(res2);
    res1.merge(res2);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with ExtendedResourceRecord

use of com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord in project narayana by jbosstm.

the class ExtendedResourceUnitTest method testTopLevelCommit.

@Test
public void testTopLevelCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(res.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
    // no heuristic but we can still call method
    assertTrue(res.forgetHeuristic());
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 3 with ExtendedResourceRecord

use of com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord in project narayana by jbosstm.

the class ExtendedResourceUnitTest method testNestedCommit.

@Test
public void testNestedCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    OTSImpleManager.current().begin();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(res.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
    OTSImpleManager.current().rollback();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 4 with ExtendedResourceRecord

use of com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord in project narayana by jbosstm.

the class ExtendedResourceUnitTest method testOnePhaseCommit.

@Test
public void testOnePhaseCommit() throws Exception {
    DemoArjunaResource ares = new DemoArjunaResource();
    OTSImpleManager.current().begin();
    ArjunaTransactionImple tx = OTSImpleManager.current().getControlWrapper().getImple().getImplHandle();
    ExtendedResourceRecord res = new ExtendedResourceRecord(false, new Uid(), ares.getReference(), tx.getControlHandle().get_coordinator(), new Uid(), OTSImpleManager.current().getControlWrapper().getImple().getImplHandle());
    assertEquals(res.topLevelOnePhaseCommit(), TwoPhaseOutcome.FINISH_OK);
    OTSImpleManager.current().rollback();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) DemoArjunaResource(com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource) ArjunaTransactionImple(com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple) Test(org.junit.Test)

Example 5 with ExtendedResourceRecord

use of com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord in project narayana by jbosstm.

the class ArjunaTransactionImple method createOTSRecord.

protected final AbstractRecord createOTSRecord(boolean propagate, Resource resource, Coordinator coord, Uid recCoordUid) {
    if (jtsLogger.logger.isTraceEnabled()) {
        jtsLogger.logger.trace("ArjunaTransactionImple::createOTSRecord for " + get_uid());
    }
    /*
		 * If the resource is an ArjunaOTS.OTSAbstractRecord or an
		 * ArjunaOTS.ArjunaSubtranAwareResource then we can do better record
		 * manipulation, and proper nested actions.
		 *
		 * Based on the type of resource we create the right abstract record to
		 * handle it, rather than a single abstract record which switches
		 * protocols internally.
		 */
    ArjunaSubtranAwareResource absRec = null;
    AbstractRecord corbaRec = null;
    if (resource != null) {
        try {
            absRec = com.arjuna.ArjunaOTS.ArjunaSubtranAwareResourceHelper.narrow(resource);
            if (absRec == null)
                throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
        } catch (Exception e) {
            // can't be an ArjunaOTS.ArjunaSubtranAwareResource
            absRec = null;
        }
    }
    if (absRec == null) {
        corbaRec = new ResourceRecord(propagate, resource, coord, recCoordUid, this);
    } else {
        Uid u = null;
        OTSAbstractRecord otsRec;
        try {
            otsRec = com.arjuna.ArjunaOTS.OTSAbstractRecordHelper.narrow(absRec);
            if (otsRec == null)
                throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
        } catch (Exception e) {
            otsRec = null;
        }
        if (otsRec != null) {
            try {
                u = new Uid(otsRec.uid());
            } catch (Exception e) {
                u = null;
            }
            if (u == null) {
                jtsLogger.i18NLogger.warn_orbspecific_coordinator_uidfail("ArjunaTransactionImple.createOTSRecord");
            }
        }
        if (u == null)
            u = new Uid();
        corbaRec = new ExtendedResourceRecord(propagate, u, absRec, coord, recCoordUid, this);
        otsRec = null;
        absRec = null;
        u = null;
    }
    return corbaRec;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) ArjunaSubtranAwareResource(com.arjuna.ArjunaOTS.ArjunaSubtranAwareResource) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) OTSAbstractRecord(com.arjuna.ArjunaOTS.OTSAbstractRecord) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) BAD_PARAM(org.omg.CORBA.BAD_PARAM) ResourceRecord(com.arjuna.ats.internal.jts.resources.ResourceRecord) ExtendedResourceRecord(com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord) SystemException(org.omg.CORBA.SystemException)

Aggregations

Uid (com.arjuna.ats.arjuna.common.Uid)8 ExtendedResourceRecord (com.arjuna.ats.internal.jts.resources.ExtendedResourceRecord)8 ArjunaTransactionImple (com.arjuna.ats.internal.jts.orbspecific.coordinator.ArjunaTransactionImple)7 DemoArjunaResource (com.hp.mwtests.ts.jts.orbspecific.resources.DemoArjunaResource)7 Test (org.junit.Test)7 ArjunaSubtranAwareResource (com.arjuna.ArjunaOTS.ArjunaSubtranAwareResource)1 OTSAbstractRecord (com.arjuna.ArjunaOTS.OTSAbstractRecord)1 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)1 ResourceRecord (com.arjuna.ats.internal.jts.resources.ResourceRecord)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 BAD_PARAM (org.omg.CORBA.BAD_PARAM)1 SystemException (org.omg.CORBA.SystemException)1