RegionMapDestroy { public boolean destroy(final EntryEventImpl eventArg, final boolean inTokenModeArg, final boolean duringRIArg, final boolean cacheWriteArg, final boolean isEvictionArg, final Object expectedOldValueArg, final boolean removeRecoveredEntryArg) throws CacheWriterException, EntryNotFoundException, TimeoutException { if (internalRegion == null) { throw new InternalGemFireError("The internalRegion for RegionMap " + this + " is null for event " + event); } event = eventArg; inTokenMode = inTokenModeArg; duringRI = duringRIArg; cacheWrite = cacheWriteArg; isEviction = isEvictionArg; expectedOldValue = expectedOldValueArg; removeRecoveredEntry = removeRecoveredEntryArg; if (event.isFromRILocalDestroy()) { removeRecoveredEntry = true; } cacheModificationLock.lockForCacheModification(internalRegion, event); final boolean locked = internalRegion.lockWhenRegionIsInitializing(); try { while (retry) { retry = false; opCompleted = false; tombstone = null; haveTombstone = false; doContinue = false; abortDestroyAndReturnFalse = false; regionEntry = focusedRegionMap.getEntry(event); invokeTestHookForConcurrentOperation(); try { if (logger.isTraceEnabled(LogMarker.LRU_TOMBSTONE_COUNT_VERBOSE) && !(internalRegion instanceof HARegion)) { logger.trace(LogMarker.LRU_TOMBSTONE_COUNT_VERBOSE, "ARM.destroy() inTokenMode={}; duringRI={}; riLocalDestroy={}; withRepl={}; fromServer={}; concurrencyEnabled={}; isOriginRemote={}; isEviction={}; operation={}; re={}", inTokenMode, duringRI, event.isFromRILocalDestroy(), internalRegion.getDataPolicy().withReplication(), event.isFromServer(), internalRegion.getConcurrencyChecksEnabled(), event.isOriginRemote(), isEviction, event.getOperation(), regionEntry); } if (regionEntry != null && regionEntry.isTombstone() && !removeRecoveredEntry) { tombstone = regionEntry; haveTombstone = true; regionEntry = null; } if (regionEntry == null) { checkTombstoneAndConcurrency(); if (inTokenMode || retainForConcurrency) { handleMissingRegionEntry(); } } else { handleExistingRegionEntry(); } if (abortDestroyAndReturnFalse) { return false; } if (doContinue) { continue; } if (opCompleted) { EntryLogger.logDestroy(event); } return opCompleted; } finally { try { triggerDistributionAndListenerNotification(); } finally { cancelExpiryTaskIfRegionEntryExisted(); } } } } finally { if (locked) { internalRegion.unlockWhenRegionIsInitializing(); } cacheModificationLock.releaseCacheModificationLock(internalRegion, event); } return false; } RegionMapDestroy(InternalRegion internalRegion, FocusedRegionMap focusedRegionMap,
      CacheModificationLock cacheModificationLock); boolean destroy(final EntryEventImpl eventArg, final boolean inTokenModeArg,
      final boolean duringRIArg, final boolean cacheWriteArg, final boolean isEvictionArg,
      final Object expectedOldValueArg, final boolean removeRecoveredEntryArg);  }
@Test public void destroyDoesNotLockGIIClearLockWhenRegionIsInitialized() throws Exception { DistributedRegion region = mock(DistributedRegion.class, RETURNS_DEEP_STUBS); when(region.isInitialized()).thenReturn(true); when(region.lockWhenRegionIsInitializing()).thenCallRealMethod(); RegionMapDestroy mapDestroy = new RegionMapDestroy(region, regionMap, mock(CacheModificationLock.class)); mapDestroy.destroy(event, inTokenMode, duringRI, cacheWrite, isEviction, expectedOldValue, removeRecoveredEntry); verify(region).lockWhenRegionIsInitializing(); assertThat(region.lockWhenRegionIsInitializing()).isFalse(); verify(region, never()).unlockWhenRegionIsInitializing(); }
@Test public void destroyLockGIIClearLockWhenRegionIsInitializing() throws Exception { DistributedRegion region = mock(DistributedRegion.class, RETURNS_DEEP_STUBS); when(region.isInitialized()).thenReturn(false); when(region.lockWhenRegionIsInitializing()).thenCallRealMethod(); RegionMapDestroy mapDestroy = new RegionMapDestroy(region, regionMap, mock(CacheModificationLock.class)); mapDestroy.destroy(event, inTokenMode, duringRI, cacheWrite, isEviction, expectedOldValue, removeRecoveredEntry); verify(region).lockWhenRegionIsInitializing(); assertThat(region.lockWhenRegionIsInitializing()).isTrue(); verify(region).unlockWhenRegionIsInitializing(); }