@Override
 public void remoteTransactionCommitted(GlobalTransaction gtx, boolean onePc) {
   RecoveryAwareRemoteTransaction remoteTransaction =
       (RecoveryAwareRemoteTransaction) getRemoteTransaction(gtx);
   if (remoteTransaction == null)
     throw new CacheException(
         String.format("Remote transaction for global transaction (%s) not found", gtx));
   remoteTransaction.markCompleted(true);
   super.remoteTransactionCommitted(gtx, onePc);
 }
  @BeforeMethod
  public void setUp() {
    txTable = new XaTransactionTable();
    TransactionFactory gtf = new TransactionFactory();
    globalTransaction = gtf.newGlobalTransaction(null, false);
    localTx = new LocalXaTransaction(new DummyTransaction(null), globalTransaction);
    xid = new DummyXid();
    localTx.setXid(xid);
    txTable.addLocalTransactionMapping(localTx);

    configuration = new Configuration();
    TransactionCoordinator txCoordinator = new TransactionCoordinator();
    txCoordinator.init(null, null, null, null, configuration);
    xaAdapter =
        new TransactionXaAdapter(localTx, txTable, configuration, null, null, txCoordinator);
  }
  /**
   * First moves the prepared transactions originated on the leavers into the recovery cache and
   * then cleans up the transactions that are not yet prepared.
   *
   * @param cacheTopology
   */
  @Override
  public void cleanupLeaverTransactions(CacheTopology cacheTopology) {
    // We only care about transactions originated before this topology update
    if (getMinTopologyId() >= cacheTopology.getTopologyId()) return;

    Iterator<RemoteTransaction> it = getRemoteTransactions().iterator();
    while (it.hasNext()) {
      RecoveryAwareRemoteTransaction recTx = (RecoveryAwareRemoteTransaction) it.next();
      if (recTx.getTopologyId() < cacheTopology.getTopologyId()) {
        recTx.computeOrphan(cacheTopology.getMembers());
        if (recTx.isInDoubt()) {
          recoveryManager.registerInDoubtTransaction(recTx);
          it.remove();
        }
      }
    }
    // this cleans up the transactions that are not yet prepared
    super.cleanupLeaverTransactions(cacheTopology);
  }
 @Override
 public void remoteTransactionRollback(GlobalTransaction gtx) {
   super.remoteTransactionRollback(gtx);
   recoveryManager.removeRecoveryInformation(((RecoverableTransactionIdentifier) gtx).getXid());
 }