Add Integration Test for PARTITION Region configuration using SDG Annotation config (@EnableEntityDefinedRegions) along with real Apache Geode objects.

This commit is contained in:
John Blum
2022-01-20 10:23:54 -08:00
parent 6721329b1a
commit a3b3fcc2e5
4 changed files with 201 additions and 0 deletions

View File

@@ -0,0 +1,103 @@
/*
* 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 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.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.config.annotation.test.partition.entities.NonPartitionEntity;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
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 {@literal real} {@link DataPolicy#PARTITION} {@link Region Regions}.
*
* @author John Blum
* @see org.junit.Test
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @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 EntityDefinedRegionsForRealCollocatedPartitionRegionsIntegrationTests extends IntegrationTestsSupport {
@Autowired
private Cache peerCache;
@Resource(name = "After")
private Region<?, ?> after;
@Resource(name = "Before")
private Region<?, ?> before;
@Before
public void setup() {
assertThat(this.peerCache).isNotNull();
assertThat(this.peerCache.getName())
.isEqualTo(EntityDefinedRegionsForRealCollocatedPartitionRegionsIntegrationTests.class.getSimpleName());
assertThat(this.after).isNotNull();
assertThat(this.before).isNotNull();
assertThat(this.peerCache.getRegion(this.after.getFullPath())).isEqualTo(this.after);
assertThat(this.peerCache.getRegion(this.before.getFullPath())).isEqualTo(this.before);
}
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.PARTITION);
assertThat(region.getAttributes().getPartitionAttributes()).isNotNull();
assertThat(region.getAttributes().getPartitionAttributes().getColocatedWith()).isEqualTo(collocatedWith);
assertThat(region.getAttributes().getPartitionAttributes().getRedundantCopies()).isEqualTo(redundantCopies);
}
@Test
public void partitionRegionConfigurationIsCorrect() {
assertRegion(this.after, "After", "Before", 1);
assertRegion(this.before, "Before", 1);
}
@PeerCacheApplication(name = "EntityDefinedRegionsForRealCollocatedPartitionRegionsIntegrationTests")
@EnableEntityDefinedRegions(basePackageClasses = NonPartitionEntity.class)
static class TestConfiguration { }
}

View File

@@ -0,0 +1,41 @@
/*
* 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.test.partition.entities;
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;
/**
* Application entity type stored in an Apache Geode
* {@link org.apache.geode.cache.DataPolicy#PARTITION {@link org.apache.geode.cache.Region}
* collocated with the {@link BeforeEntity} application entity type.
*
* This entity type is deliberately named to alphabetically come before the {@link BeforeEntity} application entity type
* in order to see how the entity component scan finds, defines, declares and registers
* {@link org.apache.geode.cache.Region} bean definitions for these application entity types since Apache Geode expects
* the {@link org.apache.geode.cache.DataPolicy#PARTITION} {@link org.apache.geode.cache.Region}
* for the {@link BeforeEntity} to be created before the {@link org.apache.geode.cache.DataPolicy#PARTITION}
* {@link org.apache.geode.cache.Region} for the {@literal AfterEntity} application entity type,
* given this {@literal AfterEntity} is collocated with the {@link BeforeEntity}.
*
* @author John Blum
* @see org.springframework.data.gemfire.mapping.annotation.PartitionRegion
* @see org.springframework.data.gemfire.config.annotation.test.partition.entities.BeforeEntity
* @since 2.7.0
*/
@PartitionRegion(name = "After", collocatedWith = "Before", redundantCopies = 1)
public class AfterEntity {
}

View File

@@ -0,0 +1,30 @@
/*
* 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.test.partition.entities;
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;
/**
* Application entity type stored in an Apache Geode
* {@link org.apache.geode.cache.DataPolicy#PARTITION {@link org.apache.geode.cache.Region}.
*
* @author John Blum
* @since 2.7.0
*/
@PartitionRegion(name = "Before", redundantCopies = 1)
public class BeforeEntity {
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2016-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.test.partition.entities;
/**
* A non-persistent entity class.
*
* @author John Blum
* @since 2.7.0
*/
public class NonPartitionEntity {
}