Skip to content

Commit fb339ce

Browse files
committed
Add Integration Test for collocated PARTITION Regions configured with SDG Annotation config (EnableEntityDefinedRegions).
Resolves gh-566.
1 parent 75aa327 commit fb339ce

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.gemfire.config.annotation;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mockito.Mockito.mock;
20+
21+
import javax.annotation.Resource;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
27+
import org.apache.geode.cache.Cache;
28+
import org.apache.geode.cache.DataPolicy;
29+
import org.apache.geode.cache.DiskStore;
30+
import org.apache.geode.cache.PartitionResolver;
31+
import org.apache.geode.cache.Region;
32+
33+
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.ComponentScan;
36+
import org.springframework.context.annotation.FilterType;
37+
import org.springframework.data.gemfire.config.annotation.test.entities.NonEntity;
38+
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;
39+
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
40+
import org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects;
41+
import org.springframework.data.gemfire.util.RegionUtils;
42+
import org.springframework.test.context.ContextConfiguration;
43+
import org.springframework.test.context.junit4.SpringRunner;
44+
45+
/**
46+
* Integration Tests for {@link EnableEntityDefinedRegions} annotation configuration
47+
* using {@link DataPolicy#PARTITION} {@link Region Regions}.
48+
*
49+
* @author John Blum
50+
* @see org.junit.Test
51+
* @see org.mockito.Mockito
52+
* @see org.apache.geode.cache.Cache
53+
* @see org.apache.geode.cache.DataPolicy
54+
* @see org.apache.geode.cache.Region
55+
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
56+
* @see org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions
57+
* @see org.springframework.data.gemfire.mapping.annotation.PartitionRegion
58+
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
59+
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
60+
* @see org.springframework.test.context.ContextConfiguration
61+
* @see org.springframework.test.context.junit4.SpringRunner
62+
* @since 2.7.0
63+
*/
64+
@RunWith(SpringRunner.class)
65+
@ContextConfiguration
66+
@SuppressWarnings("unused")
67+
public class EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests extends IntegrationTestsSupport {
68+
69+
@Autowired
70+
private Cache peerCache;
71+
72+
@Resource(name = "ContactEvents")
73+
private Region<?, ?> contactEvents;
74+
75+
@Resource(name = "Customers")
76+
private Region<?, ?> customers;
77+
78+
@Before
79+
public void setup() {
80+
81+
assertThat(this.peerCache).isNotNull();
82+
assertThat(this.peerCache.getName())
83+
.isEqualTo(EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests.class.getSimpleName());
84+
assertThat(this.contactEvents).isNotNull();
85+
assertThat(this.customers).isNotNull();
86+
assertThat(this.peerCache.getRegion(this.contactEvents.getFullPath())).isEqualTo(this.contactEvents);
87+
assertThat(this.peerCache.getRegion(this.customers.getFullPath())).isEqualTo(this.customers);
88+
}
89+
90+
private void assertRegion(Region<?, ?> region, String name, int redundantCopies) {
91+
assertRegion(region, name, null, redundantCopies);
92+
}
93+
94+
private void assertRegion(Region<?, ?> region, String name, String collocatedWith, int redundantCopies) {
95+
96+
assertThat(region).isNotNull();
97+
assertThat(region.getName()).isEqualTo(name);
98+
assertThat(region.getFullPath()).isEqualTo(RegionUtils.toRegionPath(name));
99+
assertThat(region.getAttributes()).isNotNull();
100+
assertThat(region.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_PARTITION);
101+
assertThat(region.getAttributes().getPartitionAttributes()).isNotNull();
102+
assertThat(region.getAttributes().getPartitionAttributes().getColocatedWith()).isEqualTo(collocatedWith);
103+
assertThat(region.getAttributes().getPartitionAttributes().getRedundantCopies()).isEqualTo(redundantCopies);
104+
}
105+
106+
@Test
107+
public void partitionRegionConfiguration() {
108+
109+
assertRegion(this.contactEvents, "ContactEvents", "Customers", 2);
110+
assertRegion(this.customers, "Customers", 1);
111+
}
112+
113+
@EnableGemFireMockObjects
114+
@PeerCacheApplication(name = "EntityDefinedRegionsForCollocatedPartitionRegionsIntegrationsTests")
115+
@EnableEntityDefinedRegions(basePackageClasses = NonEntity.class,
116+
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = PartitionRegion.class))
117+
static class TestConfiguration {
118+
119+
@Bean
120+
DiskStore mockDiskStore() {
121+
return mock(DiskStore.class);
122+
}
123+
124+
@Bean
125+
@SuppressWarnings("rawtypes")
126+
PartitionResolver mockPartitionResolver() {
127+
return mock(PartitionResolver.class);
128+
}
129+
}
130+
}

spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/CollocatedPartitionRegionEntity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
1817
package org.springframework.data.gemfire.config.annotation.test.entities;
1918

2019
import org.springframework.data.gemfire.mapping.annotation.PartitionRegion;

spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/test/entities/PartitionRegionEntity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
1817
package org.springframework.data.gemfire.config.annotation.test.entities;
1918

2019
import org.springframework.data.annotation.Id;

0 commit comments

Comments
 (0)