@Override public void setTarget(DistributedMember target) { assert this.target == null; getRealDeal(target); if (this.target == null && isRealDealLocal()) { assert target.equals(getCache().getDistributedSystem().getDistributedMember()); this.target = target; } }
private TransactionException getTransactionException(KeyInfo keyInfo, GemFireException e) { if (isRealDealLocal() && !buckets.isEmpty() && !buckets.containsKey(keyInfo.getBucketId())) { TransactionException ex = new TransactionDataNotColocatedException( String.format("Key %s is not colocated with transaction", keyInfo.getKey())); ex.initCause(e.getCause()); return ex; } Throwable ex = e; while (ex != null) { if (ex instanceof PrimaryBucketException) { return new TransactionDataRebalancedException( "Transactional data moved, due to rebalancing."); } ex = ex.getCause(); } return (TransactionException) e; }
/** * This is a test hook method used to find out what keys the current tx has read or written. * * @return an unmodifiable set of keys that have been read or written by the transaction on this * thread. * @throws IllegalStateException if not tx in progress * @since GemFire 5.5 */ public Set testHookTXKeys() { if (!isTX()) { throw new IllegalStateException( "tx not in progress"); } TXStateProxyImpl tx = (TXStateProxyImpl) getTXState(); if (!tx.isRealDealLocal()) { return Collections.emptySet(); } TXRegionState txr = txReadRegion(); if (txr == null) { return Collections.emptySet(); } else { return txr.getEntryKeys(); } }
@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(); }
@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(); }
@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(); }