You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/03/26 17:37:26 UTC

[geode] 01/19: GEODE-1279: Rename Bug51616JUnitTest as CreateRegionFactoryNewInstanceRegressionTest

This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 2953dc0deb44efb693d0664b0e6fbcc7370327e3
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Tue Mar 20 13:10:59 2018 -0700

    GEODE-1279: Rename Bug51616JUnitTest as CreateRegionFactoryNewInstanceRegressionTest
---
 .../apache/geode/internal/Bug51616JUnitTest.java   |  58 ------------
 ...eateRegionFactoryNewInstanceRegressionTest.java | 100 +++++++++++++++++++++
 2 files changed, 100 insertions(+), 58 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/Bug51616JUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/Bug51616JUnitTest.java
deleted file mode 100644
index 33ddb40..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/Bug51616JUnitTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You 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
- *
- * http://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.apache.geode.internal;
-
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.*;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-@Category(IntegrationTest.class)
-public class Bug51616JUnitTest {
-  @Test
-  public void testBug51616() {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOCATORS, "");
-    final Cache cache = (new CacheFactory(props)).create();
-    try {
-      RegionFactory<Integer, String> rf1 = cache.createRegionFactory(RegionShortcut.PARTITION);
-      FixedPartitionAttributes fpa =
-          FixedPartitionAttributes.createFixedPartition("one", true, 111);
-      PartitionAttributesFactory<Integer, String> paf =
-          new PartitionAttributesFactory<Integer, String>();
-      paf.setTotalNumBuckets(111).setRedundantCopies(0).addFixedPartitionAttributes(fpa);
-      rf1.setPartitionAttributes(paf.create());
-
-      Region<Integer, String> region1 = rf1.create("region1");
-
-      RegionFactory<String, Object> rf2 = cache.createRegionFactory(RegionShortcut.PARTITION);
-      PartitionAttributesFactory<String, Object> paf2 =
-          new PartitionAttributesFactory<String, Object>();
-      paf2.setColocatedWith(region1.getFullPath()).setTotalNumBuckets(111).setRedundantCopies(0);
-      PartitionAttributes<String, Object> attrs2 = paf2.create();
-      rf2.setPartitionAttributes(attrs2);
-      rf2.create("region2");
-    } finally {
-      cache.close();
-    }
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/CreateRegionFactoryNewInstanceRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/CreateRegionFactoryNewInstanceRegressionTest.java
new file mode 100644
index 0000000..3861439
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/CreateRegionFactoryNewInstanceRegressionTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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
+ *
+ * http://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.apache.geode.internal;
+
+import static org.apache.geode.cache.FixedPartitionAttributes.createFixedPartition;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.PartitionAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * Cache.createRegionFactory should return a new instance with default values.
+ *
+ * <p>
+ * Prior to the bug fix, Cache.createRegionFactory was internally reusing a modifiable instance of
+ * RegionAttributes.
+ *
+ * <p>
+ * TRAC #51616: Cache.getRegionAttributes returns modifiable RegionAttributes, with unintended side
+ * effects
+ *
+ * <p>
+ * Before the bug was fixed, the 2nd regionFactory.create threw this call stack:
+ *
+ * <pre>
+ * java.lang.IllegalStateException: FixedPartitionAttributes "[FixedPartitionAttributes@[partitionName=one;isPrimary=true;numBuckets=111]]" can not be specified in PartitionAttributesFactory if colocated-with is specified.
+ *     at com.gemstone.gemfire.internal.cache.PartitionAttributesImpl.validateWhenAllAttributesAreSet(PartitionAttributesImpl.java:569)
+ *     at com.gemstone.gemfire.cache.AttributesFactory.validateAttributes(AttributesFactory.java:1515)
+ *     at com.gemstone.gemfire.cache.AttributesFactory.create(AttributesFactory.java:1392)
+ *     at com.gemstone.gemfire.cache.RegionFactory.create(RegionFactory.java:839)
+ *     at PartitionAttributesTest.modifiedVcopsCreateCollocatedFixedRegions(PartitionAttributesTest.java:155)
+ *     at PartitionAttributesTest.main(PartitionAttributesTest.java:47)
+ * </pre>
+ */
+@Category(IntegrationTest.class)
+public class CreateRegionFactoryNewInstanceRegressionTest {
+
+  private Cache cache;
+
+  @Before
+  public void setUp() {
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void createRegionFactoryShouldReturnNewInstanceWithDefaultValues() {
+    PartitionAttributesFactory<Integer, String> paf = new PartitionAttributesFactory<>();
+    paf.setTotalNumBuckets(111);
+    paf.setRedundantCopies(0);
+    paf.addFixedPartitionAttributes(createFixedPartition("one", true, 111));
+
+    RegionFactory<Integer, String> regionFactory1 =
+        cache.createRegionFactory(RegionShortcut.PARTITION);
+    regionFactory1.setPartitionAttributes(paf.create());
+
+    Region<Integer, String> region1 = regionFactory1.create("region1");
+
+    PartitionAttributesFactory<String, Object> paf2 = new PartitionAttributesFactory<>();
+    paf2.setColocatedWith(region1.getFullPath());
+    paf2.setTotalNumBuckets(111);
+    paf2.setRedundantCopies(0);
+
+    RegionFactory<String, Object> regionFactory2 =
+        cache.createRegionFactory(RegionShortcut.PARTITION);
+
+    PartitionAttributes<String, Object> attrs2 = paf2.create();
+    regionFactory2.setPartitionAttributes(attrs2);
+    assertThatCode(() -> regionFactory2.create("region2")).doesNotThrowAnyException();
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
klund@apache.org.