@Override @Before public void setUp() throws Exception { super.setUp(); Iterator<ServerGroup> iter = groups.values().iterator(); while (iter.hasNext()) { iter.next().start(); } TxControl.enable(); }
public RecoveryXAResource() { if (xids == null) { xids = new Xid[2]; AtomicAction a = new AtomicAction(); xids[0] = new XidImple(a); String c = com.arjuna.ats.arjuna.coordinator.TxControl.getXANodeName(); String b = "2"; com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(b); xids[1] = new XidImple(new Uid()); com.arjuna.ats.arjuna.coordinator.TxControl.setXANodeName(c); } }
private static XID getXid(Uid uid, Uid branch, int formatId, Integer eisName) throws IllegalStateException { if (uid == null) { throw new IllegalStateException(); } XID xid = new XID(); xid.formatID = formatId; // gtrid is uid byte form followed by as many chars of the node name as will fit. byte[] gtridUid = uid.getBytes(); if (gtridUid.length > XID.MAXGTRIDSIZE) { throw new IllegalStateException(); // Uid is too long!!!! } String nodeName = TxControl.getXANodeName(); int nodeNameLengthToUse = nodeName.getBytes().length; xid.gtrid_length = gtridUid.length + nodeNameLengthToUse; // src, srcPos, dest, destPos, length System.arraycopy(gtridUid, 0, xid.data, 0, gtridUid.length); System.arraycopy(nodeName.getBytes(), 0, xid.data, gtridUid.length, nodeNameLengthToUse); if (branch.notEquals(Uid.nullUid())) { // bqual is uid byte form plus EIS name. byte[] bqualUid = branch.getBytes(); if (bqualUid.length > XID.MAXBQUALSIZE) { throw new IllegalStateException(); // Uid is too long!!!! } int spareBqualBytes = XID.MAXBQUALSIZE - (bqualUid.length + 4); xid.bqual_length = bqualUid.length + 4 + 4; // src, srcPos, dest, destPos, length int offset = xid.gtrid_length; System.arraycopy(bqualUid, 0, xid.data, offset, bqualUid.length); setEisName(xid, eisName); } else { /* * Note: for some dbs we seem to be able to get * away with setting the size field to the size * of the actual branch. However, for Oracle, * it appears as though it must always be 64. * (At least for zero branches.) */ xid.data[xid.gtrid_length] = (byte) 0; xid.bqual_length = 64; } return xid; }
@Override @Before public void setUp() throws Exception { super.setUp(); // Start the servers Configuration conf0 = createBasicConfig(); conf0.setJournalDirectory(getJournalDir(0, false)); conf0.setBindingsDirectory(getBindingsDir(0, false)); conf0.setSecurityEnabled(false); conf0.getAcceptorConfigurations().add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)); server0 = addServer(HornetQServers.newHornetQServer(conf0, false)); context0 = new InVMNamingContext(); jmsServer0 = new JMSServerManagerImpl(server0); jmsServer0.setContext(context0); jmsServer0.start(); Configuration conf1 = createBasicConfig(); conf1.setSecurityEnabled(false); conf1.setJournalDirectory(getJournalDir(1, false)); conf1.setBindingsDirectory(getBindingsDir(1, false)); params1 = new HashMap<String, Object>(); params1.put(TransportConstants.SERVER_ID_PROP_NAME, 1); conf1 .getAcceptorConfigurations() .add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params1)); server1 = addServer(HornetQServers.newHornetQServer(conf1, false)); context1 = new InVMNamingContext(); jmsServer1 = new JMSServerManagerImpl(server1); jmsServer1.setContext(context1); jmsServer1.start(); createQueue("sourceQueue", 0); jmsServer0.createTopic(false, "sourceTopic", "/topic/sourceTopic"); createQueue("localTargetQueue", 0); createQueue("targetQueue", 1); setUpAdministeredObjects(); TxControl.enable(); // We need a local transaction and recovery manager // We must start this after the remote servers have been created or it won't // have deleted the database and the recovery manager may attempt to recover transactions }
@Override @After public void tearDown() throws Exception { Iterator<ServerGroup> iter = groups.values().iterator(); while (iter.hasNext()) { iter.next().stop(); } TxControl.disable(true); TransactionReaper.terminate(false); super.tearDown(); }
@Override @After public void tearDown() throws Exception { checkEmpty(sourceQueue, 0); checkEmpty(localTargetQueue, 0); checkEmpty(targetQueue, 1); // Check no subscriptions left lying around checkNoSubscriptions(sourceTopic, 0); if (cff0 instanceof HornetQConnectionFactory) { ((HornetQConnectionFactory) cff0).close(); } if (cff1 instanceof HornetQConnectionFactory) { ((HornetQConnectionFactory) cff1).close(); } stopComponent(jmsServer0); stopComponent(jmsServer1); cff0 = cff1 = null; cff0xa = cff1xa = null; cf0 = cf1 = null; cf0xa = cf1xa = null; sourceQueueFactory = targetQueueFactory = localTargetQueueFactory = sourceTopicFactory = null; sourceQueue = targetQueue = localTargetQueue = null; sourceTopic = null; server0 = null; jmsServer0 = null; server1 = null; jmsServer1 = null; if (context0 != null) context0.close(); context0 = null; if (context1 != null) context1.close(); context1 = null; // Shutting down Arjuna threads TxControl.disable(true); TransactionReaper.terminate(false); super.tearDown(); }
/** * Start the transaction running. * * <p>If the transaction is already running or has terminated, then an error code will be * returned. * * @param timeout the timeout associated with the transaction. If the transaction is still active * when this timeout elapses, the system will automatically roll it back. * @return <code>ActionStatus</code> indicating outcome. */ public int begin(int timeout) { int status = super.start(); if (status == ActionStatus.RUNNING) { /* * Now do thread/action tracking. */ ThreadActionData.pushAction(this); _timeout = timeout; if (_timeout == 0) _timeout = TxControl.getDefaultTimeout(); if (_timeout > 0) TransactionReaper.transactionReaper().insert(this, _timeout); } return status; }
static { // set 5 hours timeout on transactions: enough for debug, but not too high in case of CI // problems. TxControl.setDefaultTimeout(60 * 60 * 2); }
public int topLevelPrepare() { if (jtaLogger.logger.isTraceEnabled()) { jtaLogger.logger.trace("XAResourceRecord.topLevelPrepare for " + this); } if (!_valid || (_theXAResource == null) || (_tranID == null)) { jtaLogger.i18NLogger.warn_resources_arjunacore_preparenulltx("XAResourceRecord.prepare"); removeConnection(); return TwoPhaseOutcome.PREPARE_NOTOK; } try { if (endAssociation()) { _theXAResource.end(_tranID, XAResource.TMSUCCESS); } _prepared = true; if (_theXAResource.prepare(_tranID) == XAResource.XA_RDONLY) { if (TxControl.isReadonlyOptimisation()) { // we won't be called again, so we need to tidy up now removeConnection(); } return TwoPhaseOutcome.PREPARE_READONLY; } else return TwoPhaseOutcome.PREPARE_OK; } catch (XAException e1) { jtaLogger.i18NLogger.warn_resources_arjunacore_preparefailed( XAHelper.xidToString(_tranID), _theXAResource.toString(), XAHelper.printXAErrorCode(e1), e1); /* * XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or * XAER_PROTO. */ if (_rollbackOptimization) // won't have rollback called on it removeConnection(); switch (e1.errorCode) { case XAException.XAER_RMERR: case XAException.XAER_RMFAIL: case XAException.XA_RBROLLBACK: case XAException.XA_RBEND: case XAException.XA_RBCOMMFAIL: case XAException.XA_RBDEADLOCK: case XAException.XA_RBINTEGRITY: case XAException.XA_RBOTHER: case XAException.XA_RBPROTO: case XAException.XA_RBTIMEOUT: case XAException.XAER_INVAL: case XAException.XAER_PROTO: case XAException .XAER_NOTA: // resource may have arbitrarily rolled back (shouldn't, but ...) return TwoPhaseOutcome.PREPARE_NOTOK; // will not call rollback default: return TwoPhaseOutcome .HEURISTIC_HAZARD; // we're not really sure (shouldn't get here though). } } catch (Exception e2) { jtaLogger.i18NLogger.warn_resources_arjunacore_preparefailed( XAHelper.xidToString(_tranID), _theXAResource.toString(), "-", e2); if (_rollbackOptimization) // won't have rollback called on it removeConnection(); return TwoPhaseOutcome.PREPARE_NOTOK; } }