From fb339cee3dc991cbe157f82e8a6b32e5cdaf0a5f Mon Sep 17 00:00:00 2001 From: John Blum Date: Wed, 19 Jan 2022 15:25:49 -0800 Subject: [PATCH] Add Integration Test for collocated PARTITION Regions configured with SDG Annotation config (EnableEntityDefinedRegions). Resolves gh-566. --- ...atedPartitionRegionsIntegrationsTests.java | 130 ++++++++++++++++++ .../CollocatedPartitionRegionEntity.java | 1 - .../test/entities/PartitionRegionEntity.java | 1 - 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.java diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.java new file mode 100644 index 00000000..0a15198a --- /dev/null +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.java @@ -0,0 +1,130 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.gemfire.config.annotation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +import javax.annotation.Resource; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.geode.cache.Cache; +import org.apache.geode.cache.DataPolicy; +import org.apache.geode.cache.DiskStore; +import org.apache.geode.cache.PartitionResolver; +import org.apache.geode.cache.Region; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity; +import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; +import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport; +import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects; +import org.springframework.data.gemfire.util.RegionUtils; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration Tests for {@link EnableEntityDefinedRegions} annotation configuration + * using {@link DataPolicy#PARTITION} {@link Region Regions}. + * + * @author John Blum + * @see org.junit.Test + * @see org.mockito.Mockito + * @see org.apache.geode.cache.Cache + * @see org.apache.geode.cache.DataPolicy + * @see org.apache.geode.cache.Region + * @see org.springframework.data.gemfire.PartitionedRegionFactoryBean + * @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions + * @see org.springframework.data.gemfire.mapping.annotation.PartitionRegion + * @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport + * @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects + * @see org.springframework.test.context.ContextConfiguration + * @see org.springframework.test.context.junit4.SpringRunner + * @since 2.7.0 + */ +@RunWith(SpringRunner.class) +@ContextConfiguration +@SuppressWarnings("unused") +public class EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests extends IntegrationTestsSupport { + + @Autowired + private Cache peerCache; + + @Resource(name = "ContactEvents") + private Region contactEvents; + + @Resource(name = "Customers") + private Region customers; + + @Before + public void setup() { + + assertThat(this.peerCache).isNotNull(); + assertThat(this.peerCache.getName()) + .isEqualTo(EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.class.getSimpleName()); + assertThat(this.contactEvents).isNotNull(); + assertThat(this.customers).isNotNull(); + assertThat(this.peerCache.getRegion(this.contactEvents.getFullPath())).isEqualTo(this.contactEvents); + assertThat(this.peerCache.getRegion(this.customers.getFullPath())).isEqualTo(this.customers); + } + + private void assertRegion(Region region, String name, int redundantCopies) { + assertRegion(region, name, null, redundantCopies); + } + + private void assertRegion(Region region, String name, String collocatedWith, int redundantCopies) { + + assertThat(region).isNotNull(); + assertThat(region.getName()).isEqualTo(name); + assertThat(region.getFullPath()).isEqualTo(RegionUtils.toRegionPath(name)); + assertThat(region.getAttributes()).isNotNull(); + assertThat(region.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_PARTITION); + assertThat(region.getAttributes().getPartitionAttributes()).isNotNull(); + assertThat(region.getAttributes().getPartitionAttributes().getColocatedWith()).isEqualTo(collocatedWith); + assertThat(region.getAttributes().getPartitionAttributes().getRedundantCopies()).isEqualTo(redundantCopies); + } + + @Test + public void partitionRegionConfiguration() { + + assertRegion(this.contactEvents, "ContactEvents", "Customers", 2); + assertRegion(this.customers, "Customers", 1); + } + + @EnableGemFireMockObjects + @PeerCacheApplication(name = "EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests") + @EnableEntityDefinedRegions(basePackageClasses = NonEntity.class, + includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = PartitionRegion.class)) + static class TestConfiguration { + + @Bean + DiskStore mockDiskStore() { + return mock(DiskStore.class); + } + + @Bean + @SuppressWarnings("rawtypes") + PartitionResolver mockPartitionResolver() { + return mock(PartitionResolver.class); + } + } +} diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/CollocatedPartitionRegionEntity.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/CollocatedPartitionRegionEntity.java index fa210f5d..db10f19c 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/CollocatedPartitionRegionEntity.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/CollocatedPartitionRegionEntity.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation.test.entities; import org.springframework.data.gemfire.mapping.annotation.PartitionRegion; diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/PartitionRegionEntity.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/PartitionRegionEntity.java index a4bb88e1..67f7f8b5 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/PartitionRegionEntity.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/PartitionRegionEntity.java @@ -14,7 +14,6 @@ * limitations under the License. * */ - package org.springframework.data.gemfire.config.annotation.test.entities; import org.springframework.data.annotation.Id;