You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ag...@apache.org on 2018/01/10 23:06:29 UTC
[geode] branch feature/GEODE-3583-storage updated: GEODE-4201:
Remove GemFireCacheImpl.getInstance in PartitionAttributesImpl
This is an automated email from the ASF dual-hosted git repository.
agingade pushed a commit to branch feature/GEODE-3583-storage
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3583-storage by this push:
new e8fd9e4 GEODE-4201: Remove GemFireCacheImpl.getInstance in PartitionAttributesImpl
e8fd9e4 is described below
commit e8fd9e419608423452b5bfb6beff8eca2a0f0d94
Author: Anil <ag...@pivotal.io>
AuthorDate: Wed Jan 10 15:05:02 2018 -0800
GEODE-4201: Remove GemFireCacheImpl.getInstance in PartitionAttributesImpl
---
.../internal/cache/PartitionAttributesImpl.java | 3 +-
.../cache/PartitionRegionConfigValidator.java | 2 +-
.../cache/PartitionAttributesImplJUnitTest.java | 47 ++++++++++++++++++++++
3 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionAttributesImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionAttributesImpl.java
index e97e983..37ad335 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionAttributesImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionAttributesImpl.java
@@ -651,11 +651,10 @@ public class PartitionAttributesImpl implements PartitionAttributes, Cloneable,
*
* @since GemFire 5.8Beta
*/
- void validateColocation() {
+ void validateColocation(Cache cache) {
if (this.colocatedRegionName == null) {
return;
}
- Cache cache = GemFireCacheImpl.getInstance();
if (cache != null) {
Region<?, ?> region = cache.getRegion(this.colocatedRegionName);
if (region == null) {
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionRegionConfigValidator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionRegionConfigValidator.java
index 9f08f99..726cea6 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionRegionConfigValidator.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionRegionConfigValidator.java
@@ -301,7 +301,7 @@ public class PartitionRegionConfigValidator {
final PartitionAttributesImpl userPA =
(PartitionAttributesImpl) pr.getAttributes().getPartitionAttributes();
- userPA.validateColocation(); // do this here to fix bug 47197
+ userPA.validateColocation(pr.getCache()); // do this here to fix bug 47197
PartitionedRegion colocatedPR = ColocationHelper.getColocatedRegion(pr);
if (colocatedPR != null) {
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionAttributesImplJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionAttributesImplJUnitTest.java
index b5fcbff..6c37da5 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionAttributesImplJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PartitionAttributesImplJUnitTest.java
@@ -14,7 +14,13 @@
*/
package org.apache.geode.internal.cache;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.Properties;
@@ -23,11 +29,14 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.apache.geode.cache.Cache;
import org.apache.geode.cache.EntryOperation;
+import org.apache.geode.cache.PartitionAttributes;
import org.apache.geode.cache.PartitionAttributesFactory;
import org.apache.geode.cache.PartitionResolver;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.partition.PartitionListener;
+import org.apache.geode.test.fake.Fakes;
import org.apache.geode.test.junit.categories.UnitTest;
/**
@@ -61,6 +70,7 @@ public class PartitionAttributesImplJUnitTest {
private FixedPartitionAttributesImpl fixedPartitionAttributes;
private PartitionListener partitionListener;
+ private Cache cache;
@Before
public void before() {
@@ -78,6 +88,7 @@ public class PartitionAttributesImplJUnitTest {
this.localMaxMemory = 123;
this.offHeap = false;
+ this.cache = Fakes.cache();
this.partitionResolver = new PartitionResolver<Object, Object>() {
@Override
@@ -473,6 +484,42 @@ public class PartitionAttributesImplJUnitTest {
assertNotEquals(instance, other);
}
+ @Test
+ public void validateColocationWithNonExistingRegion() {
+ PartitionAttributesImpl instance = createPartitionAttributesImpl();
+ instance.setColocatedWith("nonExistingRegion");
+ assertThatThrownBy(() -> instance.validateColocation(cache))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("It should be created before setting");
+ }
+
+ @Test
+ public void validateColocationWithNonPartitionedRegion() {
+ Region region = mock(Region.class);
+ when(cache.getRegion("nonPrRegion")).thenReturn(region);
+ PartitionAttributesImpl instance = createPartitionAttributesImpl();
+ instance.setColocatedWith("nonPrRegion");
+
+ assertThatThrownBy(() -> instance.validateColocation(cache))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessageContaining("supported only for PartitionedRegions");
+ }
+
+ @Test
+ public void validateColocationWithSimilarPartitionedRegion() {
+ PartitionedRegion region = mock(PartitionedRegion.class);
+ PartitionAttributes prAttributes = mock(PartitionAttributes.class);
+ when(cache.getRegion("PrRegion")).thenReturn(region);
+ when(region.getPartitionAttributes()).thenReturn(prAttributes);
+
+ PartitionAttributesImpl instance = createPartitionAttributesImpl();
+ when(prAttributes.getTotalNumBuckets()).thenReturn(instance.getTotalNumBuckets());
+ when(prAttributes.getRedundantCopies()).thenReturn(instance.getRedundantCopies());
+ instance.setColocatedWith("PrRegion");
+ instance.validateColocation(cache);
+ verify(cache, times(1)).getRegion("PrRegion");
+ }
+
private void fillInForEqualityTest(PartitionAttributesImpl instance) {
instance.setRedundantCopies(this.redundancy);
instance.setLocalMaxMemory(this.localMaxMemory);
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].