proxy = new DistTXStateProxyImplOnCoordinator(cache, this, id, null); } else { proxy = new TXStateProxyImpl(cache, this, id, null);
@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); }
/** * Build a new {@link TXId}, use it as part of the transaction state and associate with the * current thread using a {@link ThreadLocal}. Flag the transaction to be enlisted with a JTA * Transaction. Should only be called in a context where we know there is no existing transaction. */ public TXStateProxy beginJTA() { checkClosed(); TXId id = new TXId(this.distributionMgrId, this.uniqId.incrementAndGet()); TXStateProxy newState = null; if (isDistributed()) { newState = new DistTXStateProxyImplOnCoordinator(cache, this, id, true); } else { newState = new TXStateProxyImpl(cache, this, id, true); } setTXState(newState); return newState; }
@Test public void setTargetWillSetTXStateStubIfTargetIsDifferentFromLocalMember() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); assertThat(tx.hasRealDeal()).isFalse(); assertThat(tx.getTarget()).isNull(); DistributedMember remoteMember = mock(InternalDistributedMember.class); tx.setTarget(remoteMember); assertThat(tx.getTarget()).isEqualTo(remoteMember); assertThat(tx.isRealDealLocal()).isFalse(); assertThat(tx.hasRealDeal()).isTrue(); }
@Test public void setTargetWillSetTargetToItselfAndSetTXStateIfRealDealIsNull() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); assertThat(tx.hasRealDeal()).isFalse(); assertThat(tx.getTarget()).isNull(); tx.setTarget(member); assertThat(tx.getTarget()).isEqualTo(member); assertThat(tx.isRealDealLocal()).isTrue(); }
val = new TXStateProxyImpl(cache, this, key, memberId);
@Test public void getCacheReturnsInjectedCache() { TXStateProxyImpl tx = new TXStateProxyImpl(cache, txManager, txId, false); assertThat(tx.getCache()).isSameAs(cache); }
@Test public void setTargetToItSelfIfRealDealIsTXStateAndTargetIsSameAsLocalMember() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); tx.setLocalTXState(new TXState(tx, true)); assertThat(tx.isRealDealLocal()).isTrue(); assertThat(tx.getTarget()).isNull(); tx.setTarget(member); assertThat(tx.getTarget()).isEqualTo(member); assertThat(tx.isRealDealLocal()).isTrue(); }
TXStateProxy getOrSetHostedTXState(TXId key, TransactionMessage msg) { TXStateProxy val = this.hostedTXStates.get(key); if (val == null) { synchronized (this.hostedTXStates) { val = this.hostedTXStates.get(key); if (val == null && msg.canStartRemoteTransaction()) { if (msg.isTransactionDistributed()) { val = new DistTXStateProxyImplOnDatanode(cache, this, key, msg.getTXOriginatorClient()); val.setLocalTXState(new DistTXState(val, true)); } else { val = new TXStateProxyImpl(cache, this, key, msg.getTXOriginatorClient()); val.setLocalTXState(new TXState(val, true)); val.setTarget(cache.getDistributedSystem().getDistributedMember()); } this.hostedTXStates.put(key, val); } } } return val; }
@Test(expected = AssertionError.class) public void setTargetThrowsIfIfRealDealIsTXStateAndTargetIsDifferentFromLocalMember() { TXStateProxyImpl tx = spy(new TXStateProxyImpl(cache, txManager, txId, false)); tx.setLocalTXState(new TXState(tx, true)); assertThat(tx.getTarget()).isNull(); DistributedMember remoteMember = mock(InternalDistributedMember.class); tx.setTarget(remoteMember); } }
TXStateProxyImpl proxy = new TXStateProxyImpl(cache, txManager, txId, null);
@Test public void getKeyForIteratorReturnsKey() { RegionEntryFactory regionEntryFactory = new RegionEntryFactoryBuilder().create(false, false, false, false, false); RegionEntry regionEntry = regionEntryFactory.createEntry(region, key, null); KeyInfo stringKeyInfo = new KeyInfo(key, null, null); KeyInfo regionEntryKeyInfo = new KeyInfo(regionEntry, null, null); boolean allowTombstones = false; boolean rememberReads = true; when(region.getSharedDataView()).thenReturn(view); when(view.getEntry(stringKeyInfo, region, allowTombstones)).thenReturn(mock(NonTXEntry.class)); when(view.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones)) .thenCallRealMethod(); when(view.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones)) .thenCallRealMethod(); TXStateProxyImpl tx = new TXStateProxyImpl(cache, txManager, txId, false); Object key1 = tx.getKeyForIterator(regionEntryKeyInfo, region, rememberReads, allowTombstones); assertThat(key1.equals(key)).isTrue(); Object key2 = tx.getKeyForIterator(stringKeyInfo, region, rememberReads, allowTombstones); assertThat(key2.equals(key)).isTrue(); }