void doWait() { synchronized (this) { while (!this.notified) { getCancelCriterion().checkCancelInProgress(null); boolean interrupted = Thread.interrupted(); try { wait(1000); } catch (InterruptedException ignore) { interrupted = true; } finally { if (interrupted) { Thread.currentThread().interrupt(); } } } } }
/** * Blocks until no register interests are in progress. */ @Override public void waitForRegisterInterestsInProgress() { // In *this* particular context, let the caller know that // its cache has been cancelled. doWait below would do that as // well, so this is just an early out. getCancelCriterion().checkCancelInProgress(null); int count = this.registerInterestsInProgress.get(); if (count > 0) { SimpleWaiter simpleWaiter = null; synchronized (this.riWaiters) { // TODO double-check count = this.registerInterestsInProgress.get(); if (count > 0) { if (logger.isDebugEnabled()) { logger.debug("waitForRegisterInterestsInProgress: count ={}", count); } simpleWaiter = new SimpleWaiter(); this.riWaiters.add(simpleWaiter); } } // synchronized if (simpleWaiter != null) { simpleWaiter.doWait(); } } }
when(cache.getMyId()).thenReturn(member); when(cache.getDistributionManager()).thenReturn(distributionManager); when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion); when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class)); when(cache.getSecurityService()).thenReturn(mock(SecurityService.class));
@Before public void before() throws Exception { System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "statsDisabled", "true"); getRegionsFunction = new GetRegionsFunction(); MockitoAnnotations.initMocks(this); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.cache.getDistributedSystem()).thenReturn(mock(InternalDistributedSystem.class)); when(this.cache.getResourceManager()).thenReturn(this.internalResourceManager); when(functionContext.getResultSender()).thenReturn(testResultSender); when(functionContext.getCache()).thenReturn(cache); }
@Test public void testGetColocatedRegionThrowsCacheClosedExceptionWhenCacheIsClosed() { when(pr.getCache()).thenReturn(cache); DistributedRegion prRoot = mock(DistributedRegion.class); when(cache.getRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME, true)) .thenReturn(prRoot); when(pr.getPartitionAttributes()).thenReturn(pa); when(pa.getColocatedWith()).thenReturn("region2"); PartitionRegionConfig partitionRegionConfig = mock(PartitionRegionConfig.class); when(prRoot.get(any())).thenReturn(partitionRegionConfig); CancelCriterion cancelCriterion = mock(CancelCriterion.class); when(cache.getCancelCriterion()).thenReturn(cancelCriterion); doThrow(CacheClosedException.class).when(cancelCriterion).checkCancelInProgress(any()); assertThatThrownBy(() -> ColocationHelper.getColocatedRegion(pr)) .isInstanceOf(CacheClosedException.class); } }
getCancelCriterion().checkCancelInProgress(null);