private static <T extends RegionService> T mockRegionServiceApi(T mockRegionService) { AtomicBoolean closed = new AtomicBoolean(false); doAnswer(newSetter(closed, true, null)).when(mockRegionService).close(); when(mockRegionService.isClosed()).thenAnswer(newGetter(closed)); when(mockRegionService.getCancelCriterion()).thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); when(mockRegionService.getRegion(anyString())).thenAnswer(invocation -> { String regionPath = invocation.getArgument(0); String resolvedRegionPath = Optional.ofNullable(regionPath) .map(String::trim) .filter(it -> !it.isEmpty()) .map(GemFireMockObjectsSupport::toRegionPath) .orElseThrow(() -> newIllegalArgumentException("Region path [%s] is not valid", regionPath)); return regions.get(resolvedRegionPath); }); when(mockRegionService.createPdxEnum(anyString(), anyString(), anyInt())) .thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); when(mockRegionService.createPdxInstanceFactory(anyString())) .thenThrow(newUnsupportedOperationException(NOT_SUPPORTED)); when(mockRegionService.rootRegions()).thenAnswer(invocation -> regions.values().stream().filter(GemFireMockObjectsSupport::isRootRegion).collect(Collectors.toSet())); return mockRegionService; }
/** * Closes and destroys the {@link Region}. * * @throws Exception if {@code destroy()} fails. * @see org.springframework.beans.factory.DisposableBean * @see org.apache.geode.cache.Region#close() * @see org.apache.geode.cache.Region#destroyRegion() */ @Override public void destroy() throws Exception { Optional.ofNullable(getObject()).ifPresent(region -> { if (this.close) { if (!region.getRegionService().isClosed()) { try { region.close(); } catch (Exception ignore) { } } } if (this.destroy) { region.destroyRegion(); } }); }
/** * Closes and destroys the {@link Region}. * * @throws Exception if {@code destroy()} fails. * @see org.springframework.beans.factory.DisposableBean * @see org.apache.geode.cache.Region#close() * @see org.apache.geode.cache.Region#destroyRegion() */ @Override public void destroy() throws Exception { Optional.ofNullable(getObject()).ifPresent(region -> { if (this.close) { if (!region.getRegionService().isClosed()) { try { region.close(); } catch (Exception ignore) { } } } if (this.destroy) { region.destroyRegion(); } }); }
/** * Closes and destroys the {@link Region}. * * @throws Exception if destroy fails. * @see org.springframework.beans.factory.DisposableBean */ @Override public void destroy() throws Exception { Optional.ofNullable(getObject()).ifPresent(region -> { if (isClose()) { if (!region.getRegionService().isClosed()) { try { region.close(); } catch (Exception ignore) { } } } if (isDestroy()) { region.destroyRegion(); } }); }
/** * Closes and destroys the {@link Region}. * * @throws Exception if destroy fails. * @see org.springframework.beans.factory.DisposableBean */ @Override public void destroy() throws Exception { Optional.ofNullable(getObject()).ifPresent(region -> { if (isClose()) { if (!region.getRegionService().isClosed()) { try { region.close(); } catch (Exception ignore) { } } } if (isDestroy()) { region.destroyRegion(); } }); }