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:40 UTC

[geode] 15/19: GEODE-1279: Rename Bug42055DUnitTest as BucketRegionSizeWithOverflowRegressionTest

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 ca73e12f4f5a741dfd4d9ad586f943567cd244ee
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Mar 23 13:39:00 2018 -0700

    GEODE-1279: Rename Bug42055DUnitTest as BucketRegionSizeWithOverflowRegressionTest
    
    The test was apparently unfinished, so I implemented the rest of it. It
    looks like the bug still exists (my assertions fail), so I filed
    GEODE-4929 and marked the test with Ignore("GEODE-4929"). We need to do
    some more work to determine if the bug is really a bug and then fix
    this up.
---
 ...BucketRegionSizeWithOverflowRegressionTest.java | 147 +++++++++++++++++++++
 .../geode/internal/cache/Bug42055DUnitTest.java    |  95 -------------
 2 files changed, 147 insertions(+), 95 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRegionSizeWithOverflowRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRegionSizeWithOverflowRegressionTest.java
new file mode 100644
index 0000000..807966c
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketRegionSizeWithOverflowRegressionTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.cache;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.geode.cache.EvictionAction.OVERFLOW_TO_DISK;
+import static org.apache.geode.cache.EvictionAttributes.createLRUEntryAttributes;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.CacheTestCase;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * PR accessor configured for OverflowToDisk should not create a diskstore.
+ *
+ * <p>
+ * TRAC #42055: a pr accessor configured for OverflowToDisk fails during creation because of disk
+ *
+ * <p>
+ * TRAC #42055 also mentions delta so we should add test(s) for delta as well. <br>
+ * TODO: Test that the bucket size does not go negative when we fault out and in a delta object.
+ */
+@Category(DistributedTest.class)
+public class BucketRegionSizeWithOverflowRegressionTest extends CacheTestCase {
+
+  private static final int ENTRIES_COUNT = 1;
+
+  private String uniqueName;
+  private File datastoreDiskDir;
+  private File accessorDiskDir;
+
+  private VM datastore;
+  private VM accessor;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    datastore = getHost(0).getVM(0);
+    accessor = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    datastoreDiskDir = temporaryFolder.newFolder(uniqueName + "_datastore_disk");
+    accessorDiskDir = temporaryFolder.newFolder(uniqueName + "_accessor_disk");
+
+    datastore.invoke(() -> createDataStore());
+    accessor.invoke(() -> createAccessor());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  @Ignore("GEODE-4929")
+  @Test
+  public void testPROverflow() throws Exception {
+    accessor.invoke(() -> {
+      Region<String, String> region = getCache().getRegion(uniqueName);
+      for (int i = 1; i <= ENTRIES_COUNT + 1; i++) {
+        region.put("key-" + i, "value-" + i);
+      }
+
+      PartitionedRegion partitionedRegion = (PartitionedRegion) region;
+      assertThat(partitionedRegion.getDataStore()).isNull();
+      assertThat(partitionedRegion.size()).isGreaterThanOrEqualTo(0);
+    });
+
+    datastore.invoke(() -> {
+      PartitionedRegion partitionedRegion = (PartitionedRegion) getCache().getRegion(uniqueName);
+      assertThat(getCache().getRegion(uniqueName).size()).isEqualTo(2);
+      assertThat(getCache().getRegion(uniqueName).size()).isGreaterThanOrEqualTo(0);
+      assertThat(partitionedRegion.getDataStore().getAllLocalBucketIds()).hasSize(2);
+    });
+
+    // datastore should create diskstore
+    await().atMost(1, MINUTES)
+        .until(() -> assertThat(datastoreDiskDir.listFiles().length).isGreaterThan(0));
+
+    // accessor should not create a diskstore
+    assertThat(accessorDiskDir.listFiles()).hasSize(0);
+  }
+
+  private void createDataStore() {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(new File[] {datastoreDiskDir});
+
+    AttributesFactory af = new AttributesFactory();
+    af.setDataPolicy(DataPolicy.PARTITION);
+    af.setDiskStoreName(dsf.create(uniqueName).getName());
+    af.setEvictionAttributes(createLRUEntryAttributes(ENTRIES_COUNT, OVERFLOW_TO_DISK));
+    af.setPartitionAttributes(new PartitionAttributesFactory().create());
+
+    getCache().createRegion(uniqueName, af.create());
+  }
+
+  private void createAccessor() {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(new File[] {accessorDiskDir});
+
+    PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<>();
+    paf.setLocalMaxMemory(0);
+
+    AttributesFactory<Integer, TestDelta> af = new AttributesFactory<>();
+    af.setDataPolicy(DataPolicy.PARTITION);
+    af.setDiskStoreName(dsf.create(uniqueName).getName());
+    af.setEvictionAttributes(createLRUEntryAttributes(ENTRIES_COUNT, OVERFLOW_TO_DISK));
+    af.setPartitionAttributes(paf.create());
+
+    getCache().createRegion(uniqueName, af.create());
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug42055DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug42055DUnitTest.java
deleted file mode 100644
index fcdf327..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug42055DUnitTest.java
+++ /dev/null
@@ -1,95 +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.cache;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.EvictionAction;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache30.CacheTestCase;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Test that the bucket size does not go negative when we fault out and in a delta object.
- *
- */
-@Category(DistributedTest.class)
-public class Bug42055DUnitTest extends JUnit4CacheTestCase {
-
-
-  /**
-   * @param name
-   */
-  public Bug42055DUnitTest() {
-    super();
-  }
-
-  @Test
-  public void testPROverflow() throws Exception {
-    final Host host = Host.getHost(0);
-    VM vm0 = host.getVM(0);
-    VM vm1 = host.getVM(1);
-
-    SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {
-      public Object call() throws Exception {
-        Cache cache = getCache();
-        AttributesFactory attr = new AttributesFactory();
-        PartitionAttributesFactory paf = new PartitionAttributesFactory();
-        PartitionAttributes prAttr = paf.create();
-        attr.setPartitionAttributes(prAttr);
-        attr.setEvictionAttributes(
-            EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
-        Region region = cache.createRegion("region1", attr.create());
-
-        return null;
-      }
-    };
-
-    vm0.invoke(createDataRegion);
-
-    SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {
-      public void run() {
-        Cache cache = getCache();
-        AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
-        PartitionAttributesFactory<Integer, TestDelta> paf =
-            new PartitionAttributesFactory<Integer, TestDelta>();
-        paf.setLocalMaxMemory(0);
-        PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
-        attr.setPartitionAttributes(prAttr);
-        attr.setDataPolicy(DataPolicy.PARTITION);
-        attr.setEvictionAttributes(
-            EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
-        Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
-      }
-    };
-
-    vm1.invoke(createEmptyRegion);
-  }
-}

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