AbstractRegionMapPut { public RegionEntry put() { serializeNewValueIfNeeded(); runWhileLockedForCacheModification(this::doPut); if (isCompleted()) { return getRegionEntry(); } else { return null; } } AbstractRegionMapPut(FocusedRegionMap focusedRegionMap, InternalRegion owner,
      EntryEventImpl event); RegionEntry put();  }
@Test public void putWithShouldCreatedEntryBeRemovedCallsRemoveEntry() { instance.shouldCreatedEntryBeRemoved = true; instance.put(); verify(focusedRegionMap, times(1)).removeEntry(any(), eq(createdRegionEntry), eq(false)); }
@Test public void putWithSatisfiedPreconditionsAndNoExistingEntryReturnsRegionEntryFromFactory() { instance.checkPreconditions = true; when(focusedRegionMap.getEntry(event)).thenReturn(null); RegionEntry result = instance.put(); assertThat(result).isSameAs(createdRegionEntry); verifyMapContractWhenCreateSucceeds(); verifyAbstractContract(); }
@Test public void putWithOnlyExistingTrueAndNoEntryExistsReturnsNull() { instance.onlyExisting = true; instance.entryExists = false; RegionEntry result = instance.put(); assertThat(result).isNull(); verify(focusedRegionMap, times(1)).getEntry(eq(event)); verify(focusedRegionMap, never()).putEntryIfAbsent(any(), any()); verifyAbstractContract(); }
@Test public void putWithExistingEntryReturnsExistingEntry() { instance.checkPreconditions = true; instance.onlyExisting = true; instance.entryExists = true; RegionEntry existingEntry = mock(RegionEntry.class); when(focusedRegionMap.getEntry(eq(event))).thenReturn(existingEntry); RegionEntry result = instance.put(); assertThat(result).isSameAs(existingEntry); verify(focusedRegionMap, times(1)).getEntry(eq(event)); verify(focusedRegionMap, never()).getEntryFactory(); verify(focusedRegionMap, never()).putEntryIfAbsent(any(), eq(createdRegionEntry)); verifyAbstractContract(); }
@Test public void putWithExistingEntryFromPutIfAbsentReturnsExistingEntry() { instance.checkPreconditions = true; RegionEntry existingEntry = mock(RegionEntry.class); when(focusedRegionMap.putEntryIfAbsent(any(), eq(createdRegionEntry))) .thenReturn(existingEntry); RegionEntry result = instance.put(); assertThat(result).isSameAs(existingEntry); verify(focusedRegionMap, times(1)).getEntry(eq(event)); verify(focusedRegionMap, times(1)).getEntryFactory(); verifyAbstractContract(); }
@Test public void putWithExistingEntryFromPutIfAbsentThatIsRemovedReturnsExistingEntry() { instance.checkPreconditions = true; RegionEntry existingEntry = mock(RegionEntry.class); when(existingEntry.isRemovedPhase2()).thenReturn(true).thenReturn(false); when(focusedRegionMap.putEntryIfAbsent(any(), eq(createdRegionEntry))) .thenReturn(existingEntry); RegionEntry result = instance.put(); assertThat(result).isSameAs(existingEntry); verify(focusedRegionMap, times(2)).getEntry(eq(event)); verify(focusedRegionMap, times(2)).getEntryFactory(); verify(entryMap, times(1)).remove(any(), eq(existingEntry)); verifyAbstractContractWithRetry(); }