JtaAfterCompletionMessage extends TXMessage { @Override protected boolean operateOnTx(TXId txId, ClusterDistributionManager dm) throws RemoteOperationException { TXManagerImpl txMgr = dm.getCache().getTXMgr(); if (logger.isDebugEnabled()) { logger.debug("JTA: Calling afterCompletion for :{}", txId); } TXCommitMessage commitMessage = txMgr.getRecentlyCompletedMessage(txId); if (commitMessage != null) { TXCommitMessage message = commitMessage == TXCommitMessage.ROLLBACK_MSG ? null : commitMessage; TXRemoteCommitReplyMessage.send(getSender(), getProcessorId(), message, getReplySender(dm)); return false; } TXStateProxy txState = txMgr.getTXState(); txState.setCommitOnBehalfOfRemoteStub(true); txState.afterCompletion(status); commitMessage = txState.getCommitMessage(); TXRemoteCommitReplyMessage.send(getSender(), getProcessorId(), commitMessage, getReplySender(dm)); txMgr.removeHostedTXState(txId); return false; } JtaAfterCompletionMessage();  JtaAfterCompletionMessage(int status, int txUniqId,
      InternalDistributedMember onBehalfOfClientMember, ReplyProcessor21 processor); @Override int getProcessorType(); static RemoteCommitResponse send(Cache cache, int txId,
      InternalDistributedMember onBehalfOfClientMember, int status, DistributedMember recipient); @Override int getDSFID(); @Override void toData(DataOutput out,
      SerializationContext context); @Override void fromData(DataInput in,
      DeserializationContext context);  }
@Test public void testAfterCompletionNotInvokedIfJTACompleted() throws Exception { InternalCache cache = mock(InternalCache.class); TXManagerImpl txMgr = mock(TXManagerImpl.class); ClusterDistributionManager distributionManager = mock(ClusterDistributionManager.class); TXId txId = mock(TXId.class); when(distributionManager.getCache()).thenReturn(cache); when(cache.getTXMgr()).thenReturn(txMgr); when(txMgr.getRecentlyCompletedMessage(txId)).thenReturn(mock(TXCommitMessage.class)); when(txMgr.getTXState()).thenReturn(mock(TXStateProxyImpl.class)); JtaAfterCompletionMessage message = new JtaAfterCompletionMessage(); JtaAfterCompletionMessage spyMessage = spy(message); when(spyMessage.getSender()).thenReturn(mock(InternalDistributedMember.class)); spyMessage.operateOnTx(txId, distributionManager); verify(txMgr, never()).getTXState(); }