private void doRemoteJTA(final boolean isCommit) {
    Host host = Host.getHost(0);
    VM acc = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(acc, datastore, 0);
    VM accessor = getVMForTransactions(acc, datastore);

    datastore.invoke(new SerializableCallable<Object>() {
      @Override
      public Object call() {
        getCache().getTxManager().addListener(new TestTxListener(false));
        return null;
      }
    });
    final CustId expectedCustId = new CustId(6);
    final Customer expectedCustomer = new Customer("customer6", "address6");
    accessor.invoke(new SerializableCallable<Object>() {
      @Override
      public Object call() throws Exception {
        getCache().getTxManager().addListener(new TestTxListener(true));
        Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
        Context ctx = getCache().getJNDIContext();
        UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        assertThat(Status.STATUS_NO_TRANSACTION).isEqualTo(tx.getStatus());
        tx.begin();
        assertThat(Status.STATUS_ACTIVE).isEqualTo(tx.getStatus());
        custRegion.put(expectedCustId, expectedCustomer);
        assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId));
        return null;
      }
    });
    datastore.invoke(new SerializableCallable<Object>() {
      @Override
      public Object call() {
        Region custRegion = getCache().getRegion(CUSTOMER);
        assertThat(custRegion.get(expectedCustId)).isNull();
        return null;
      }
    });
    accessor.invoke(new SerializableCallable<Object>() {
      @Override
      public Object call() throws Exception {
        Region custRegion = getCache().getRegion(CUSTOMER);
        Context ctx = getCache().getJNDIContext();
        UserTransaction tx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        if (isCommit) {
          tx.commit();
          assertThat(expectedCustomer).isEqualTo(custRegion.get(expectedCustId));
        } else {
          tx.rollback();
          assertThat(custRegion.get(expectedCustId)).isNull();
        }
        return null;
      }
    });
    datastore.invoke(new SerializableCallable<Object>() {
      @Override
      public Object call() {
        TestTxListener l = (TestTxListener) getCache().getTXMgr().getListener();
        assertThat(l.isListenerInvoked()).isTrue();
        return null;
      }
    });
  }
@return first key found on the given member
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RemoteTransactionDUnitTest.java