private TXStateProxy masqueradeToRollback() { TXStateProxy existingTx; try { existingTx = txMgr.masqueradeAs(rollbackMsg); } catch (InterruptedException e) { e.printStackTrace(); throw new RuntimeException(e); } return existingTx; }
private TXStateProxy prepForTransaction(ClusterDistributionManager dm) throws InterruptedException { if (this.txUniqId == TXManagerImpl.NOTX) { return null; } else { InternalCache cache = dm.getCache(); if (cache == null) { // ignore and return, we are shutting down! return null; } TXManagerImpl mgr = cache.getTXMgr(); return mgr.masqueradeAs(this); } }
private TXStateProxy prepForTransaction(ClusterDistributionManager dm) throws InterruptedException { if (this.txUniqId == TXManagerImpl.NOTX) { return null; } else { InternalCache cache = dm.getCache(); if (cache == null) { // ignore and return, we are shutting down! return null; } TXManagerImpl mgr = cache.getTXMgr(); return mgr.masqueradeAs(this); } }
@Test public void messageForNotFinishedTXPerformsOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(true); msg.process(dm); verify(msg, times(1)).operateOnPartitionedRegion(dm, pr, startTime); }
@Test public void messageWithNoTXPerformsOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(null); msg.process(dm); verify(msg, times(1)).operateOnPartitionedRegion(dm, pr, startTime); }
@Test public void messageForFinishedTXDoesNotPerformOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(false); msg.process(dm); verify(msg, times(0)).operateOnPartitionedRegion(dm, pr, startTime); }
@Test public void messageWithNoTXPerformsOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(null); msg.setSender(sender); msg.process(dm); verify(msg, times(1)).operateOnRegion(dm, r, startTime); verify(dm, times(1)).putOutgoing(any()); }
@Test public void messageForNotFinishedTXPerformsOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(true); msg.setSender(sender); msg.process(dm); verify(msg, times(1)).operateOnRegion(dm, r, startTime); verify(dm, times(1)).putOutgoing(any()); }
@Test public void messageForFinishedTXDoesNotPerformOnRegion() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(false); msg.setSender(sender); msg.process(dm); verify(msg, times(0)).operateOnRegion(dm, r, startTime); // A reply is sent even though we do not call operationOnRegion verify(dm, times(1)).putOutgoing(any()); }
@Test public void noNewTxProcessingAfterTXManagerImplClosed() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(txMgr.isClosed()).thenReturn(true); msg.setSender(sender); msg.process(dm); verify(msg, times(0)).operateOnRegion(dm, r, startTime); // If we do not respond what prevents the sender from waiting forever? verify(dm, times(0)).putOutgoing(any()); }
@Test public void masqueradeAsCanGetLock() throws InterruptedException { TXStateProxy tx; tx = txMgr.masqueradeAs(msg); assertNotNull(tx); }
private void setupTx() throws InterruptedException { TXStateProxy tx = txMgr.masqueradeAs(msg); tx.setCommitOnBehalfOfRemoteStub(true); txMgr.unmasquerade(tx); }
@Test public void messageForFinishedTXRepliesWithException() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(false); msg.process(dm); verify(msg, times(1)).sendReply( isNull(), eq(0), eq(dm), argThat(ex -> ex != null && ex.getCause() instanceof TransactionException), eq(pr), eq(startTime)); }
@Test public void messageForFinishedTXRepliesWithException() throws Exception { when(txMgr.masqueradeAs(msg)).thenReturn(tx); when(tx.isInProgress()).thenReturn(false); msg.setSender(sender); msg.process(dm); verify(msg, times(1)).sendReply( eq(sender), eq(0), eq(dm), argThat(ex -> ex != null && ex.getCause() instanceof TransactionException), eq(r), eq(startTime)); }
@Test public void masqueradeAsSetsTarget() throws InterruptedException { TXStateProxy tx; tx = txMgr.masqueradeAs(msg); assertNotNull(tx.getTarget()); } }
@Override public void run() { try { tx1 = txMgr.masqueradeAs(msg); } catch (InterruptedException e) { e.printStackTrace(); throw new RuntimeException(e); } msg.process(dm); TXStateProxy existingTx = masqueradeToRollback(); latch.countDown(); await() .until(() -> tx1.getLock().hasQueuedThreads()); rollbackTransaction(existingTx); } });
@Test public void testTxStateWithCommittedTx() throws InterruptedException { when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class)); setupTx(); TXStateProxy tx = txMgr.masqueradeAs(commitMsg); try { tx.commit(); } finally { txMgr.unmasquerade(tx); } assertFalse(tx.isInProgress()); }
@Test public void testTxStateWithRolledBackTx() throws InterruptedException { when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class)); setupTx(); TXStateProxy tx = txMgr.masqueradeAs(rollbackMsg); try { tx.rollback(); } finally { txMgr.unmasquerade(tx); } assertFalse(tx.isInProgress()); }
@Test public void txStateCleanedUpIfRemovedFromHostedTxStatesMap() { tx1 = txMgr.getOrSetHostedTXState(txid, msg); TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1; assertNotNull(txStateProxy); assertFalse(txStateProxy.getLocalRealDeal().isClosed()); txMgr.masqueradeAs(tx1); // during TX failover, tx can be removed from the hostedTXStates map by FindRemoteTXMessage txMgr.getHostedTXStates().remove(txid); txMgr.unmasquerade(tx1); assertTrue(txStateProxy.getLocalRealDeal().isClosed()); }
@Test public void txStateNotCleanedupIfNotRemovedFromHostedTxStatesMap() { tx1 = txMgr.getOrSetHostedTXState(txid, msg); TXStateProxyImpl txStateProxy = (TXStateProxyImpl) tx1; assertNotNull(txStateProxy); assertFalse(txStateProxy.getLocalRealDeal().isClosed()); txMgr.masqueradeAs(tx1); txMgr.unmasquerade(tx1); assertFalse(txStateProxy.getLocalRealDeal().isClosed()); }