/** * Attempt to create an AbstractRecord wrapping the given XAResource. Return null if this fails, or * is diallowed by the current configuration of multiple last resource behaviour. * * @param xaRes * @param params * @param xid * @return */ private AbstractRecord createRecord(XAResource xaRes, Object[] params, Xid xid) { final AbstractRecord record; if ((xaRes instanceof LastResourceCommitOptimisation) || ((LAST_RESOURCE_OPTIMISATION_INTERFACE != null) && LAST_RESOURCE_OPTIMISATION_INTERFACE .isInstance(xaRes))) { record = new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params)); } else { record = new XAResourceRecord(this, xaRes, xid, params); } return record; }
/** * Attempt to create an AbstractRecord wrapping the given XAResource. Return null if this fails, or * is diallowed by the current configuration of multiple last resource behaviour. * * @param xaRes * @param params * @param xid * @return */ private AbstractRecord createRecord(XAResource xaRes, Object[] params, Xid xid) { final AbstractRecord record; if ((xaRes instanceof LastResourceCommitOptimisation) || ((LAST_RESOURCE_OPTIMISATION_INTERFACE != null) && LAST_RESOURCE_OPTIMISATION_INTERFACE .isInstance(xaRes))) { record = new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params)); } else { record = new XAResourceRecord(this, xaRes, xid, params); } return record; }
return new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params));
return new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params));
return new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params));
return new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params));
return new LastResourceRecord(new XAOnePhaseResource(xaRes, xid, params));
@Test public void testInvalid () { XAOnePhaseResource xares = new XAOnePhaseResource(); assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR); assertEquals(xares.rollback(), TwoPhaseOutcome.FINISH_ERROR); }
@Test public void testCommit () { SampleOnePhaseResource res = new SampleOnePhaseResource(); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK); assertTrue(res.onePhaseCalled()); }
@Test public void testPackUnpack () throws Exception { DummyXA res = new DummyXA(false); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); OutputObjectState os = new OutputObjectState(); xares.pack(os); InputObjectState is = new InputObjectState(os); xares.unpack(is); } }
@Test public void testCommitHeuristic () { SampleOnePhaseResource res = new SampleOnePhaseResource(SampleOnePhaseResource.ErrorType.heurcom); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK); assertTrue(res.forgetCalled()); }
@Test public void testCommitHeuristic () { SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurcom); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); assertEquals(xares.commit(), TwoPhaseOutcome.FINISH_OK); assertTrue(res.forgetCalled()); }
@Test public void testPackUnpackError () throws Exception { SampleOnePhaseResource res = new SampleOnePhaseResource(); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); OutputObjectState os = new OutputObjectState(); try { xares.pack(os); fail(); } catch (final IOException ex) { } }
@Test public void testRollbackHeuristic () { SampleOnePhaseResource res = new SampleOnePhaseResource(SampleOnePhaseResource.ErrorType.heurrb); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR); assertTrue(res.forgetCalled()); } }
@Test public void testRollbackHeuristic () { SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurrb); XidImple xid = new XidImple(new Uid()); XAOnePhaseResource xares = new XAOnePhaseResource(res, xid, null); assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR); assertTrue(res.forgetCalled()); }
@Test public void testFailure () throws Exception { SampleOnePhaseResource res = new SampleOnePhaseResource(ErrorType.heurmix); XAOnePhaseResource xares = new XAOnePhaseResource(res, new XidImple(new Uid()), null); assertEquals(xares.commit(), TwoPhaseOutcome.HEURISTIC_HAZARD); res = new SampleOnePhaseResource(ErrorType.rmerr); xares = new XAOnePhaseResource(res, new XidImple(new Uid()), null); assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR); res = new SampleOnePhaseResource(ErrorType.nota); xares = new XAOnePhaseResource(res, new XidImple(new Uid()), null); assertEquals(xares.commit(), TwoPhaseOutcome.HEURISTIC_HAZARD); res = new SampleOnePhaseResource(ErrorType.inval); xares = new XAOnePhaseResource(res, new XidImple(new Uid()), null); assertEquals(xares.commit(), TwoPhaseOutcome.HEURISTIC_HAZARD); res = new SampleOnePhaseResource(ErrorType.proto); xares = new XAOnePhaseResource(res, new XidImple(new Uid()), null); assertEquals(xares.commit(), TwoPhaseOutcome.ONE_PHASE_ERROR); }
@Test public void test () throws Exception { DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection(); Object[] obj = new Object[1]; SampleOnePhaseResource res = new SampleOnePhaseResource(); obj[XAResourceRecord.XACONNECTION] = rc; XAOnePhaseResource xares = new XAOnePhaseResource(res, new XidImple(new Uid()), obj); OutputObjectState os = new OutputObjectState(); xares.pack(os); InputObjectState is = new InputObjectState(os); xares.unpack(is); }