@Test public void clientTransactionsToBeExpiredAndDistributedAreSentToRemoveServer() { Set<TXId> txIds = mock(Set.class); spyTxMgr.expireDisconnectedClientTransactions(txIds, true); verify(spyTxMgr, times(1)).expireClientTransactionsOnRemoteServer(eq(txIds)); }
@Test public void clientTransactionsNotToBeDistributedAreNotSentToRemoveServer() { Set<TXId> txIds = mock(Set.class); spyTxMgr.expireDisconnectedClientTransactions(txIds, false); verify(spyTxMgr, never()).expireClientTransactionsOnRemoteServer(eq(txIds)); }
/** * expire the transaction states for the given client. This uses the transactionTimeToLive setting * that is inherited from the TXManagerImpl. If that setting is non-positive we expire the states * immediately * */ private void expireTXStates(ClientProxyMembershipID proxyID) { final TXManagerImpl txMgr = (TXManagerImpl) this._cache.getCacheTransactionManager(); final Set<TXId> txIds = txMgr.getTransactionsForClient((InternalDistributedMember) proxyID.getDistributedMember()); if (this._cache.isClosed()) { return; } if (!txIds.isEmpty()) { txMgr.expireDisconnectedClientTransactions(txIds, true); } }
@Test public void clientTransactionsToBeRemovedAndDistributedAreSentToRemoveServerIfWithNoTimeout() { Set<TXId> txIds = (Set<TXId>) mock(Set.class); doReturn(0).when(spyTxMgr).getTransactionTimeToLive(); when(txIds.iterator()).thenAnswer(new Answer<Iterator<TXId>>() { @Override public Iterator<TXId> answer(InvocationOnMock invocation) throws Throwable { return Arrays.asList(txid, mock(TXId.class)).iterator(); } }); spyTxMgr.expireDisconnectedClientTransactions(txIds, true); verify(spyTxMgr, times(1)).expireClientTransactionsOnRemoteServer(eq(txIds)); }
@Test public void processMessageFromServerOfGeode170AndLaterVersionWillExpireDisconnectedClientTransactions() { when(version.compareTo(Version.GEODE_170)).thenReturn(1); message.process(dm); verify(txManager, times(1)).expireDisconnectedClientTransactions(any(), eq(false)); }
@Test public void clientTransactionsToBeExpiredIsScheduledToBeRemoved() { doReturn(1).when(spyTxMgr).getTransactionTimeToLive(); TXId txId1 = mock(TXId.class); TXId txId2 = mock(TXId.class); TXId txId3 = mock(TXId.class); tx1 = spyTxMgr.getOrSetHostedTXState(txId1, msg); tx2 = spyTxMgr.getOrSetHostedTXState(txId2, msg); Set<TXId> set = new HashSet<>(); set.add(txId1); set.add(txId2); spyTxMgr.expireDisconnectedClientTransactions(set, false); verify(spyTxMgr, times(1)).scheduleToRemoveClientTransaction(eq(txId1), eq(1100L)); verify(spyTxMgr, times(1)).scheduleToRemoveClientTransaction(eq(txId2), eq(1100L)); verify(spyTxMgr, never()).scheduleToRemoveClientTransaction(eq(txId3), eq(1100L)); }
@Override protected void process(ClusterDistributionManager dm) { InternalCache cache = dm.getCache(); InternalDistributedMember sender = getSender(); if (cache != null) { TXManagerImpl mgr = cache.getTXMgr(); if (sender.getVersionObject().compareTo(Version.GEODE_170) >= 0) { // schedule to expire disconnected client transaction. mgr.expireDisconnectedClientTransactions(this.txIds, false); } else { // check if transaction has been updated before remove it mgr.removeExpiredClientTransactions(this.txIds); } } } }
@Test public void clientTransactionsToBeExpiredAreRemovedAndNotDistributedIfWithNoTimeout() { doReturn(1).when(spyTxMgr).getTransactionTimeToLive(); TXId txId1 = mock(TXId.class); TXId txId2 = mock(TXId.class); TXId txId3 = mock(TXId.class); tx1 = spyTxMgr.getOrSetHostedTXState(txId1, msg); tx2 = spyTxMgr.getOrSetHostedTXState(txId2, msg); Set<TXId> txIds = spy(new HashSet<>()); txIds.add(txId1); doReturn(0).when(spyTxMgr).getTransactionTimeToLive(); when(txIds.iterator()).thenAnswer(new Answer<Iterator<TXId>>() { @Override public Iterator<TXId> answer(InvocationOnMock invocation) throws Throwable { return Arrays.asList(txId1, txId3).iterator(); } }); assertEquals(2, spyTxMgr.getHostedTXStates().size()); spyTxMgr.expireDisconnectedClientTransactions(txIds, false); verify(spyTxMgr, never()).expireClientTransactionsOnRemoteServer(eq(txIds)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txIds)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txId1)); verify(spyTxMgr, times(1)).removeHostedTXState(eq(txId3)); assertEquals(tx2, spyTxMgr.getHostedTXStates().get(txId2)); assertEquals(1, spyTxMgr.getHostedTXStates().size()); }