@Test public void getRegionKeysForIterationTranslatesRemoteOperationException() { expectedException.expect(TransactionDataNodeHasDepartedException.class); InternalDistributedSystem system = mock(InternalDistributedSystem.class); ClusterDistributionManager manager = mock(ClusterDistributionManager.class); when(system.getDistributionManager()).thenReturn(manager); when(manager.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); InternalDistributedMember target = new InternalDistributedMember("localhost", 1234); RemoteFetchKeysMessage.FetchKeysResponse responseProcessor = new RemoteFetchKeysMessage.FetchKeysResponse(system, target); RemoteFetchKeysMessage.FetchKeysResponse spy = Mockito.spy(responseProcessor); Exception replyException = new ReplyException("testing", new RemoteOperationException("The cache is closing", new CacheClosedException())); doThrow(replyException).when(spy).waitForRepliesUninterruptibly(); spy.waitForKeys(); fail( "Expected to translate RemoteOperationException.CacheClosedException to TransactionDataNodeHasDepartedException "); }
@Override public Set getRegionKeysForIteration() { try { RemoteFetchKeysMessage.FetchKeysResponse response = RemoteFetchKeysMessage.send((LocalRegion) getRegion(), state.getTarget()); return response.waitForKeys(); } catch (RegionDestroyedException regionDestroyedException) { throw new TransactionDataNotColocatedException( String.format("Region %s not colocated with other regions in transaction", regionDestroyedException.getRegionFullPath()), regionDestroyedException); } catch (CacheClosedException cacheClosedException) { throw new TransactionDataNodeHasDepartedException("Cache was closed while fetching keys"); } catch (TransactionException transactionException) { throw transactionException; } catch (Exception exception) { throw new TransactionException(exception); } }