IndexRealizer implements ConfigurationRealizer<Index, IndexInfo> { @Override public RealizationResult delete(Index config, InternalCache cache) { QueryService queryService = cache.getQueryService(); RealizationResult realizationResult = new RealizationResult(); Region<Object, Object> region = cache.getRegion(SEPARATOR + config.getRegionName()); if (region == null) { realizationResult.setSuccess(false); realizationResult.setMessage("Region for index not found: " + config.getRegionName()); return realizationResult; } org.apache.geode.cache.query.Index index = queryService.getIndex(region, config.getName()); if (index == null) { realizationResult.setSuccess(false); realizationResult.setMessage("Index not found for Region: " + config.getRegionName() + ", " + config.getName()); return realizationResult; } try { queryService.removeIndex(index); realizationResult.setSuccess(true); realizationResult.setMessage("Index " + config.getName() + " successfully removed from " + config.getRegionName()); return realizationResult; } catch (RuntimeException e) { logger.error(e.getMessage(), e); realizationResult.setSuccess(false); realizationResult.setMessage(e.getMessage()); } return realizationResult; }  @Override RealizationResult create(Index config, InternalCache cache); @Override IndexInfo get(Index config, InternalCache cache); @Override RealizationResult update(Index config, InternalCache cache); @Override RealizationResult delete(Index config, InternalCache cache);  }
@Test public void delete_succeeds() { Region<Object, Object> region = mock(Region.class); org.apache.geode.cache.query.Index removeIndex = mock(org.apache.geode.cache.query.Index.class); when(queryService.getIndex(region, "testIndex")).thenReturn(removeIndex); when(cache.getRegion(SEPARATOR + "testRegion")).thenReturn(region); RealizationResult realizationResult = indexRealizer.delete(index, cache); assertSoftly(softly -> { softly.assertThat(realizationResult.isSuccess()).isTrue(); softly.assertThat(realizationResult.getMessage()) .isEqualTo("Index testIndex successfully removed from testRegion"); }); }
@Test public void delete_fails_removal() { Region<Object, Object> region = mock(Region.class); org.apache.geode.cache.query.Index removeIndex = mock(org.apache.geode.cache.query.Index.class); when(queryService.getIndex(region, "testIndex")).thenReturn(removeIndex); when(cache.getRegion(SEPARATOR + "testRegion")).thenReturn(region); doThrow(new RuntimeException("removal failed")).when(queryService).removeIndex(removeIndex); RealizationResult realizationResult = indexRealizer.delete(index, cache); assertSoftly(softly -> { softly.assertThat(realizationResult.isSuccess()).isFalse(); softly.assertThat(realizationResult.getMessage()).isEqualTo("removal failed"); }); }
@Test public void delete_fails_to_find_region() { Region<Object, Object> region = mock(Region.class); org.apache.geode.cache.query.Index removeIndex = mock(org.apache.geode.cache.query.Index.class); when(queryService.getIndex(region, "testIndex")).thenReturn(removeIndex); when(cache.getRegion(SEPARATOR + "testRegion")).thenReturn(null); RealizationResult realizationResult = indexRealizer.delete(index, cache); assertSoftly(softly -> { softly.assertThat(realizationResult.isSuccess()).isFalse(); softly.assertThat(realizationResult.getMessage()) .isEqualTo("Region for index not found: testRegion"); }); }
@Test public void delete_fails_to_find_index() { Region<Object, Object> region = mock(Region.class); org.apache.geode.cache.query.Index removeIndex = mock(org.apache.geode.cache.query.Index.class); when(queryService.getIndex(region, "testIndex")).thenReturn(null); when(cache.getRegion(SEPARATOR + "testRegion")).thenReturn(region); RealizationResult realizationResult = indexRealizer.delete(index, cache); assertSoftly(softly -> { softly.assertThat(realizationResult.isSuccess()).isFalse(); softly.assertThat(realizationResult.getMessage()) .isEqualTo("Index not found for Region: testRegion, testIndex"); }); }