void scheduleToRemoveExpiredClientTransaction(TXId txId) { synchronized (this.hostedTXStates) { TXStateProxy result = hostedTXStates.get(txId); if (result != null) { if (((TXStateProxyImpl) result).isOverTransactionTimeoutLimit()) { result.close(); hostedTXStates.remove(txId); } } } }
@Test public void isOverTransactionTimeoutLimitReturnsTrueIfHavingRecentOperation() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); doReturn(0L).when(tx).getLastOperationTimeFromClient(); doReturn(1001L).when(tx).getCurrentTime(); when(txManager.getTransactionTimeToLive()).thenReturn(1); assertThat(tx.isOverTransactionTimeoutLimit()).isEqualTo(true); }
@Test public void isOverTransactionTimeoutLimitReturnsFalseIfNotHavingRecentOperation() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); doReturn(0L).when(tx).getLastOperationTimeFromClient(); doReturn(1000L).when(tx).getCurrentTime(); when(txManager.getTransactionTimeToLive()).thenReturn(1); assertThat(tx.isOverTransactionTimeoutLimit()).isEqualTo(false); }
@Test public void clientTransactionWithIdleTimeLongerThanTransactionTimeoutIsRemoved() throws Exception { when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class)); TXStateProxyImpl tx = spy((TXStateProxyImpl) txMgr.getOrSetHostedTXState(txid, msg)); doReturn(true).when(tx).isOverTransactionTimeoutLimit(); txMgr.scheduleToRemoveExpiredClientTransaction(txid); assertTrue(txMgr.isHostedTXStatesEmpty()); }