@Test public void commitReleasesServerAffinityAfterCommit() { TXCommitMessage txCommitMessage = mock(TXCommitMessage.class); TXManagerImpl txManager = mock(TXManagerImpl.class); when(cache.getTxManager()).thenReturn(txManager); when(serverRegionProxy.commit(anyInt())).thenReturn(txCommitMessage); doNothing().when(cancelCriterion).checkCancelInProgress(null); doNothing().when(txManager).setTXState(null); ClientTXStateStub stub = spy(new ClientTXStateStub(cache, dm, stateProxy, target, region)); InOrder order = inOrder(serverRegionProxy, internalPool, cancelCriterion); stub.commit(); order.verify(serverRegionProxy).commit(anyInt()); order.verify(internalPool).releaseServerAffinity(); order.verify(cancelCriterion).checkCancelInProgress(null); }
@Test public void commitReleasesServerAffinity_whenCommitThrowsAnException() { TXManagerImpl txManager = mock(TXManagerImpl.class); when(cache.getTxManager()).thenReturn(txManager); when(serverRegionProxy.commit(anyInt())).thenThrow(new InternalGemFireError()); doNothing().when(cancelCriterion).checkCancelInProgress(null); doNothing().when(txManager).setTXState(null); ClientTXStateStub stub = spy(new ClientTXStateStub(cache, dm, stateProxy, target, region)); InOrder order = inOrder(serverRegionProxy, internalPool); assertThatThrownBy(() -> stub.commit()).isInstanceOf(InternalGemFireError.class); order.verify(serverRegionProxy).commit(anyInt()); order.verify(internalPool).releaseServerAffinity(); } }
@Override public void commit() throws CommitConflictException { obtainLocalLocks(); try { TXCommitMessage txcm = null; try { txcm = firstProxy.commit(proxy.getTxId().getUniqId()); } finally { this.firstProxy.getPool().releaseServerAffinity(); } afterServerCommit(txcm); } catch (TransactionDataNodeHasDepartedException e) { throw new TransactionInDoubtException(e); } finally { lockReq.releaseLocal(); } }