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

[geode] branch develop updated (0ffb983 -> 3b32fd5)

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

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


    from 0ffb983  Revert "GEODE-4928 DistributedLockService doesn't work as expected while the dlock grantor is initialized"
     new 2953dc0  GEODE-1279: Rename Bug51616JUnitTest as CreateRegionFactoryNewInstanceRegressionTest
     new 0618d54  GEODE-1279: Rename Bug33726JUnitTest as AfterRegionCreateNotBeforeRegionInitRegressionTest
     new be91870  GEODE-1279: Rename Bug34179TooManyFilesOpenJUnitTest as OplogTooManyFilesOpenRegressionTest
     new cd3ff6d  GEODE-1279: Rename Bug34583JUnitTest as RegionValuesIteratorAfterLocalInvalidateRegressionTest
     new 020291f  GEODE-1279: Fix serialization of LocalVM
     new 8009a12  GEODE-1279: Rename Bug37241DUnitTest as CleanupFailedInitWithDiskFilesRegressionTest
     new 3e2619f  GEODE-1279: Rename Bug37377DUnitTest as ClearDuringGiiOplogWithMissingCreateRegressionTest
     new 10eabfb  GEODE-1279: Rename Bug37500JUnitTest as DiskAccessExceptionDisablesServerRegressionTest
     new 0e6a1b9  GEODE-1279: Rename Bug39079DUnitTest
     new e2e2b90  GEODE-1279: Rename Bug40299DUnitTest as ClearDuringNetSearchOplogRegressionTest
     new f542032  GEODE-1279: Rename Bug40632DUnitTest as CreatePRWithLocalExpirationRegressionTest
     new f53b5a6  GEODE-1279: Rename Bug41091DUnitTest as BucketCreationGIIHARegressionTest
     new d93f3d5  GEODE-1279: Rename Bug41733DUnitTest as BucketCreationRequesterCrashHARegressionTest
     new 735b855  GEODE-1279: Rename Bug41957DUnitTest as RegisterInterestWithEvictionRegressionTest
     new ca73e12  GEODE-1279: Rename Bug42055DUnitTest as BucketRegionSizeWithOverflowRegressionTest
     new 5561078  GEODE-1279: Rename Bug45164DUnitTest as PREntrySetIteratorRegressionTest
     new 3b4791c  GEODE-1279: Rename Bug45934DUnitTest as DiskRecoveryWithVersioningGiiRegressionTest
     new 5349447  GEODE-1279: Rename Bug47667DUnitTest as ClientTxCommitShouldNotHangRegressionTest
     new 3b32fd5  GEODE-1279: Rename Bug36853EventsExpiryDUnitTest as ClientSubscriptionExpiryDataLossRegressionTest

The 19 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../geode/internal/cache/AbstractRegion.java       |  13 -
 .../geode/internal/cache/InternalRegion.java       |  13 +
 .../apache/geode/internal/cache/LocalRegion.java   |   2 +-
 .../cache/SearchLoadAndWriteProcessor.java         |  17 +-
 .../apache/geode/internal/Bug51616JUnitTest.java   |  58 ----
 ...eateRegionFactoryNewInstanceRegressionTest.java | 100 ++++++
 ...ionCreateNotBeforeRegionInitRegressionTest.java |  94 ++++++
 .../cache/BucketCreationGIIHARegressionTest.java   | 120 ++++++++
 ...cketCreationRequesterCrashHARegressionTest.java | 261 ++++++++++++++++
 ...BucketRegionSizeWithOverflowRegressionTest.java | 147 +++++++++
 .../geode/internal/cache/Bug33726JUnitTest.java    | 110 -------
 .../cache/Bug34179TooManyFilesOpenJUnitTest.java   |  96 ------
 .../geode/internal/cache/Bug34583JUnitTest.java    |  96 ------
 .../geode/internal/cache/Bug37241DUnitTest.java    | 205 -------------
 .../geode/internal/cache/Bug37377DUnitTest.java    | 317 -------------------
 .../geode/internal/cache/Bug37500JUnitTest.java    | 163 ----------
 .../geode/internal/cache/Bug39079DUnitTest.java    | 341 ---------------------
 .../geode/internal/cache/Bug40299DUnitTest.java    | 263 ----------------
 .../geode/internal/cache/Bug40632DUnitTest.java    | 109 -------
 .../geode/internal/cache/Bug41091DUnitTest.java    | 169 ----------
 .../geode/internal/cache/Bug41733DUnitTest.java    | 211 -------------
 .../geode/internal/cache/Bug41957DUnitTest.java    | 165 ----------
 .../geode/internal/cache/Bug42055DUnitTest.java    |  95 ------
 .../geode/internal/cache/Bug45164DUnitTest.java    | 113 -------
 .../geode/internal/cache/Bug45934DUnitTest.java    | 138 ---------
 .../geode/internal/cache/Bug47667DUnitTest.java    |  96 ------
 ...eanupFailedInitWithDiskFilesRegressionTest.java | 161 ++++++++++
 ...ingGiiOplogWithMissingCreateRegressionTest.java | 229 ++++++++++++++
 .../ClearDuringNetSearchOplogRegressionTest.java   | 205 +++++++++++++
 .../ClientTxCommitShouldNotHangRegressionTest.java | 175 +++++++++++
 .../CreatePRWithLocalExpirationRegressionTest.java |  96 ++++++
 ...ccessExceptionDisablesServerRegressionTest.java | 241 +++++++++++++++
 ...iskRecoveryWithVersioningGiiRegressionTest.java | 206 +++++++++++++
 .../GiiDiskAccessExceptionRegressionTest.java      | 211 +++++++++++++
 ...zedDiskRegionWithIoExceptionRegressionTest.java | 174 +++++++++++
 .../cache/OplogTooManyFilesOpenRegressionTest.java | 155 ++++++++++
 .../cache/PREntrySetIteratorRegressionTest.java    |  98 ++++++
 ...IteratorAfterLocalInvalidateRegressionTest.java | 101 ++++++
 ...RegisterInterestWithEvictionRegressionTest.java | 144 +++++++++
 .../cache/ha/Bug36853EventsExpiryDUnitTest.java    | 268 ----------------
 ...ntSubscriptionExpiryDataLossRegressionTest.java | 195 ++++++++++++
 .../java/org/apache/geode/test/dunit/LocalVM.java  |   3 +-
 42 files changed, 3132 insertions(+), 3042 deletions(-)
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/Bug51616JUnitTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/CreateRegionFactoryNewInstanceRegressionTest.java
 create mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationGIIHARegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationRequesterCrashHARegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/BucketRegionSizeWithOverflowRegressionTest.java
 delete mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug34179TooManyFilesOpenJUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug34583JUnitTest.java
 delete mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/Bug37241DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug37377DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug37500JUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug39079DUnitTest.java
 delete mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/Bug40299DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug40632DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug41091DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug41733DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug41957DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug42055DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug45934DUnitTest.java
 delete mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/Bug47667DUnitTest.java
 create mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/CleanupFailedInitWithDiskFilesRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringGiiOplogWithMissingCreateRegressionTest.java
 create mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringNetSearchOplogRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/ClientTxCommitShouldNotHangRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/CreatePRWithLocalExpirationRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/DiskAccessExceptionDisablesServerRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/DiskRecoveryWithVersioningGiiRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/GiiDiskAccessExceptionRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/InitializedDiskRegionWithIoExceptionRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/OplogTooManyFilesOpenRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/RegionValuesIteratorAfterLocalInvalidateRegressionTest.java
 create mode 100644 geode-core/src/test/java/org/apache/geode/internal/cache/RegisterInterestWithEvictionRegressionTest.java
 delete mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/ha/Bug36853EventsExpiryDUnitTest.java
 create mode 100755 geode-core/src/test/java/org/apache/geode/internal/cache/ha/ClientSubscriptionExpiryDataLossRegressionTest.java

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

[geode] 03/19: GEODE-1279: Rename Bug34179TooManyFilesOpenJUnitTest as OplogTooManyFilesOpenRegressionTest

Posted by kl...@apache.org.
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 be91870b7e78d8c0c16c3661343ce5a7277ef79e
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Tue Mar 20 16:29:00 2018 -0700

    GEODE-1279: Rename Bug34179TooManyFilesOpenJUnitTest as OplogTooManyFilesOpenRegressionTest
---
 .../cache/Bug34179TooManyFilesOpenJUnitTest.java   |  96 -------------
 .../cache/OplogTooManyFilesOpenRegressionTest.java | 155 +++++++++++++++++++++
 2 files changed, 155 insertions(+), 96 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34179TooManyFilesOpenJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34179TooManyFilesOpenJUnitTest.java
deleted file mode 100644
index caa5f10..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34179TooManyFilesOpenJUnitTest.java
+++ /dev/null
@@ -1,96 +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 java.io.File;
-import java.util.Arrays;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.LogWriter;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * Disk region perf test for Persist only with Async writes and Buffer. Set Rolling oplog to true
- * and setMaxOplogSize to 10240
- *
- * If more than some number of files are open, an Exception is thrown. This ia JDK 1.4 bug. This
- * test should be run after transition to JDK 1.5 to verify that the bug does not exceed.
- *
- * The disk properties will ensure that very many oplog files are created.
- *
- * This test is currently not being executed and is marked with an underscore
- */
-@Category(IntegrationTest.class)
-public class Bug34179TooManyFilesOpenJUnitTest extends DiskRegionTestingBase {
-
-  private static int ENTRY_SIZE = 1024;
-
-  private static int OP_COUNT = 100000;
-
-  private LogWriter log = null;
-
-  private DiskRegionProperties diskProps = new DiskRegionProperties();
-
-  @Override
-  protected final void postSetUp() throws Exception {
-    File file1 = new File("testingDirectory/" + getName() + "1");
-    file1.mkdir();
-    file1.deleteOnExit();
-    dirs = new File[1];
-    dirs[0] = file1;
-    diskProps.setDiskDirs(dirs);
-
-    diskProps.setPersistBackup(true);
-    diskProps.setTimeInterval(15000l);
-    diskProps.setBytesThreshold(10000l);
-    diskProps.setRolling(true);
-    // set max oplog size as 10 kb
-    diskProps.setMaxOplogSize(10240);
-    region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, diskProps);
-
-    log = ds.getLogWriter();
-  }
-
-  /**
-   * currently not being executed for congo but after transition to JDK 1.5, this test should be
-   * executed.
-   */
-  @Ignore("TODO: test is disabled")
-  @Test
-  public void testPopulate1kbwrites() {
-    final byte[] value = new byte[ENTRY_SIZE];
-    Arrays.fill(value, (byte) 77);
-    for (int i = 0; i < OP_COUNT; i++) {
-      region.put(new Integer(i), value);
-    }
-    closeDown(); // closes disk file which will flush all buffers
-  }
-
-  /**
-   * cleans all the directory of all the files present in them
-   */
-  protected void deleteFiles() {
-    for (int i = 0; i < dirs.length; i++) {
-      File[] files = dirs[i].listFiles();
-      for (int j = 0; j < files.length; j++) {
-        files[j].delete();
-      }
-    }
-  }
-
-}// end of Bug34179TooManyFilesOpenJUnitTest
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/OplogTooManyFilesOpenRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/OplogTooManyFilesOpenRegressionTest.java
new file mode 100644
index 0000000..33b91fc
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/OplogTooManyFilesOpenRegressionTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
+
+/**
+ * Disk region perf test for Persist only with Async writes and Buffer. Set Rolling oplog to true
+ * and setMaxOplogSize to 10240
+ *
+ * If more than some number of files are open, an Exception is thrown. This ia JDK 1.4 bug. This
+ * test should be run after transition to JDK 1.5 to verify that the bug does not exceed.
+ *
+ * The disk properties will ensure that very many oplog files are created.
+ *
+ * <p>
+ * TRAC #34179: Failed creating operation log. (putDiskRegPersistAsyncWithBufferRollOlgPerf.conf)
+ *
+ * <pre>
+ * Caused by: com.gemstone.gemfire.cache.DiskAccessException: Failed creating operation log because: java.io.FileNotFoundException: /export/marlin2/users/vjadhav/diskTxJan06/tests/results/battery/putDiskRegPersistAsyncWithBufferRollOlgPerf-0222-160447/BACKUP_diskRegion_505.olg (Too many open files)
+ *     at com.gemstone.gemfire.internal.cache.Oplog.<init>(Oplog.java:234)
+ *     at com.gemstone.gemfire.internal.cache.Oplog.modify(Oplog.java:1355)
+ *     at com.gemstone.gemfire.internal.cache.DiskRegion.put(DiskRegion.java:280)
+ *     at com.gemstone.gemfire.internal.cache.DiskEntry$Helper.writeToDisk(DiskEntry.java:325)
+ *     at com.gemstone.gemfire.internal.cache.DiskEntry$Helper.update(DiskEntry.java:359)
+ *     at com.gemstone.gemfire.internal.cache.AbstractDiskRegionEntry.setValue(AbstractDiskRegionEntry.java:66)
+ *     at com.gemstone.gemfire.internal.cache.EntryEventImpl.setNewValue(EntryEventImpl.java:356)
+ *     at com.gemstone.gemfire.internal.cache.EntryEventImpl.putExistingEntry(EntryEventImpl.java:314)
+ *     at com.gemstone.gemfire.internal.cache.AbstractRegionMap.basicPut(AbstractRegionMap.java:786)
+ *     at com.gemstone.gemfire.internal.cache.LocalRegion.virtualPut(LocalRegion.java:2147)
+ *     at com.gemstone.gemfire.internal.cache.LocalRegion.basicPut(LocalRegion.java:2030)
+ *     at com.gemstone.gemfire.internal.cache.LocalRegion.put(LocalRegion.java:826)
+ *     at com.gemstone.gemfire.internal.cache.AbstractRegion.put(AbstractRegion.java:122)
+ * </pre>
+ */
+@Category(IntegrationTest.class)
+public class OplogTooManyFilesOpenRegressionTest {
+
+  private static final int VALUE_SIZE = 1024;
+  private static final int PUT_COUNT = 100_000;
+
+  private Cache cache;
+  private Region<Integer, byte[]> region;
+  private byte[] value;
+
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() {
+    String uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    File temporaryDirectory = temporaryFolder.getRoot();
+
+    value = new byte[VALUE_SIZE];
+    Arrays.fill(value, (byte) 77);
+
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+
+    DiskRegionProperties diskRegionProperties = new DiskRegionProperties();
+    diskRegionProperties.setBytesThreshold(10000l);
+    diskRegionProperties.setDiskDirs(new File[] {temporaryDirectory});
+    diskRegionProperties.setMaxOplogSize(10240);
+    diskRegionProperties.setPersistBackup(true);
+    diskRegionProperties.setRolling(true);
+    diskRegionProperties.setSynchronous(false);
+    diskRegionProperties.setTimeInterval(15000l);
+
+    DiskStoreFactory dsf = cache.createDiskStoreFactory();
+    dsf.setAllowForceCompaction(diskRegionProperties.getAllowForceCompaction());
+    dsf.setAutoCompact(diskRegionProperties.isRolling());
+    dsf.setCompactionThreshold(diskRegionProperties.getCompactionThreshold());
+    dsf.setDiskDirsAndSizes(diskRegionProperties.getDiskDirs(), new int[] {Integer.MAX_VALUE});
+    dsf.setQueueSize((int) diskRegionProperties.getBytesThreshold());
+    dsf.setTimeInterval(diskRegionProperties.getTimeInterval());
+
+    setMaxOplogSizeInBytes(diskRegionProperties, dsf);
+
+    DirectoryHolder.SET_DIRECTORY_SIZE_IN_BYTES_FOR_TESTING_PURPOSES = true;
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    RegionFactory<Integer, byte[]> regionFactory = cache.createRegionFactory();
+    regionFactory.setDiskStoreName(diskStore.getName());
+    regionFactory.setDiskSynchronous(diskRegionProperties.isSynchronous());
+    regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    regionFactory.setConcurrencyLevel(diskRegionProperties.getConcurrencyLevel());
+    regionFactory.setInitialCapacity(diskRegionProperties.getInitialCapacity());
+    regionFactory.setLoadFactor(diskRegionProperties.getLoadFactor());
+    regionFactory.setScope(Scope.LOCAL);
+    regionFactory.setStatisticsEnabled(diskRegionProperties.getStatisticsEnabled());
+
+    region = regionFactory.create(uniqueName);
+  }
+
+  private void setMaxOplogSizeInBytes(DiskRegionProperties diskRegionProperties,
+      DiskStoreFactory dsf) {
+    DiskStoreFactoryImpl impl = (DiskStoreFactoryImpl) dsf;
+    impl.setMaxOplogSizeInBytes(diskRegionProperties.getMaxOplogSize());
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void testPopulate1kbwrites() {
+    for (int i = 0; i < PUT_COUNT; i++) {
+      region.put(i, value);
+    }
+
+    // closes disk file which will flush all buffers
+    region.destroyRegion();
+  }
+}

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

[geode] 10/19: GEODE-1279: Rename Bug40299DUnitTest as ClearDuringNetSearchOplogRegressionTest

Posted by kl...@apache.org.
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 e2e2b904b4688b2fdfd4a8713df66ae63057f7db
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Mar 22 12:15:23 2018 -0700

    GEODE-1279: Rename Bug40299DUnitTest as ClearDuringNetSearchOplogRegressionTest
    
    * Move testNetSearchMessageDoGet from SearchLoadAndWriteProcessor to
    the test
    * Move generateEventID and getMyId from AbstractRegion to
    InternalRegion
    * Remove Thread.sleep and cleanup test
---
 .../geode/internal/cache/AbstractRegion.java       |  13 -
 .../geode/internal/cache/InternalRegion.java       |  13 +
 .../apache/geode/internal/cache/LocalRegion.java   |   2 +-
 .../cache/SearchLoadAndWriteProcessor.java         |  17 +-
 .../geode/internal/cache/Bug40299DUnitTest.java    | 263 ---------------------
 .../ClearDuringNetSearchOplogRegressionTest.java   | 205 ++++++++++++++++
 6 files changed, 222 insertions(+), 291 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
index 46c7a4e..bc5f792 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/AbstractRegion.java
@@ -371,19 +371,6 @@ public abstract class AbstractRegion implements InternalRegion, AttributesMutato
 
   abstract void basicClear(RegionEventImpl regionEvent);
 
-  /**
-   * The default Region implementation will generate EvenTID in the EntryEvent object. This method
-   * is overridden in special Region objects like HARegion or
-   * SingleWriteSingleReadRegionQueue.SingleReadWriteMetaRegion to return false as the event
-   * propagation from those regions do not need EventID objects. This method is made abstract to
-   * directly use it in clear operations. (clear and localclear)
-   *
-   * @return boolean indicating whether to generate eventID or not
-   */
-  abstract boolean generateEventID();
-
-  protected abstract InternalDistributedMember getMyId();
-
   @Override
   public void clear() {
     checkReadiness();
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
index eeb2023..7c5d722 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalRegion.java
@@ -225,4 +225,17 @@ public interface InternalRegion extends Region, HasCachePerfStats, RegionEntryCo
   boolean isInitialized();
 
   void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client);
+
+  InternalDistributedMember getMyId();
+
+  /**
+   * The default Region implementation will generate EvenTID in the EntryEvent object. This method
+   * is overridden in special Region objects like HARegion or
+   * SingleWriteSingleReadRegionQueue.SingleReadWriteMetaRegion to return false as the event
+   * propagation from those regions do not need EventID objects. This method is made abstract to
+   * directly use it in clear operations. (clear and localclear)
+   *
+   * @return boolean indicating whether to generate eventID or not
+   */
+  boolean generateEventID();
 }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 7519048..b20c838 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -853,7 +853,7 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
    * @since GemFire 5.0
    */
   @Override
-  protected InternalDistributedMember getMyId() {
+  public InternalDistributedMember getMyId() {
     return this.cache.getInternalDistributedSystem().getDistributedMember();
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/SearchLoadAndWriteProcessor.java b/geode-core/src/main/java/org/apache/geode/internal/cache/SearchLoadAndWriteProcessor.java
index c7502b5..b55c9f4 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/SearchLoadAndWriteProcessor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/SearchLoadAndWriteProcessor.java
@@ -1338,17 +1338,6 @@ public class SearchLoadAndWriteProcessor implements MembershipListener {
   }
 
   /**
-   * Test method for bug 40299.
-   */
-  @SuppressWarnings("synthetic-access")
-  public void testNetSearchMessageDoGet(String theRegionName, Object theKey, int theTimeoutMs,
-      int theTtl, int theIdleTime) {
-    NetSearchRequestMessage nMsg = new NetSearchRequestMessage();
-    nMsg.initialize(this, theRegionName, theKey, theTimeoutMs, theTtl, theIdleTime);
-    nMsg.doGet((ClusterDistributionManager) this.distributionManager);
-  }
-
-  /**
    * A QueryMessage is broadcast to every node that has the region defined, to find out who has a
    * valid copy of the requested object.
    */
@@ -1769,8 +1758,8 @@ public class SearchLoadAndWriteProcessor implements MembershipListener {
 
     }
 
-    private void initialize(SearchLoadAndWriteProcessor processor, String theRegionName,
-        Object theKey, int timeoutMS, int ttlMS, int idleTimeMS) {
+    void initialize(SearchLoadAndWriteProcessor processor, String theRegionName, Object theKey,
+        int timeoutMS, int ttlMS, int idleTimeMS) {
       this.processorId = processor.processorId;
       this.regionName = theRegionName;
       this.key = theKey;
@@ -1842,7 +1831,7 @@ public class SearchLoadAndWriteProcessor implements MembershipListener {
           + "\" in region \"" + this.regionName + "\", processorId " + processorId;
     }
 
-    private void doGet(ClusterDistributionManager dm) {
+    void doGet(ClusterDistributionManager dm) {
       long startTime = dm.cacheTimeMillis();
       // boolean retVal = true;
       byte[] ebv = null;
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40299DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40299DUnitTest.java
deleted file mode 100755
index fe0f796..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40299DUnitTest.java
+++ /dev/null
@@ -1,263 +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 java.io.File;
-import java.util.Properties;
-
-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.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.EvictionAction;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.Operation;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache30.CacheSerializableRunnable;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.IgnoredException;
-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.junit.categories.DistributedTest;
-
-/**
- * Bug40299 DUNIT Test: The Clear operation during a NetSearchMessage.doGet() in progress can cause
- * DiskAccessException by accessing cleared oplogs and eventually destroy region. The Test verifies
- * that fix prevents this.
- */
-@Category(DistributedTest.class)
-public class Bug40299DUnitTest extends JUnit4CacheTestCase {
-
-  protected static String regionName = "TestRegion";
-
-  static Properties props = new Properties();
-
-  protected static DistributedSystem distributedSystem = null;
-
-  private static VM vm0 = null;
-
-  protected static Cache cache = null;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    final Host host = Host.getHost(0);
-    vm0 = host.getVM(0);
-  }
-
-  @Override
-  public final void preTearDownCacheTestCase() throws Exception {
-    vm0.invoke(destroyRegion());
-  }
-
-  /**
-   * This method is used to create Cache in VM0
-   *
-   * @return CacheSerializableRunnable
-   */
-
-  private CacheSerializableRunnable createCacheForVM0() {
-    SerializableRunnable createCache = new CacheSerializableRunnable("createCache") {
-      public void run2() {
-        try {
-
-          distributedSystem = (new Bug40299DUnitTest()).getSystem(props);
-          assertTrue(distributedSystem != null);
-          cache = CacheFactory.create(distributedSystem);
-          assertTrue(cache != null);
-          AttributesFactory factory = new AttributesFactory();
-          factory.setScope(Scope.DISTRIBUTED_ACK);
-          File dir = new File("testingDirectoryDefault");
-          dir.mkdir();
-          dir.deleteOnExit();
-          File[] dirs = {dir};
-          factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-          factory.setDiskSynchronous(false);
-          factory.setDiskStoreName(cache.createDiskStoreFactory()
-              .setDiskDirsAndSizes(dirs, new int[] {Integer.MAX_VALUE}).setQueueSize(1)
-              .setMaxOplogSize(60) // does the test want 60 bytes or 60M?
-              .setAutoCompact(false).setTimeInterval(1000).create("Bug40299DUnitTest").getName());
-          factory.setEvictionAttributes(
-              EvictionAttributes.createLRUEntryAttributes(2, EvictionAction.OVERFLOW_TO_DISK));
-          RegionAttributes attr = factory.create();
-          cache.createRegion(regionName, attr);
-        } catch (Exception ex) {
-          ex.printStackTrace();
-          fail("Error Creating cache / region ");
-        }
-      }
-    };
-    return (CacheSerializableRunnable) createCache;
-  }
-
-  /**
-   * This method puts in 7 in the Region
-   *
-   * @return CacheSerializableRunnable
-   */
-  private CacheSerializableRunnable putSomeEntries() {
-    SerializableRunnable puts = new CacheSerializableRunnable("putSomeEntries") {
-      public void run2() {
-        assertTrue("Cache is found as null ", cache != null);
-        Region rgn = cache.getRegion(regionName);
-        for (int i = 0; i < 7; i++) {
-          rgn.put("key" + i, new Long(i));
-        }
-      }
-    };
-    return (CacheSerializableRunnable) puts;
-  }
-
-  /**
-   * This method does concurrent NetSearch.doGet with clear in the Region
-   *
-   * @return CacheSerializableRunnable
-   */
-  private CacheSerializableRunnable concurrentNetSearchGetAndClear() {
-    SerializableRunnable getAndClear =
-        new CacheSerializableRunnable("concurrentNetSearchGetAndClear") {
-          public void run2() {
-            assertTrue("Cache is found as null ", cache != null);
-            Region rgn = cache.getRegion(regionName);
-            assertTrue("Region size expected to be 7 but is " + rgn.size(), rgn.size() == 7);
-
-            Thread getThread1 = null;
-            LocalRegion lr = (LocalRegion) rgn;
-            lr.getDiskRegion().acquireWriteLock();
-            // got writeLock from diskregion
-            try {
-              getThread1 = new Thread(new getThread((LocalRegion) rgn));
-
-              // start getThread
-              getThread1.start();
-
-              // sleep for a while to allow getThread to wait for readLock.
-              Thread.sleep(1000);
-
-              // This test appears to be testing a problem with the non-RVV
-              // based clear. So we'll use that functionality here.
-              // Region.clear uses an RVV, and will deadlock if called while
-              // the write lock is held.
-              RegionEventImpl regionEvent = new RegionEventImpl(lr, Operation.REGION_CLEAR, null,
-                  false, lr.getMyId(), lr.generateEventID());
-              // clearRegion to remove entry that getThread has reference of
-              lr.cmnClearRegion(regionEvent, true, false);
-            } catch (InterruptedException e) {
-              if (cache.getLogger().fineEnabled()) {
-                cache.getLogger().fine("InterruptedException in run of localClearThread");
-              }
-            } finally {
-              ((LocalRegion) rgn).getDiskRegion().releaseWriteLock();
-            }
-            // allow getThread to join to set getAfterClearSuccessful
-            try {
-              getThread1.join();
-            } catch (InterruptedException ie) {
-              if (cache.getLogger().fineEnabled()) {
-                cache.getLogger().fine("InterruptedException in join of getThread");
-              }
-            }
-          }
-        };
-
-    return (CacheSerializableRunnable) getAndClear;
-  }
-
-  /**
-   *
-   * getThread
-   *
-   */
-  protected class getThread implements Runnable {
-    LocalRegion region = null;
-
-    getThread(LocalRegion rgn) {
-      super();
-      this.region = rgn;
-    }
-
-    public void run() {
-
-      SearchLoadAndWriteProcessor processor = SearchLoadAndWriteProcessor.getProcessor();
-      processor.initialize((LocalRegion) region, "key1", null);
-      processor.testNetSearchMessageDoGet(region.getName(), "key1", 1500, 1500, 1500);
-    }
-  }
-
-  /**
-   * This method verifies that region is not destroyed
-   *
-   * @return CacheSerializableRunnable
-   */
-  private CacheSerializableRunnable verifyRegionNotDestroyed() {
-    SerializableRunnable verifyR = new CacheSerializableRunnable("verifyRegionNotDestroyed") {
-      public void run2() {
-        assertTrue("Cache is found as null ", cache != null);
-        Region region = cache.getRegion(regionName);
-        assertTrue("Region was destroyed", region != null);
-      }
-    };
-    return (CacheSerializableRunnable) verifyR;
-  }
-
-  /**
-   * This method destroys the Region
-   *
-   * @return CacheSerializableRunnable
-   */
-  private CacheSerializableRunnable destroyRegion() {
-    SerializableRunnable destroyR = new CacheSerializableRunnable("destroyRegion") {
-      public void run2() {
-        try {
-          assertTrue("Cache is found as null ", cache != null);
-
-          Region rgn = cache.getRegion(regionName);
-          rgn.localDestroyRegion();
-          cache.close();
-        } catch (Exception ex) {
-
-        }
-      }
-    };
-    return (CacheSerializableRunnable) destroyR;
-  }
-
-  /**
-   * The Clear operation during a NetSearchMessage.doGet() in progress can cause DiskAccessException
-   * by accessing cleared oplogs and eventually destroy region. The Test verifies that fix prevents
-   * this.
-   */
-
-  @Test
-  public void testQueryGetWithClear() {
-    IgnoredException.addIgnoredException("Entry has been cleared and is not present on disk");
-    // create region in VM0
-    vm0.invoke(createCacheForVM0());
-    // Do puts to region.
-    vm0.invoke(putSomeEntries());
-    // call NetSearchMessage.doGet() after region.clear()
-    vm0.invoke(concurrentNetSearchGetAndClear());
-    // verify that region is not destroyed
-    vm0.invoke(verifyRegionNotDestroyed());
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringNetSearchOplogRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringNetSearchOplogRegressionTest.java
new file mode 100755
index 0000000..ff6674a
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringNetSearchOplogRegressionTest.java
@@ -0,0 +1,205 @@
+/*
+ * 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.EvictionAttributes.createLRUEntryAttributes;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+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.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.internal.cache.SearchLoadAndWriteProcessor.NetSearchRequestMessage;
+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;
+
+/**
+ * The Clear operation during a NetSearchMessage.doGet() in progress can cause DiskAccessException
+ * by accessing cleared oplogs and eventually destroy region. The Test verifies that fix prevents
+ * this.
+ *
+ * <p>
+ * Test must be DistributedTest because it requires ClusterDistributionManager.
+ *
+ * <p>
+ * TRAC #40299: Suspect String - DiskAccessException : Data for DiskEntry could not be obtained
+ * from Disk. A clear operation may have deleted the oplogs (logged as error)
+ */
+@Category(DistributedTest.class)
+public class ClearDuringNetSearchOplogRegressionTest extends CacheTestCase {
+
+  private String uniqueName;
+  private String regionName;
+  private File[] diskDirs;
+  private transient CacheObserver observer;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    regionName = uniqueName;
+
+    diskDirs = new File[] {temporaryFolder.newFolder(uniqueName)};
+
+    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
+
+    observer = spy(CacheObserver.class);
+
+    addIgnoredException("Entry has been cleared and is not present on disk");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  /**
+   * The Clear operation during a NetSearchMessage.doGet() in progress can cause DiskAccessException
+   * by accessing cleared oplogs and eventually destroy region. The Test verifies that fix prevents
+   * this.
+   */
+  @Test
+  public void testQueryGetWithClear() throws Exception {
+    // create region
+    createCacheForVM0();
+
+    // Do puts to region
+    putSevenEntries();
+
+    // call NetSearchMessage.doGet() after region.clear()
+    concurrentNetSearchGetAndClear();
+
+    // verify that region is not destroyed
+    verifyRegionNotDestroyed();
+  }
+
+  private void createCacheForVM0() {
+    DiskStoreFactory diskStoreFactory = getCache().createDiskStoreFactory();
+    diskStoreFactory.setDiskDirsAndSizes(diskDirs, new int[] {Integer.MAX_VALUE});
+    diskStoreFactory.setQueueSize(1);
+    diskStoreFactory.setMaxOplogSize(60); // does the test want 60 bytes or 60M?
+    diskStoreFactory.setAutoCompact(false).setTimeInterval(1000);
+
+    DiskStore diskStore = diskStoreFactory.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+    factory.setEvictionAttributes(createLRUEntryAttributes(2, EvictionAction.OVERFLOW_TO_DISK));
+
+    getCache().createRegion(regionName, factory.create());
+  }
+
+  private void putSevenEntries() {
+    Region<String, Integer> region = getCache().getRegion(regionName);
+    for (int i = 0; i < 7; i++) {
+      region.put("key" + i, i);
+    }
+  }
+
+  private void concurrentNetSearchGetAndClear() throws InterruptedException {
+    InternalRegion region = (InternalRegion) getCache().getRegion(regionName);
+    assertThat(region.size()).isEqualTo(7);
+
+    Thread getter = new Thread(new Getter(region));
+
+    region.getDiskRegion().acquireWriteLock();
+    try {
+      doConcurrentNetSearchGetAndClear(getter, region);
+    } finally {
+      region.getDiskRegion().releaseWriteLock();
+    }
+
+    // allow getThread to join to set getAfterClearSuccessful
+    getter.join();
+  }
+
+  private void doConcurrentNetSearchGetAndClear(Thread getter, InternalRegion region) {
+    CacheObserverHolder.setInstance(observer);
+
+    // start getThread
+    getter.start();
+
+    await().atMost(1, MINUTES).until(() -> verify(observer, times(1)).afterSettingDiskRef());
+
+    // This test appears to be testing a problem with the non-RVV
+    // based clear. So we'll use that functionality here.
+    // Region.clear uses an RVV, and will deadlock if called while
+    // the write lock is held.
+    RegionEventImpl regionEvent = new RegionEventImpl(region, Operation.REGION_CLEAR, null, false,
+        region.getMyId(), region.generateEventID());
+
+    // clearRegion to remove entry that getter has reference of
+    ((LocalRegion) region).cmnClearRegion(regionEvent, true, false);
+  }
+
+  private void verifyRegionNotDestroyed() {
+    Region region = getCache().getRegion(regionName);
+    assertThat(region).isNotNull();
+    assertThat(region.isDestroyed()).isFalse();
+  }
+
+  private static class Getter implements Runnable {
+
+    private final InternalRegion region;
+
+    Getter(InternalRegion region) {
+      super();
+      this.region = region;
+    }
+
+    @Override
+    public void run() {
+      SearchLoadAndWriteProcessor processor = SearchLoadAndWriteProcessor.getProcessor();
+      processor.initialize((LocalRegion) region, "key1", null);
+      sendNetSearchRequestMessage(processor, "key1", 1500, 1500, 1500);
+    }
+
+    private void sendNetSearchRequestMessage(SearchLoadAndWriteProcessor processor, Object key,
+        int timeoutMillis, int ttlMillis, int idleMillis) {
+      NetSearchRequestMessage message = new SearchLoadAndWriteProcessor.NetSearchRequestMessage();
+      message.initialize(processor, region.getName(), key, timeoutMillis, ttlMillis, idleMillis);
+      message.doGet((ClusterDistributionManager) region.getDistributionManager());
+    }
+  }
+}

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

[geode] 02/19: GEODE-1279: Rename Bug33726JUnitTest as AfterRegionCreateNotBeforeRegionInitRegressionTest

Posted by kl...@apache.org.
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 0618d54dc1ea5ea2a75406918f404bc76b016eab
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Tue Mar 20 13:43:59 2018 -0700

    GEODE-1279: Rename Bug33726JUnitTest as AfterRegionCreateNotBeforeRegionInitRegressionTest
    
    General fixup of test to use Awaitility and ErrorCollector.
---
 ...ionCreateNotBeforeRegionInitRegressionTest.java |  94 ++++++++++++++++++
 .../geode/internal/cache/Bug33726JUnitTest.java    | 110 ---------------------
 2 files changed, 94 insertions(+), 110 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java
new file mode 100755
index 0000000..985f42f
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.CoreMatchers.is;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ErrorCollector;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * AFTER_REGION_CREATE was being sent before region initialization (bug 33726). Test to verify that
+ * that is no longer the case.
+ *
+ * <p>
+ * TRAC #33726: afterRegionCreate event delivered before region initialization occurs
+ */
+@Category(IntegrationTest.class)
+public class AfterRegionCreateNotBeforeRegionInitRegressionTest {
+
+  private Cache cache;
+  private TestCacheListener cacheListener;
+
+  @Rule
+  public ErrorCollector errorCollector = new ErrorCollector();
+
+  @Before
+  public void setUp() {
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+    cacheListener = new TestCacheListener();
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void testAfterRegionCreate() throws Exception {
+    AttributesFactory factory = new AttributesFactory();
+    factory.setCacheListener(cacheListener);
+
+    Region region = cache.createRegion("testRegion", factory.create());
+    region.createSubregion("testSubRegion", factory.create());
+
+    await().atMost(1, MINUTES)
+        .until(() -> assertThat(cacheListener.afterRegionCreateCount.get()).isEqualTo(2));
+  }
+
+  private class TestCacheListener extends CacheListenerAdapter {
+
+    final AtomicInteger afterRegionCreateCount = new AtomicInteger();
+
+    @Override
+    public void afterRegionCreate(RegionEvent event) {
+      InternalRegion region = (InternalRegion) event.getRegion();
+      String regionPath = event.getRegion().getFullPath();
+      if (regionPath.contains("/testRegion/testSubRegion") || regionPath.contains("/testRegion")) {
+        afterRegionCreateCount.incrementAndGet();
+        errorCollector.checkThat(region.isInitialized(), is(true));
+      }
+    }
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java
deleted file mode 100755
index 09e0b9a..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java
+++ /dev/null
@@ -1,110 +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.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.fail;
-
-import java.util.Properties;
-
-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.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionEvent;
-import org.apache.geode.cache.util.CacheListenerAdapter;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * AFTER_REGION_CREATE was being sent before region initialization (bug 33726). Test to verify that
- * that is no longer the case.
- *
- */
-@Category(IntegrationTest.class)
-public class Bug33726JUnitTest {
-
-  private boolean[] flags = new boolean[2];
-
-  private static boolean isOK = false;
-
-  @Test
-  public void testAfterRegionCreate() {
-    Properties props = new Properties();
-    props.put(MCAST_PORT, "0");
-    DistributedSystem ds = DistributedSystem.connect(props);
-    AttributesFactory factory = new AttributesFactory();
-    factory.setCacheListener(new TestCacheListener());
-    Cache cache = null;
-    try {
-      cache = CacheFactory.create(ds);
-
-      Region region = cache.createRegion("testRegion", factory.create());
-      region.createSubregion("testSubRegion", factory.create());
-    } catch (Exception e) {
-      fail("Failed to create cache due to " + e);
-      e.printStackTrace();
-    }
-
-
-    if (!testFlag()) {
-      fail("After create sent although region was not initialized");
-    }
-  }
-
-  public boolean testFlag() {
-    if (isOK) {
-      return isOK;
-    } else {
-      synchronized (Bug33726JUnitTest.class) {
-        if (isOK) {
-          return isOK;
-        } else {
-          try {
-            Bug33726JUnitTest.class.wait(120000);
-          } catch (InterruptedException ie) {
-            fail("interrupted");
-          }
-        }
-      }
-      return isOK;
-    }
-  }
-
-  protected class TestCacheListener extends CacheListenerAdapter {
-
-    public void afterRegionCreate(RegionEvent event) {
-      Region region = event.getRegion();
-      if (((LocalRegion) region).isInitialized()) {
-        String regionPath = event.getRegion().getFullPath();
-        if (regionPath.indexOf("/testRegion/testSubRegion") >= 0) {
-          flags[1] = true;
-        } else if (regionPath.indexOf("/testRegion") >= 0) {
-          flags[0] = true;
-        }
-
-      }
-      if (flags[0] && flags[1]) {
-        isOK = true;
-        synchronized (Bug33726JUnitTest.class) {
-          Bug33726JUnitTest.class.notify();
-        }
-      }
-    }
-  }
-}

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

[geode] 14/19: GEODE-1279: Rename Bug41957DUnitTest as RegisterInterestWithEvictionRegressionTest

Posted by kl...@apache.org.
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 735b8551577f68fa20938e64fa8864ec1c1403ff
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Mar 22 20:37:01 2018 -0700

    GEODE-1279: Rename Bug41957DUnitTest as RegisterInterestWithEvictionRegressionTest
---
 .../geode/internal/cache/Bug41957DUnitTest.java    | 165 ---------------------
 ...RegisterInterestWithEvictionRegressionTest.java | 144 ++++++++++++++++++
 2 files changed, 144 insertions(+), 165 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41957DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41957DUnitTest.java
deleted file mode 100644
index 301c0f5..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41957DUnitTest.java
+++ /dev/null
@@ -1,165 +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.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.InterestPolicy;
-import org.apache.geode.cache.InterestResultPolicy;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.SubscriptionAttributes;
-import org.apache.geode.cache.client.PoolFactory;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache30.CacheSerializableRunnable;
-import org.apache.geode.cache30.ClientServerTestCase;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.DistributedTestUtils;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.junit.categories.ClientServerTest;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Test for bug 41957. Basic idea is to have a client with a region with a low eviction limit do a
- * register interest with key&values and see if we end up with more entries in the client than the
- * eviction limit.
- *
- * @since GemFire 6.5
- */
-@Category({DistributedTest.class, ClientServerTest.class})
-public class Bug41957DUnitTest extends ClientServerTestCase {
-
-  @Override
-  public final void postTearDownCacheTestCase() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Test
-  public void testBug41957() {
-    final Host host = Host.getHost(0);
-    final VM server = host.getVM(0);
-    final VM client = host.getVM(1);
-    final String regionName = getUniqueName();
-    final int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    final String serverHost = NetworkUtils.getServerHostName(server.getHost());
-
-    createBridgeServer(server, regionName, serverPort, false);
-
-    createBridgeClient(client, regionName, serverHost, new int[] {serverPort});
-
-    client.invoke(new CacheSerializableRunnable("register interest") {
-      public void run2() throws CacheException {
-        Region region = getRootRegion(regionName);
-        int ENTRIES_ON_SERVER = 10;
-        for (int i = 1; i <= ENTRIES_ON_SERVER; i++) {
-          region.registerInterest("k" + i, InterestResultPolicy.KEYS_VALUES);
-        }
-        assertEquals(2, region.size());
-      }
-    });
-
-    stopBridgeServer(server);
-  }
-
-  private void createBridgeServer(VM server, final String regionName, final int serverPort,
-      final boolean createPR) {
-    server.invoke(new CacheSerializableRunnable("Create server") {
-      public void run2() throws CacheException {
-        // Create DS
-        Properties config = new Properties();
-        config.setProperty(LOCATORS,
-            "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
-        getSystem(config);
-
-        // Create Region
-        AttributesFactory factory = new AttributesFactory();
-        factory.setCacheLoader(new CacheServerCacheLoader());
-        if (createPR) {
-          factory.setDataPolicy(DataPolicy.PARTITION);
-          factory.setPartitionAttributes((new PartitionAttributesFactory()).create());
-        } else {
-          factory.setScope(Scope.DISTRIBUTED_ACK);
-          factory.setDataPolicy(DataPolicy.REPLICATE);
-        }
-        Region region = createRootRegion(regionName, factory.create());
-        if (createPR) {
-          assertTrue(region instanceof PartitionedRegion);
-        }
-        int ENTRIES_ON_SERVER = 10;
-        for (int i = 1; i <= ENTRIES_ON_SERVER; i++) {
-          region.create("k" + i, "v" + i);
-        }
-        try {
-          startBridgeServer(serverPort);
-        } catch (Exception e) {
-          Assert.fail("While starting CacheServer", e);
-        }
-      }
-    });
-  }
-
-  private void createBridgeClient(VM client, final String regionName, final String serverHost,
-      final int[] serverPorts) {
-    client.invoke(new CacheSerializableRunnable("Create client") {
-      public void run2() throws CacheException {
-        // Create DS
-        Properties config = new Properties();
-        config.setProperty(MCAST_PORT, "0");
-        config.setProperty(LOCATORS, "");
-        getSystem(config);
-
-        // Create Region
-        AttributesFactory factory = new AttributesFactory();
-        factory.setScope(Scope.LOCAL);
-        {
-          PoolFactory pf = PoolManager.createFactory();
-          pf.setSubscriptionEnabled(true);
-          for (int i = 0; i < serverPorts.length; i++) {
-            pf.addServer(serverHost, serverPorts[i]);
-          }
-          pf.create("myPool");
-        }
-        int ENTRIES_ON_CLIENT = 2;
-        factory.setPoolName("myPool");
-        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
-        factory
-            .setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(ENTRIES_ON_CLIENT));
-        createRootRegion(regionName, factory.create());
-      }
-    });
-  }
-
-  private void stopBridgeServer(VM server) {
-    server.invoke(new CacheSerializableRunnable("Stop Server") {
-      public void run2() throws CacheException {
-        stopBridgeServers(getCache());
-      }
-    });
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RegisterInterestWithEvictionRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/RegisterInterestWithEvictionRegressionTest.java
new file mode 100644
index 0000000..e632d06
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/RegisterInterestWithEvictionRegressionTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.apache.geode.cache.EvictionAttributes.createLRUEntryAttributes;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+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.InterestPolicy;
+import org.apache.geode.cache.InterestResultPolicy;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.SubscriptionAttributes;
+import org.apache.geode.cache.client.PoolFactory;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache30.ClientServerTestCase;
+import org.apache.geode.test.dunit.NetworkUtils;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * Test for bug 41957. Basic idea is to have a client with a region with a low eviction limit do a
+ * register interest with key and values and see if we end up with more entries in the client than
+ * the eviction limit.
+ *
+ * <p>
+ * TRAC #41957: Interaction between registerInterest and eviction produces incorrect number of
+ * entries in region
+ *
+ * @since GemFire 6.5
+ */
+@Category({DistributedTest.class, ClientServerTest.class})
+public class RegisterInterestWithEvictionRegressionTest extends ClientServerTestCase {
+
+  private static final int ENTRIES_ON_SERVER = 10;
+  private static final int ENTRIES_ON_CLIENT = 2;
+
+  private String uniqueName;
+  private String hostName;
+  private int serverPort;
+
+  private VM server;
+  private VM client;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server = getHost(0).getVM(0);
+    client = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    hostName = NetworkUtils.getServerHostName(server.getHost());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  @Test
+  public void registerInterestKeysValuesShouldHonorEvictionLimit() {
+    serverPort = server.invoke(() -> createServer());
+    client.invoke(() -> createClient());
+
+    client.invoke(() -> {
+      Region region = getRootRegion(uniqueName);
+      for (int i = 1; i <= ENTRIES_ON_SERVER; i++) {
+        region.registerInterest("k" + i, InterestResultPolicy.KEYS_VALUES);
+      }
+      assertThat(region.size()).isEqualTo(2);
+    });
+
+    server.invoke(() -> stopServer());
+  }
+
+  private int createServer() throws IOException {
+    AttributesFactory factory = new AttributesFactory();
+    factory.setCacheLoader(new CacheServerCacheLoader());
+    factory.setDataPolicy(DataPolicy.REPLICATE);
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+
+    Region region = createRootRegion(uniqueName, factory.create());
+
+    for (int i = 1; i <= ENTRIES_ON_SERVER; i++) {
+      region.create("k" + i, "v" + i);
+    }
+
+    return startBridgeServer(0);
+  }
+
+  private void createClient() {
+    Properties config = new Properties();
+    config.setProperty(MCAST_PORT, "0");
+    config.setProperty(LOCATORS, "");
+    getCache(config);
+
+    PoolFactory pf = PoolManager.createFactory();
+    pf.setSubscriptionEnabled(true);
+    pf.addServer(hostName, serverPort);
+    pf.create(uniqueName);
+
+    // Create Region
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.LOCAL);
+
+    factory.setPoolName(uniqueName);
+    factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
+    factory.setEvictionAttributes(createLRUEntryAttributes(ENTRIES_ON_CLIENT));
+    createRootRegion(uniqueName, factory.create());
+  }
+
+  private void stopServer() {
+    stopBridgeServers(getCache());
+  }
+}

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

[geode] 06/19: GEODE-1279: Rename Bug37241DUnitTest as CleanupFailedInitWithDiskFilesRegressionTest

Posted by kl...@apache.org.
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 8009a1203ffc30c5d3c7b0d6c7652afdaae6353b
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Wed Mar 21 13:28:03 2018 -0700

    GEODE-1279: Rename Bug37241DUnitTest as CleanupFailedInitWithDiskFilesRegressionTest
---
 .../geode/internal/cache/Bug37241DUnitTest.java    | 205 ---------------------
 ...eanupFailedInitWithDiskFilesRegressionTest.java | 161 ++++++++++++++++
 2 files changed, 161 insertions(+), 205 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37241DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37241DUnitTest.java
deleted file mode 100755
index 8aec85b..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37241DUnitTest.java
+++ /dev/null
@@ -1,205 +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 java.io.File;
-import java.util.Arrays;
-import java.util.Properties;
-
-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.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.ReplyException;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Confirms the bug 37241 is fixed. CleanupFailedInitialization on should also clean disk files
- * created
- */
-@Category(DistributedTest.class)
-public class Bug37241DUnitTest extends JUnit4DistributedTestCase {
-
-  private static Cache cache = null;
-
-  static VM server1 = null;
-
-  static VM server2 = null;
-
-  private static final String REGION_NAME = "Bug37241DUnitTest_region";
-
-  static final String expectedReplyException = ReplyException.class.getName();
-
-  static final String expectedException = IllegalStateException.class.getName();
-
-  @Override
-  public final void postSetUp() throws Exception {
-    final Host host = Host.getHost(0);
-    server1 = host.getVM(0);
-    server2 = host.getVM(1);
-  }
-
-  /*
-   * 1.Create persistent region serevr1 with scope global. 2.Try to create persitent region with
-   * same name on server2 with scope d-ack. 3.Region creation should fail . Check for all files
-   * created in the directory for server 2 gets deleted.
-   */
-  @Test
-  public void testBug37241ForNewDiskRegion() {
-    server1.invoke(() -> Bug37241DUnitTest.createRegionOnServer1());
-
-    try {
-      server2.invoke(() -> Bug37241DUnitTest.createRegionOnServer2(Scope.DISTRIBUTED_ACK));
-    } catch (Exception e) {
-      server2.invoke(() -> Bug37241DUnitTest.ignoreExceptionInLogs());
-      server2.invoke(() -> Bug37241DUnitTest.checkForCleanup());
-    }
-  }
-
-  @Test
-  public void testBug37241ForRecreatedDiskRegion() {
-    server1.invoke(() -> Bug37241DUnitTest.createRegionOnServer1());
-    server2.invoke(() -> Bug37241DUnitTest.createRegionOnServer2(Scope.GLOBAL));
-    server2.invoke(() -> Bug37241DUnitTest.closeRegion());
-    try {
-      server2.invoke(() -> Bug37241DUnitTest.createRegionOnServer2(Scope.DISTRIBUTED_ACK));
-    } catch (Exception e) {
-      server2.invoke(() -> Bug37241DUnitTest.ignoreExceptionInLogs());
-      server2.invoke(() -> Bug37241DUnitTest.checkForCleanupAfterRecreation());
-    }
-  }
-
-  private void createCache(Properties props) throws Exception {
-    DistributedSystem ds = getSystem(props);
-    ds.disconnect();
-    ds = getSystem(props);
-    assertNotNull(ds);
-    cache = CacheFactory.create(ds);
-    assertNotNull(cache);
-  }
-
-  public static void createRegionOnServer1() throws Exception {
-    new Bug37241DUnitTest().createCache(new Properties());
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.GLOBAL);
-    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-
-    File[] dirs = new File[2];
-    File file1 = new File("server1_disk1");
-    File file2 = new File("server1_disk2");
-    file1.mkdir();
-    file2.mkdir();
-    dirs[0] = file1;
-    dirs[1] = file2;
-    factory.setDiskSynchronous(false);
-    factory.setDiskStoreName(
-        cache.createDiskStoreFactory().setDiskDirs(dirs).create("Bug37241DUnitTest").getName());
-    RegionAttributes attrs = factory.create();
-    cache.createRegion(REGION_NAME, attrs);
-  }
-
-  public static void createRegionOnServer2(Scope scope) throws Exception {
-    new Bug37241DUnitTest().createCache(new Properties());
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(scope);
-    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-
-    File[] dirs = new File[2];
-    File file1 = new File("server2_disk1");
-    File file2 = new File("server2_disk2");
-    file1.mkdir();
-    file2.mkdir();
-    dirs[0] = file1;
-    dirs[1] = file2;
-    factory.setDiskSynchronous(false);
-    factory.setDiskStoreName(
-        cache.createDiskStoreFactory().setDiskDirs(dirs).create("Bug37241DUnitTest").getName());
-
-    // added for not to log exepected IllegalStateExcepion.
-    LogWriterUtils.getLogWriter()
-        .info("<ExpectedException action=add>" + expectedReplyException + "</ExpectedException>");
-    LogWriterUtils.getLogWriter()
-        .info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
-    cache.getLogger()
-        .info("<ExpectedException action=add>" + expectedReplyException + "</ExpectedException>");
-    cache.getLogger()
-        .info("<ExpectedException action=add>" + expectedException + "</ExpectedException>");
-
-    RegionAttributes attrs = factory.create();
-    cache.createRegion(REGION_NAME, attrs);
-
-  }
-
-  public static void checkForCleanup() {
-    try {
-      Thread.sleep(200);
-    } catch (InterruptedException ignore) {
-    }
-    cache.getLogger()
-        .info("checkForCleanup=" + Arrays.asList(new File("server2_disk2").listFiles()));
-    assertEquals(0, new File("server2_disk2").listFiles().length);
-  }
-
-
-  public static void checkForCleanupAfterRecreation() {
-    checkForCleanup();
-  }
-
-  public static void ignoreExceptionInLogs() {
-
-    cache.getLogger()
-        .info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
-
-    cache.getLogger().info(
-        "<ExpectedException action=remove>" + expectedReplyException + "</ExpectedException>");
-    LogWriterUtils.getLogWriter()
-        .info("<ExpectedException action=remove>" + expectedException + "</ExpectedException>");
-    LogWriterUtils.getLogWriter().info(
-        "<ExpectedException action=remove>" + expectedReplyException + "</ExpectedException>");
-  }
-
-  public static void closeRegion() {
-    Cache cache = CacheFactory.getAnyInstance();
-    Region region = cache.getRegion("/" + REGION_NAME);
-    region.close();
-  }
-
-  public static void closeCache() {
-    if (cache != null && !cache.isClosed()) {
-      cache.close();
-      cache.getDistributedSystem().disconnect();
-    }
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    server1.invoke(() -> Bug37241DUnitTest.closeCache());
-    server2.invoke(() -> Bug37241DUnitTest.closeCache());
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/CleanupFailedInitWithDiskFilesRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/CleanupFailedInitWithDiskFilesRegressionTest.java
new file mode 100755
index 0000000..a276800
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/CleanupFailedInitWithDiskFilesRegressionTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.awaitility.Awaitility.await;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+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.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.distributed.internal.ReplyException;
+import org.apache.geode.test.dunit.RMIException;
+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;
+
+/**
+ * Confirms the bug 37241 is fixed. CleanupFailedInitialization on should also clean disk files
+ * created
+ *
+ * <p>
+ * TRAC #37241: cleanupFailedInitialization on should also clean disk files created
+ */
+@Category(DistributedTest.class)
+public class CleanupFailedInitWithDiskFilesRegressionTest extends CacheTestCase {
+
+  private String uniqueName;
+  private File[] foldersForServer1;
+  private File[] foldersForServer2;
+  private File server2Disk2;
+
+  private VM server1;
+  private VM server2;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server1 = getHost(0).getVM(0);
+    server2 = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    File server1Disk1 = temporaryFolder.newFolder(uniqueName + "_server1_disk1");
+    File server1Disk2 = temporaryFolder.newFolder(uniqueName + "_server1_disk2");
+    foldersForServer1 = new File[] {server1Disk1, server1Disk2};
+
+    File server2Disk1 = temporaryFolder.newFolder(uniqueName + "_server2_disk1");
+    server2Disk2 = temporaryFolder.newFolder(uniqueName + "_server2_disk2");
+    foldersForServer2 = new File[] {server2Disk1, server2Disk2};
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  /**
+   * 1. Create persistent region server1 with scope global.
+   * <p>
+   * 2. Try to create persistent region with same name on server2 with scope d-ack.
+   * <p>
+   * 3. Region creation should fail. Check for all files created in the directory for server 2 gets
+   * deleted.
+   */
+  @Test
+  public void newDiskRegionShouldBeCleanedUp() {
+    server1.invoke(() -> createRegionOnServer1());
+
+    assertThatThrownBy(() -> server2.invoke(() -> createRegionOnServer2(Scope.DISTRIBUTED_ACK)))
+        .isInstanceOf(RMIException.class).hasCauseInstanceOf(IllegalStateException.class);
+
+    addIgnoredException(IllegalStateException.class);
+    addIgnoredException(ReplyException.class);
+    server2.invoke(() -> validateCleanupOfDiskFiles());
+  }
+
+  @Test
+  public void recreatedDiskRegionShouldBeCleanedUp() {
+    server1.invoke(() -> createRegionOnServer1());
+    server2.invoke(() -> createRegionOnServer2(Scope.GLOBAL));
+    server2.invoke(() -> closeRegion());
+
+    assertThatThrownBy(() -> server2.invoke(() -> createRegionOnServer2(Scope.DISTRIBUTED_ACK)))
+        .isInstanceOf(RMIException.class).hasCauseInstanceOf(IllegalStateException.class);
+
+    addIgnoredException(IllegalStateException.class);
+    addIgnoredException(ReplyException.class);
+    server2.invoke(() -> validateCleanupOfDiskFiles());
+  }
+
+  private void createRegionOnServer1() {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(foldersForServer1);
+
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.GLOBAL);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+
+    getCache().createRegion(uniqueName, factory.create());
+  }
+
+  private void createRegionOnServer2(Scope scope) {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(foldersForServer2);
+
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(scope);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+
+    getCache().createRegion(uniqueName, factory.create());
+  }
+
+  private void closeRegion() {
+    getCache().getRegion(uniqueName).close();
+  }
+
+  private void validateCleanupOfDiskFiles() {
+    await().atMost(1, MINUTES).until(() -> assertThat(server2Disk2.listFiles()).hasSize(0));
+  }
+}

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

[geode] 08/19: GEODE-1279: Rename Bug37500JUnitTest as DiskAccessExceptionDisablesServerRegressionTest

Posted by kl...@apache.org.
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 10eabfb3a89b8996aeeee2786a1f2c988bbfbf85
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Wed Mar 21 16:38:25 2018 -0700

    GEODE-1279: Rename Bug37500JUnitTest as DiskAccessExceptionDisablesServerRegressionTest
---
 .../geode/internal/cache/Bug37500JUnitTest.java    | 163 --------------
 ...ccessExceptionDisablesServerRegressionTest.java | 241 +++++++++++++++++++++
 2 files changed, 241 insertions(+), 163 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37500JUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37500JUnitTest.java
deleted file mode 100644
index a65b30f..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37500JUnitTest.java
+++ /dev/null
@@ -1,163 +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 static org.junit.Assert.fail;
-
-import java.io.File;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.Scope;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * This is a bugtest for bug 37500.
- *
- *
- */
-@Category(IntegrationTest.class)
-public class Bug37500JUnitTest extends DiskRegionTestingBase {
-
-  /** The disk region configuration object for the test */
-  private DiskRegionProperties diskProps = new DiskRegionProperties();
-
-  /** The key for entry1 */
-  static final String KEY1 = "KEY1";
-
-  /** The key for entry2 */
-  static final String KEY2 = "KEY2";
-
-  /** Boolean to indicate the roller thread to proceed */
-  static volatile boolean proceedForRolling = false;
-
-  /**
-   * Boolean to decide whether we want to allow roller to run ( used via CacheObserver callback
-   */
-  static volatile boolean notifyRoller = false;
-
-  /**
-   * This test does the following: <br>
-   * 1. Create a disk-region with following configurations :
-   * <li>dirSize = 2000 bytes
-   * <li>maxOplogSize = 500 bytes
-   * <li>rolling = true
-   * <li>syncMode = true
-   * <li>approx size on disk for operations = 440 bytes<br>
-   *
-   * 2.Make Roller go into WAIT state via CacheObserverAdapter.beforeGoingToCompact callback<br>
-   * 3.Put 440 bytes , it will go in oplog1 <br>
-   * 4.Put another 440 bytes ,it will go in oplog1<br>
-   * 5.Put 440 bytes , switching will be caused, it will go in oplog2, Roller will remained blocked
-   * (step 2)<br>
-   * 6.Put 440 bytes , it will go in oplog2, oplog2 will now be full<br>
-   * 7.Notify the Roller and put 440 bytes , this will try further switching. The put will fail with
-   * exception due to bug 37500. The put thread takes an entry level lock for entry2 ( the one with
-   * KEY2) and tries to write to disk but there is no free space left, so it goes into wait,
-   * expecting Roller to free up the space. The roller, which has now been notified to run, tries to
-   * roll entry2 for which it seeks entry level lock which has been acquired by put-thread. So the
-   * put thread eventually comes out of the wait with DiskAccessException<br>
-   *
-   * Another scenario for this bug is, once the disk space was getting exhausted , the entry
-   * operation threads which had already taken a lock on Entry got stuck trying to seek the Oplog
-   * Lock. The switching thread had acquired the Oplog.lock & was waiting for the roller thread to
-   * free disk space. Since the roller needed to acquire Entry lock to roll, it was unable to do so
-   * because of entry operation threads. This would cause the entry operation threads to get
-   * DiskAccessException after completing the stipulated wait. The Roller was able to free space
-   * only when it has rolled all the relevant entries which could happen only when the entry
-   * operation threads released the entry lock after getting DiskAccessException.
-   *
-   *
-   * @throws Exception
-   */
-  @Test
-  public void testBug37500() throws Exception {
-    final int MAX_OPLOG_SIZE = 1000;
-    diskProps.setMaxOplogSize(MAX_OPLOG_SIZE);
-    diskProps.setPersistBackup(true);
-    diskProps.setRolling(true);
-    diskProps.setSynchronous(false);
-
-    File testdir = new File("bug37500-diskDir");
-    testdir.mkdir();
-    testdir.deleteOnExit();
-    diskProps.setDiskDirsAndSizes(new File[] {testdir}, new int[] {2000});
-
-    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
-
-    region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL);
-    CacheObserver old = CacheObserverHolder.setInstance(new CacheObserverAdapter() {
-      public void beforeGoingToCompact() {
-        if (!proceedForRolling) {
-          synchronized (Bug37500JUnitTest.class) {
-            if (!proceedForRolling) {
-              try {
-                cache.getLogger().info("beforeGoingToCompact :: going into wait");
-                Bug37500JUnitTest.class.wait();
-              } catch (InterruptedException e) {
-                cache.getLogger().info("Roller interrupted");
-                fail("interrupted");
-              }
-              cache.getLogger().info("beforeGoingToCompact :: coming out of wait");
-            }
-          }
-        }
-      }
-
-      public void beforeSwitchingOplog() {
-        if (notifyRoller) {
-          cache.getLogger().info("beforeSwitchingOplog :: going to notify Roller");
-          synchronized (Bug37500JUnitTest.class) {
-            proceedForRolling = true;
-            Bug37500JUnitTest.class.notify();
-            cache.getLogger().info("beforeSwitchingOplog :: notified the Roller");
-          }
-        }
-
-      }
-    });
-
-    cache.getLogger().info("goin to put no. 1");
-    // put 440 bytes , it will go in oplog1
-    region.put(KEY1, new byte[420]);
-
-    cache.getLogger().info("goin to put no. 2");
-    // put another 440 bytes ,it will go in oplog1
-    region.put(KEY2, new byte[420]);
-
-    cache.getLogger().info("goin to put no. 3");
-    // put 440 bytes , switching will be caused, it will go in oplog2 (value
-    // size increased to 432 as key wont be written to disk for UPDATE)
-    region.put(KEY1, new byte[432]);
-
-    cache.getLogger().info("goin to put no. 4");
-    // put 440 bytes , it will go in oplog2
-    region.put(KEY1, new byte[432]);
-
-    notifyRoller = true;
-    cache.getLogger().info("goin to put no. 5");
-    // put 440 bytes , this will try further switching
-    region.put(KEY2, new byte[432]);
-
-    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
-    CacheObserverHolder.setInstance(old);
-    closeDown();
-  }
-
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/DiskAccessExceptionDisablesServerRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskAccessExceptionDisablesServerRegressionTest.java
new file mode 100644
index 0000000..6104204
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskAccessExceptionDisablesServerRegressionTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+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;
+
+/**
+ * This is a bugtest for bug 37500.
+ *
+ * <p>
+ * TRAC #37500: A DiskAccessException brings cache server to a stall
+ *
+ * <pre>
+ * com.gemstone.gemfire.cache.DiskAccessException:  Unable to get free space for creating an oplog after waiting for 20 seconds
+ *     at com.gemstone.gemfire.internal.cache.ComplexDiskRegion.getNextDir(ComplexDiskRegion.java:150)
+ *     at com.gemstone.gemfire.internal.cache.Oplog.switchOpLog(Oplog.java:2020)
+ *     at com.gemstone.gemfire.internal.cache.Oplog.basicModify(Oplog.java:2423)
+ *     at com.gemstone.gemfire.internal.cache.Oplog.modify(Oplog.java:2339)
+ *     at com.gemstone.gemfire.internal.cache.DiskRegion.put(DiskRegion.java:321)
+ *     at com.gemstone.gemfire.internal.cache.DiskEntry$Helper.writeToDisk(DiskEntry.java:362)
+ *     at com.gemstone.gemfire.internal.cache.DiskEntry$Helper.overflowToDisk(DiskEntry.java:532)
+ *     at com.gemstone.gemfire.internal.cache.AbstractLRURegionMap.evictEntry(AbstractLRURegionMap.java:164)
+ *     at com.gemstone.gemfire.internal.cache.AbstractLRURegionMap.lruUpdateCallback(AbstractLRURegionMap.java:240)
+ *     at com.gemstone.gemfire.internal.cache.AbstractRegionMap.basicPut(AbstractRegionMap.java:928)
+ *     at com.gemstone.gemfire.internal.cache.LocalRegion.virtualPut(LocalRegion.java:3605)
+ *     at com.gemstone.gemfire.internal.cache.DistributedRegion.virtualPut(DistributedRegion.java:151)
+ *     at com.gemstone.gemfire.internal.cache.LocalRegion.basicUpdate(LocalRegion.java:3591)
+ *     at com.gemstone.gemfire.internal.cache.AbstractUpdateOperation.doPutOrCreate(AbstractUpdateOperation.java:100)
+ *     at com.gemstone.gemfire.internal.cache.AbstractUpdateOperation$AbstractUpdateMessage.basicOperateOnRegion(AbstractUpdateOperation.java:171)
+ *     at com.gemstone.gemfire.internal.cache.AbstractUpdateOperation$AbstractUpdateMessage.operateOnRegion(AbstractUpdateOperation.java:154)
+ *     at com.gemstone.gemfire.internal.cache.DistributedCacheOperation$CacheOperationMessage.basicProcess(DistributedCacheOperation.java:487)
+ *     at com.gemstone.gemfire.internal.cache.DistributedCacheOperation$CacheOperationMessage.process(DistributedCacheOperation.java:404)
+ *     at com.gemstone.gemfire.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:242)
+ *     at com.gemstone.gemfire.distributed.internal.DistributionMessage.schedule(DistributionMessage.java:287)
+ *     at com.gemstone.gemfire.distributed.internal.DistributionManager.scheduleIncomingMessage(DistributionManager.java:2732)
+ *     at com.gemstone.gemfire.distributed.internal.DistributionManager.handleIncomingDMsg(DistributionManager.java:2424)
+ *     at com.gemstone.gemfire.distributed.internal.DistributionManager$MyListener.messageReceived(DistributionManager.java:3585)
+ *     at com.gemstone.gemfire.distributed.internal.membership.jgroup.JGroupMembershipManager.processMessage(JGroupMembershipManager.java:1349)
+ *     at com.gemstone.gemfire.distributed.internal.membership.jgroup.JGroupMembershipManager.handleOrDeferMessage(JGroupMembershipManager.java:1289)
+ *     at com.gemstone.gemfire.distributed.internal.membership.jgroup.JGroupMembershipManager$MyDCReceiver.messageReceived(JGroupMembershipManager.java:449)
+ *     at com.gemstone.gemfire.distributed.internal.direct.DirectChannel.receive(DirectChannel.java:535)
+ *     at com.gemstone.gemfire.internal.tcp.TCPConduit.messageReceived(TCPConduit.java:483)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.dispatchMessage(Connection.java:3026)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.processNIOBuffer(Connection.java:2861)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.runNioReader(Connection.java:1332)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.run(Connection.java:1257)
+ *     at java.lang.Thread.run(Thread.java:595)
+ * </pre>
+ */
+@Category(IntegrationTest.class)
+public class DiskAccessExceptionDisablesServerRegressionTest {
+
+  private static final int MAX_OPLOG_SIZE = 1000;
+  private static final String KEY1 = "KEY1";
+  private static final String KEY2 = "KEY2";
+
+  private Cache cache;
+  private Region<String, byte[]> region;
+  private MyCacheObserver observer;
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() throws Exception {
+    String uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    File temporaryDirectory = temporaryFolder.newFolder(uniqueName);
+
+    DirectoryHolder.SET_DIRECTORY_SIZE_IN_BYTES_FOR_TESTING_PURPOSES = true;
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = true;
+    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
+
+    observer = new MyCacheObserver();
+    CacheObserverHolder.setInstance(observer);
+
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+
+    DiskStoreFactory dsf = cache.createDiskStoreFactory();
+    dsf.setDiskDirsAndSizes(new File[] {temporaryDirectory}, new int[] {2000});
+    ((DiskStoreFactoryImpl) dsf).setMaxOplogSizeInBytes(MAX_OPLOG_SIZE);
+
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    RegionFactory<String, byte[]> regionFactory =
+        cache.createRegionFactory(RegionShortcut.LOCAL_PERSISTENT);
+    regionFactory.setDiskStoreName(diskStore.getName());
+
+    region = regionFactory.create(uniqueName);
+  }
+
+  @After
+  public void tearDown() {
+    CacheObserverHolder.setInstance(null);
+
+    DirectoryHolder.SET_DIRECTORY_SIZE_IN_BYTES_FOR_TESTING_PURPOSES = false;
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = false;
+    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
+
+    cache.close();
+  }
+
+  /**
+   * This test does the following: <br>
+   * 1. Create a disk-region with following configurations:
+   * <ul>
+   * <li>dirSize = 2000 bytes
+   * <li>maxOplogSize = 500 bytes
+   * <li>rolling = true
+   * <li>syncMode = true
+   * <li>approx size on disk for operations = 440 bytes
+   * </ul>
+   *
+   * <p>
+   * 2.Make Roller go into WAIT state via CacheObserverAdapter.beforeGoingToCompact callback
+   *
+   * <p>
+   * 3.Put 440 bytes , it will go in oplog1
+   *
+   * <p>
+   * 4.Put another 440 bytes ,it will go in oplog1
+   *
+   * <p>
+   * 5.Put 440 bytes , switching will be caused, it will go in oplog2, Roller will remained blocked
+   * (step 2)
+   *
+   * <p>
+   * 6.Put 440 bytes , it will go in oplog2, oplog2 will now be full
+   *
+   * <p>
+   * 7.Notify the Roller and put 440 bytes , this will try further switching. The put will fail with
+   * exception due to bug 37500. The put thread takes an entry level lock for entry2 ( the one with
+   * KEY2) and tries to write to disk but there is no free space left, so it goes into wait,
+   * expecting Roller to free up the space. The roller, which has now been notified to run, tries to
+   * roll entry2 for which it seeks entry level lock which has been acquired by put-thread. So the
+   * put thread eventually comes out of the wait with DiskAccessException
+   *
+   * <p>
+   * Another scenario for this bug is, once the disk space was getting exhausted , the entry
+   * operation threads which had already taken a lock on Entry got stuck trying to seek the Oplog
+   * Lock. The switching thread had acquired the Oplog.lock & was waiting for the roller thread to
+   * free disk space. Since the roller needed to acquire Entry lock to roll, it was unable to do so
+   * because of entry operation threads. This would cause the entry operation threads to get
+   * DiskAccessException after completing the stipulated wait. The Roller was able to free space
+   * only when it has rolled all the relevant entries which could happen only when the entry
+   * operation threads released the entry lock after getting DiskAccessException.
+   */
+  @Test
+  public void testBug37500() throws Exception {
+    // put 440 bytes , it will go in oplog1
+    region.put(KEY1, new byte[420]);
+
+    // put another 440 bytes ,it will go in oplog1
+    region.put(KEY2, new byte[420]);
+
+    // put 440 bytes , switching will be caused, it will go in oplog2 (value
+    // size increased to 432 as key wont be written to disk for UPDATE)
+    region.put(KEY1, new byte[432]);
+
+    // put 440 bytes , it will go in oplog2
+    region.put(KEY1, new byte[432]);
+
+    observer.notifyRoller();
+
+    // put 440 bytes , this will try further switching
+    region.put(KEY2, new byte[432]);
+  }
+
+  private static class MyCacheObserver extends CacheObserverAdapter {
+
+    private final Object notification = new Object();
+
+    /**
+     * Flag to decide whether we want to allow roller to run
+     */
+    private volatile boolean notifyRoller = false;
+
+    private volatile boolean proceedForRolling = false;
+
+    void notifyRoller() {
+      notifyRoller = true;
+    }
+
+    @Override
+    public void beforeGoingToCompact() {
+      synchronized (notification) {
+        while (!proceedForRolling) {
+          try {
+            notification.wait();
+          } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+          }
+        }
+      }
+    }
+
+    @Override
+    public void beforeSwitchingOplog() {
+      if (notifyRoller) {
+        synchronized (notification) {
+          proceedForRolling = true;
+          notification.notifyAll();
+        }
+      }
+    }
+  }
+}

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

[geode] 05/19: GEODE-1279: Fix serialization of LocalVM

Posted by kl...@apache.org.
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 020291f093d553569298ab1abe833a08b955d952
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Wed Mar 21 13:27:39 2018 -0700

    GEODE-1279: Fix serialization of LocalVM
---
 geode-core/src/test/java/org/apache/geode/test/dunit/LocalVM.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/LocalVM.java b/geode-core/src/test/java/org/apache/geode/test/dunit/LocalVM.java
index 385df4d..540270e 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/LocalVM.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/LocalVM.java
@@ -15,6 +15,7 @@
 
 package org.apache.geode.test.dunit;
 
+import java.io.Serializable;
 import java.rmi.RemoteException;
 
 import hydra.MethExecutor;
@@ -62,7 +63,7 @@ public class LocalVM extends VM {
     throw new UnsupportedOperationException("Not supported by LocalVM");
   }
 
-  protected static class LocalDUnitVMIF implements RemoteDUnitVMIF {
+  protected static class LocalDUnitVMIF implements RemoteDUnitVMIF, Serializable {
 
     @Override
     public MethExecutorResult executeMethodOnObject(final Object target, final String methodName)

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

[geode] 16/19: GEODE-1279: Rename Bug45164DUnitTest as PREntrySetIteratorRegressionTest

Posted by kl...@apache.org.
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 55610788f5852d2a3574c3b7f0d6d7bc8f569c82
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Mar 23 14:05:58 2018 -0700

    GEODE-1279: Rename Bug45164DUnitTest as PREntrySetIteratorRegressionTest
---
 .../geode/internal/cache/Bug45164DUnitTest.java    | 113 ---------------------
 .../cache/PREntrySetIteratorRegressionTest.java    |  98 ++++++++++++++++++
 2 files changed, 98 insertions(+), 113 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
deleted file mode 100644
index a295bfe..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
+++ /dev/null
@@ -1,113 +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 java.util.Map.Entry;
-
-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.Region;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache30.CacheTestCase;
-import org.apache.geode.test.dunit.AsyncInvocation;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.SerializableRunnable;
-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;
-
-@Category(DistributedTest.class)
-public class Bug45164DUnitTest extends JUnit4CacheTestCase {
-  private static final int count = 10000;
-  private static final int stride = 3;
-
-  public Bug45164DUnitTest() {
-    super();
-  }
-
-  @Test
-  public void testIterateWhileDestroy() throws Throwable {
-    SerializableRunnable destroy = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-        for (int j = 0; j < count / stride; j += stride) {
-          region.destroy(j);
-        }
-      }
-    };
-
-    SerializableRunnable iterate = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-
-        int i = 0;
-        for (Entry<Integer, Object> entry : region.entrySet()) {
-          i++;
-          if (entry == null) {
-            fail("Element " + i + " is null");
-
-          }
-        }
-      }
-    };
-
-    Host h = Host.getHost(0);
-    AsyncInvocation async1 = h.getVM(1).invokeAsync(destroy);
-    AsyncInvocation async2 = h.getVM(2).invokeAsync(iterate);
-
-    async1.getResult();
-    async2.getResult();
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    SerializableRunnable create = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Cache cache = getCache(new CacheFactory());
-        Region<Integer, Object> region =
-            cache.<Integer, Object>createRegionFactory(RegionShortcut.PARTITION).create("test");
-        if (region == null) {
-          LogWriterUtils.getLogWriter().error("oops!");
-        }
-      }
-    };
-
-    SerializableRunnable load = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-        for (int i = 0; i < count; i++) {
-          region.put(i, i);
-        }
-      }
-    };
-
-    Host h = Host.getHost(0);
-    h.getVM(1).invoke(create);
-    h.getVM(2).invoke(create);
-    h.getVM(3).invoke(create);
-
-    h.getVM(1).invoke(load);
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
new file mode 100644
index 0000000..e67cab7
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map.Entry;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.dunit.AsyncInvocation;
+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.SerializableTestName;
+
+/**
+ * Iterating over Region.entrySet() should not return null for PartitionedRegion.
+ *
+ * <p>
+ * TRAC #45164: Iterating on Region.entrySet() can return null on partitioned region
+ */
+@Category(DistributedTest.class)
+public class PREntrySetIteratorRegressionTest extends CacheTestCase {
+
+  private static final int ENTRY_COUNT = 10_000;
+  private static final int ENTRY_DESTROY_SEQUENCE = 3;
+
+  private String uniqueName;
+
+  private VM vm1;
+  private VM vm2;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    vm1 = getHost(0).getVM(1);
+    vm2 = getHost(0).getVM(2);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    vm1.invoke(() -> createPartitionedRegion());
+    vm2.invoke(() -> createPartitionedRegion());
+
+    vm1.invoke(() -> doPuts());
+  }
+
+  @Test
+  public void regionEntrySetIteratorNextShouldNeverReturnNull() throws Exception {
+    AsyncInvocation destroySomeEntries = vm1.invokeAsync(() -> {
+      Region<Integer, Object> region = getCache().getRegion(uniqueName);
+      for (int j = 0; j < ENTRY_COUNT / ENTRY_DESTROY_SEQUENCE; j += ENTRY_DESTROY_SEQUENCE) {
+        region.destroy(j);
+      }
+    });
+
+    AsyncInvocation validateEntrySetIteratorContainsNoNulls = vm2.invokeAsync(() -> {
+      Region<Integer, Object> region = getCache().getRegion(uniqueName);
+      for (Entry<Integer, Object> entry : region.entrySet()) {
+        assertThat(entry).isNotNull();
+      }
+    });
+
+    destroySomeEntries.await();
+    validateEntrySetIteratorContainsNoNulls.await();
+  }
+
+  private void createPartitionedRegion() {
+    getCache().<Integer, Object>createRegionFactory(RegionShortcut.PARTITION).create(uniqueName);
+  }
+
+  private void doPuts() {
+    Region<Integer, Object> region = getCache().getRegion(uniqueName);
+    for (int i = 0; i < ENTRY_COUNT; i++) {
+      region.put(i, i);
+    }
+  }
+}

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

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

Posted by kl...@apache.org.
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.

[geode] 17/19: GEODE-1279: Rename Bug45934DUnitTest as DiskRecoveryWithVersioningGiiRegressionTest

Posted by kl...@apache.org.
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 3b4791cc7c155cd025b18eb3a26bbda1c2c63e3b
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Mar 23 15:04:54 2018 -0700

    GEODE-1279: Rename Bug45934DUnitTest as DiskRecoveryWithVersioningGiiRegressionTest
    
    Filed GEODE-4935 against this test. It needs some further review and
    work.
---
 .../geode/internal/cache/Bug45934DUnitTest.java    | 138 --------------
 ...iskRecoveryWithVersioningGiiRegressionTest.java | 206 +++++++++++++++++++++
 2 files changed, 206 insertions(+), 138 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45934DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45934DUnitTest.java
deleted file mode 100644
index 8021b97..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45934DUnitTest.java
+++ /dev/null
@@ -1,138 +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.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.HashMap;
-import java.util.Map;
-
-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.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.internal.util.DelayedAction;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.SerializableCallable;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-@Category(DistributedTest.class)
-public class Bug45934DUnitTest extends JUnit4CacheTestCase {
-
-  @Test
-  public void testNormal() throws Exception {
-    int count = 1000;
-    Host host = Host.getHost(0);
-    final VM remote = host.getVM(1);
-    final String name = getName();
-
-    // 0. create the remote region, set error flag
-    createRemoteRegion(remote, name);
-
-    // 1. create the local cache
-    CacheFactory cf = new CacheFactory();
-    cf.set(MCAST_PORT, "45934");
-    cf.set(CONSERVE_SOCKETS, "false");
-    Cache cache = getCache(cf);
-
-    // 2. create normal region locally
-    RegionFactory<Integer, Integer> rf = cache.<Integer, Integer>createRegionFactory();
-    rf.setDataPolicy(DataPolicy.NORMAL);
-    rf.setScope(Scope.DISTRIBUTED_ACK);
-    Region<Integer, Integer> region = rf.create(name);
-
-    // 3. reset the error flag after initial failure
-    DistributedCacheOperation.test_InvalidVersionAction = new DelayedAction(new Runnable() {
-      @Override
-      public void run() {
-        unsetRemoteFlag(remote);
-      }
-    });
-    DistributedCacheOperation.test_InvalidVersionAction.allowToProceed();
-
-    // 3. put data
-    Map<Integer, Integer> values = new HashMap<Integer, Integer>();
-    for (int i = 0; i < count; i++) {
-      values.put(i, i);
-    }
-    region.putAll(values);
-
-    // 5. double check
-    verifyLocal(region, count);
-    verify(remote, name, count);
-
-    cache.close();
-  }
-
-  private void createRemoteRegion(final VM remote, final String name) {
-    SerializableCallable create = new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        CacheFactory cf = new CacheFactory();
-        cf.set(MCAST_PORT, "45934");
-        cf.set(CONSERVE_SOCKETS, "false");
-
-        getCache(cf).<Integer, Integer>createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT)
-            .create(name);
-
-        AbstractUpdateOperation.test_InvalidVersion = true;
-        return null;
-      }
-    };
-    remote.invoke(create);
-  }
-
-  private void unsetRemoteFlag(final VM remote) {
-    SerializableCallable create = new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        AbstractUpdateOperation.test_InvalidVersion = false;
-        return null;
-      }
-    };
-    remote.invoke(create);
-  }
-
-  private void verifyLocal(Region<Integer, Integer> r, int count) {
-    assertEquals(count, r.size());
-    for (int i = 0; i < count; i++) {
-      assertEquals(i, (int) r.get(i));
-    }
-  }
-
-  private void verify(VM vm, final String name, final int count) {
-    SerializableCallable verify = new SerializableCallable() {
-      @Override
-      public Object call() throws Exception {
-        Region<Integer, Integer> r = getCache().getRegion(name);
-        assertEquals(count, r.size());
-        for (int i = 0; i < count; i++) {
-          assertEquals(i, (int) r.get(i));
-        }
-        return null;
-      }
-    };
-    vm.invoke(verify);
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/DiskRecoveryWithVersioningGiiRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskRecoveryWithVersioningGiiRegressionTest.java
new file mode 100644
index 0000000..7523e94
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/DiskRecoveryWithVersioningGiiRegressionTest.java
@@ -0,0 +1,206 @@
+/*
+ * 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.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE_PERSISTENT;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.internal.util.DelayedAction;
+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;
+
+/**
+ * TODO:GEODE-4935: why does this test NOT actually involve disk recover?
+ *
+ * <p>
+ * TRAC #45934: AssertionError: Version stamp should have a member at this point for entry ...
+ *
+ * <p>
+ * Occurs when a crash and recovery from disk in one VM while another one is spooling up its cache.
+ * The one that is starting attempts a GII from the one that recovers and throws an exception when
+ * the initial image version tags do not contain membership IDs.
+ *
+ * <pre>
+ * java.lang.AssertionError: Version stamp should have a member at this point for entry VersionedThinDiskLRURegionEntry@83cf00 (key=3; rawValue=VMCachedDeserializable@25892505; version={v0; rv0; ds=0; time=0};member=null)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.Oplog.create(Oplog.java:3600)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.DiskStoreImpl.put(DiskStoreImpl.java:638)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.DiskRegion.put(DiskRegion.java:306)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.DiskEntry$Helper.writeToDisk(DiskEntry.java:501)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.DiskEntry$Helper.update(DiskEntry.java:603)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.AbstractDiskRegionEntry.setValue(AbstractDiskRegionEntry.java:105)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.AbstractRegionEntry.initialImageInit(AbstractRegionEntry.java:673)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.AbstractRegionMap.initialImagePut(AbstractRegionMap.java:893)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.InitialImageOperation.processChunk(InitialImageOperation.java:681)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.InitialImageOperation$ImageProcessor.process(InitialImageOperation.java:874)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.ReplyMessage.process(ReplyMessage.java:207)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.internal.cache.InitialImageOperation$ImageReplyMessage.process(InitialImageOperation.java:1683)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.ReplyMessage.dmProcess(ReplyMessage.java:185)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.ReplyMessage.process(ReplyMessage.java:174)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:301)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.DistributionMessage$1.run(DistributionMessage.java:364)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.DistributionManager.runUntilShutdown(DistributionManager.java:684)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in com.gemstone.gemfire.distributed.internal.DistributionManager$5$1.run(DistributionManager.java:992)
+ *     at Remote Member 'frodo(30627)<v17>:55972' in java.lang.Thread.run(Thread.java:662)
+ *     at com.gemstone.gemfire.distributed.internal.ReplyException.handleAsUnexpected(ReplyException.java:79)
+ *     at com.gemstone.gemfire.internal.cache.InitialImageOperation.getFromOne(InitialImageOperation.java:328)
+ *     at com.gemstone.gemfire.internal.cache.DistributedRegion.getInitialImageAndRecovery(DistributedRegion.java:1330)
+ *     at com.gemstone.gemfire.internal.cache.DistributedRegion.initialize(DistributedRegion.java:1085)
+ *     at com.gemstone.gemfire.internal.cache.GemFireCacheImpl.createVMRegion(GemFireCacheImpl.java:2603)
+ *     at com.gemstone.gemfire.internal.cache.SingleWriteSingleReadRegionQueue.initializeRegion(SingleWriteSingleReadRegionQueue.java:1043)
+ *     at com.gemstone.gemfire.internal.cache.SingleWriteSingleReadRegionQueue.<init>(SingleWriteSingleReadRegionQueue.java:226)
+ *     at com.gemstone.gemfire.internal.cache.SingleWriteSingleReadRegionQueue.<init>(SingleWriteSingleReadRegionQueue.java:174)
+ *     at com.gemstone.gemfire.internal.cache.GatewayImpl$GatewayEventProcessor.initializeMessageQueue(GatewayImpl.java:1486)
+ *     at com.gemstone.gemfire.internal.cache.GatewayImpl$GatewayEventProcessor.<init>(GatewayImpl.java:1225)
+ *     at com.gemstone.gemfire.internal.cache.GatewayImpl.initializeEventProcessor(GatewayImpl.java:968)
+ *     at com.gemstone.gemfire.internal.cache.GatewayImpl.start(GatewayImpl.java:637)
+ *     at com.gemstone.gemfire.internal.cache.GatewayImpl.start(GatewayImpl.java:585)
+ *     at com.gemstone.gemfire.internal.cache.GatewayHubImpl.startGateways(GatewayHubImpl.java:604)
+ *     at com.gemstone.gemfire.internal.cache.GatewayHubImpl.start(GatewayHubImpl.java:591)
+ *     at com.gemstone.gemfire.internal.cache.GatewayHubImpl.start(GatewayHubImpl.java:529)
+ *     at com.gemstone.gemfire.internal.cache.persistence.PersistentGatewayDUnitTest$5.run(PersistentGatewayDUnitTest.java:209)
+ *     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ *     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ *     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ *     at java.lang.reflect.Method.invoke(Method.java:597)
+ *     at hydra.MethExecutor.executeObject(MethExecutor.java:258)
+ *     at hydra.RemoteTestModule.executeMethodOnObject(RemoteTestModule.java:269)
+ *     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
+ *     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
+ *     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
+ *     at java.lang.reflect.Method.invoke(Method.java:597)
+ *     at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
+ *     at sun.rmi.transport.Transport$1.run(Transport.java:159)
+ *     at java.security.AccessController.doPrivileged(Native Method)
+ *     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
+ *     at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
+ *     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
+ *     at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
+ *     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
+ *     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
+ *     at java.lang.Thread.run(Thread.java:662) from com.gemstone.gemfire.internal.cache.persistence.PersistentGatewayDUnitTest$5.run with 0 args : "Create gateway region" (took 1277 ms)
+ * </pre>
+ */
+@Category(DistributedTest.class)
+public class DiskRecoveryWithVersioningGiiRegressionTest extends CacheTestCase {
+
+  private static final int ENTRY_COUNT = 1000;
+
+  private String uniqueName;
+  private File diskDir;
+
+  private VM serverWithDisk;
+  private VM server;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    serverWithDisk = getHost(0).getVM(1);
+    server = getHost(0).getVM(2);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    diskDir = temporaryFolder.newFolder(uniqueName + "_serverWithDisk_disk");
+
+    serverWithDisk.invoke(() -> createCacheWithDisk());
+    server.invoke(() -> createCache());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    AbstractUpdateOperation.test_InvalidVersion = false;
+    DistributedCacheOperation.test_InvalidVersionAction = null;
+
+    disconnectAllFromDS();
+  }
+
+  @Test
+  public void giiFromMemberDoingDiskRecovery() throws Exception {
+    serverWithDisk.invoke(() -> {
+      AbstractUpdateOperation.test_InvalidVersion = true;
+    });
+
+    server.invoke(() -> {
+      DistributedCacheOperation.test_InvalidVersionAction =
+          new DelayedAction(() -> unsetRemoteFlagInServerWithDisk());
+      DistributedCacheOperation.test_InvalidVersionAction.allowToProceed();
+
+      putEntries();
+      validateRegionContents();
+    });
+
+    serverWithDisk.invoke(() -> validateRegionContents());
+  }
+
+  private void createCacheWithDisk() {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(new File[] {diskDir});
+
+    RegionFactory regionFactory = getCache().createRegionFactory(REPLICATE_PERSISTENT);
+    regionFactory.setDiskStoreName(dsf.create(uniqueName).getName());
+    regionFactory.create(uniqueName);
+  }
+
+  private void createCache() {
+    RegionFactory<Integer, Integer> regionFactory = getCache().createRegionFactory(REPLICATE);
+    regionFactory.create(uniqueName);
+  }
+
+  private void unsetRemoteFlagInServerWithDisk() {
+    serverWithDisk.invoke(() -> AbstractUpdateOperation.test_InvalidVersion = false);
+  }
+
+  private void putEntries() {
+    Region<Integer, Integer> region = getCache().getRegion(uniqueName);
+
+    Map<Integer, Integer> values = new HashMap<>();
+    for (int i = 0; i < ENTRY_COUNT; i++) {
+      values.put(i, i);
+    }
+    region.putAll(values);
+  }
+
+  private void validateRegionContents() {
+    Region<Integer, Integer> region = getCache().getRegion(uniqueName);
+
+    assertThat(region.size()).isEqualTo(ENTRY_COUNT);
+    for (int i = 0; i < ENTRY_COUNT; i++) {
+      assertThat(region.get(i)).isEqualTo(i);
+    }
+  }
+}

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

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

Posted by kl...@apache.org.
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.

[geode] 12/19: GEODE-1279: Rename Bug41091DUnitTest as BucketCreationGIIHARegressionTest

Posted by kl...@apache.org.
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 f53b5a6aaa23701af15a2388e191c8b9f939e461
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Mar 22 16:38:42 2018 -0700

    GEODE-1279: Rename Bug41091DUnitTest as BucketCreationGIIHARegressionTest
    
    * Cleanup the test.
---
 .../cache/BucketCreationGIIHARegressionTest.java   | 120 +++++++++++++++
 .../geode/internal/cache/Bug41091DUnitTest.java    | 169 ---------------------
 2 files changed, 120 insertions(+), 169 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationGIIHARegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationGIIHARegressionTest.java
new file mode 100644
index 0000000..754d645
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationGIIHARegressionTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+
+import org.junit.After;
+import org.junit.Before;
+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.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage;
+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.SerializableTestName;
+
+/**
+ * This class tests that bucket regions can handle a failure of the GII target during GII.
+ *
+ * <p>
+ * TRAC #41091: Missing primary detected after member forcefully disconnected from DS (underlying
+ * InternalGemFireError: Trying to clear a bucket region that was not destroyed)
+ */
+@Category(DistributedTest.class)
+public class BucketCreationGIIHARegressionTest extends CacheTestCase {
+
+  private String uniqueName;
+
+  private VM server1;
+  private VM server2;
+  private VM server3;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server1 = getHost(0).getVM(0);
+    server2 = getHost(0).getVM(1);
+    server3 = getHost(0).getVM(2);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    DistributionMessageObserver.setInstance(null);
+    invokeInEveryVM(() -> {
+      DistributionMessageObserver.setInstance(null);
+    });
+
+    disconnectAllFromDS();
+  }
+
+  @Test
+  public void bucketCreationLosesGiiTarget() {
+    server1.invoke(() -> createRegion());
+    server2.invoke(() -> createRegion());
+
+    server3.invoke(() -> {
+      PartitionAttributesFactory paf = new PartitionAttributesFactory();
+      paf.setRedundantCopies(1);
+      paf.setLocalMaxMemory(0);
+
+      AttributesFactory af = new AttributesFactory();
+      af.setPartitionAttributes(paf.create());
+
+      Region<Integer, String> region = getCache().createRegion(uniqueName, af.create());
+
+      region.put(0, "a");
+    });
+  }
+
+  private void createRegion() {
+    DistributionMessageObserver.setInstance(new MyDistributionMessageObserver());
+
+    PartitionAttributesFactory paf = new PartitionAttributesFactory();
+    paf.setRedundantCopies(1);
+
+    AttributesFactory af = new AttributesFactory();
+    af.setPartitionAttributes(paf.create());
+
+    getCache().createRegion(uniqueName, af.create());
+  }
+
+  private class MyDistributionMessageObserver extends DistributionMessageObserver {
+
+    @Override
+    public void beforeProcessMessage(ClusterDistributionManager dm, DistributionMessage message) {
+      if (message instanceof RequestImageMessage) {
+        RequestImageMessage rim = (RequestImageMessage) message;
+        Region region = getCache().getRegion(rim.regionPath);
+        if (region instanceof BucketRegion) {
+          getCache().close();
+        }
+      }
+    }
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41091DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41091DUnitTest.java
deleted file mode 100644
index 2c8f496..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41091DUnitTest.java
+++ /dev/null
@@ -1,169 +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.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Properties;
-
-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.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.ClusterDistributionManager;
-import org.apache.geode.distributed.internal.DistributionMessage;
-import org.apache.geode.distributed.internal.DistributionMessageObserver;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.NetworkUtils;
-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.junit.categories.DistributedTest;
-
-/**
- * This class tests that bucket regions can handle a failure of the GII target during GII.
- */
-@Category(DistributedTest.class)
-public class Bug41091DUnitTest extends JUnit4CacheTestCase {
-
-  @Override
-  public final void postTearDownCacheTestCase() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Test
-  public void test() {
-    final Host host = Host.getHost(0);
-    VM vm0 = host.getVM(0);
-    VM vm1 = host.getVM(1);
-    VM vm2 = host.getVM(2);
-    VM vm3 = host.getVM(3);
-
-    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-
-    // We need to use our own locator because we need enable network partition detection.
-    startLocatorInVM(vm3, locatorPort);
-    try {
-
-      final SerializableRunnable createRegion = new SerializableRunnable("create the region") {
-
-        public void run() {
-          DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
-
-            @Override
-            public void beforeProcessMessage(ClusterDistributionManager dm,
-                DistributionMessage message) {
-              if (message instanceof RequestImageMessage) {
-                RequestImageMessage rim = (RequestImageMessage) message;
-                Region region = getCache().getRegion(rim.regionPath);
-                if (region instanceof BucketRegion) {
-                  // We can no longer do any puts until the bucket is completely created,
-                  // so this will hang
-                  // getCache().getRegion("region").put(113, "b");
-                  getCache().close();
-                }
-              }
-            }
-          });
-
-          Properties props = new Properties();
-          props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
-          props.setProperty(LOCATORS,
-              NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
-          getSystem(props);
-
-
-          Cache cache = getCache();
-          AttributesFactory af = new AttributesFactory();
-          PartitionAttributesFactory paf = new PartitionAttributesFactory();
-          paf.setRedundantCopies(1);
-          af.setPartitionAttributes(paf.create());
-          cache.createRegion("region", af.create());
-        }
-      };
-      vm0.invoke(createRegion);
-      vm1.invoke(createRegion);
-
-      vm2.invoke(new SerializableRunnable("create an entry") {
-
-        public void run() {
-          Properties props = new Properties();
-          props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
-          props.setProperty(LOCATORS,
-              NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
-          getSystem(props);
-          Cache cache = getCache();
-          AttributesFactory af = new AttributesFactory();
-          PartitionAttributesFactory paf = new PartitionAttributesFactory();
-          paf.setRedundantCopies(1);
-          paf.setLocalMaxMemory(0);
-          af.setPartitionAttributes(paf.create());
-          Region region = cache.createRegion("region", af.create());
-          region.put(Integer.valueOf(0), "a");
-        }
-      });
-    } finally {
-      SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
-        public void run() {
-          assertTrue(Locator.hasLocator());
-          Locator.getLocator().stop();
-          assertFalse(Locator.hasLocator());
-        }
-      };
-      vm3.invoke(stopLocator);
-    }
-  }
-
-  protected void startLocatorInVM(final VM vm, final int locatorPort) {
-    vm.invoke(new SerializableRunnable("Create Locator") {
-
-      final String testName = getUniqueName();
-
-      public void run() {
-        disconnectFromDS();
-        Properties props = new Properties();
-        props.setProperty(MCAST_PORT, String.valueOf(0));
-        props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
-        props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
-        props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
-        try {
-          File logFile = new File(testName + "-locator" + locatorPort + ".log");
-          InetAddress bindAddr = null;
-          try {
-            bindAddr = InetAddress.getByName(NetworkUtils.getServerHostName(vm.getHost()));
-          } catch (UnknownHostException uhe) {
-            Assert.fail("While resolving bind address ", uhe);
-          }
-          Locator locator = Locator.startLocatorAndDS(locatorPort, logFile, bindAddr, props);
-        } catch (IOException ex) {
-          Assert.fail("While starting locator on port " + locatorPort, ex);
-        }
-      }
-    });
-  }
-}

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

[geode] 04/19: GEODE-1279: Rename Bug34583JUnitTest as RegionValuesIteratorAfterLocalInvalidateRegressionTest

Posted by kl...@apache.org.
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 cd3ff6d748f854c8e3a2d025bd14bfe19fdbd8de
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Tue Mar 20 16:47:58 2018 -0700

    GEODE-1279: Rename Bug34583JUnitTest as RegionValuesIteratorAfterLocalInvalidateRegressionTest
---
 .../geode/internal/cache/Bug34583JUnitTest.java    |  96 --------------------
 ...IteratorAfterLocalInvalidateRegressionTest.java | 101 +++++++++++++++++++++
 2 files changed, 101 insertions(+), 96 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34583JUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34583JUnitTest.java
deleted file mode 100644
index 10ff741..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug34583JUnitTest.java
+++ /dev/null
@@ -1,96 +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.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.junit.After;
-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.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * Confirm that bug 34583 is fixed. Cause of bug is recursion is entries iterator that causes stack
- * overflow.
- */
-@Category(IntegrationTest.class)
-public class Bug34583JUnitTest {
-
-  public Bug34583JUnitTest() {}
-
-  public void setup() {}
-
-  @After
-  public void tearDown() {}
-
-
-
-  @Test
-  public void testBunchOfInvalidEntries() throws Exception {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    DistributedSystem ds = DistributedSystem.connect(props);
-    try {
-      AttributesFactory factory = new AttributesFactory();
-      Cache cache = null;
-      cache = CacheFactory.create(ds);
-
-      Region r = cache.createRegion("testRegion", factory.create());
-      final int ENTRY_COUNT = 25000;
-      {
-        for (int i = 1; i <= ENTRY_COUNT; i++) {
-          r.put("key" + i, "value" + i);
-        }
-      }
-      { // make sure iterator works while values are valid
-        Collection c = r.values();
-        assertEquals(ENTRY_COUNT, c.size());
-        Iterator it = c.iterator();
-        int count = 0;
-        while (it.hasNext()) {
-          it.next();
-          count++;
-        }
-        assertEquals(ENTRY_COUNT, count);
-      }
-      r.localInvalidateRegion();
-      // now we expect iterator to stackOverflow if bug 34583
-      {
-        Collection c = r.values();
-        assertEquals(0, c.size());
-        Iterator it = c.iterator();
-        int count = 0;
-        while (it.hasNext()) {
-          it.next();
-          count++;
-        }
-        assertEquals(0, count);
-      }
-    } finally {
-      ds.disconnect();
-    }
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/RegionValuesIteratorAfterLocalInvalidateRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionValuesIteratorAfterLocalInvalidateRegressionTest.java
new file mode 100644
index 0000000..7ee9f81
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/RegionValuesIteratorAfterLocalInvalidateRegressionTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+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;
+
+/**
+ * Confirm that bug 34583 is fixed. Cause of bug is recursion is entries iterator that causes stack
+ * overflow.
+ *
+ * <p>
+ * TRAC #34583: StackOverflowError while performing region.put() at bridge client.
+ */
+@Category(IntegrationTest.class)
+public class RegionValuesIteratorAfterLocalInvalidateRegressionTest {
+
+  private static final int PUT_COUNT = 25000;
+
+  private Cache cache;
+  private Region<String, String> region;
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() {
+    String uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+
+    RegionFactory<String, String> regionFactory = cache.createRegionFactory(RegionShortcut.LOCAL);
+    region = regionFactory.create(uniqueName);
+
+    for (int i = 1; i <= PUT_COUNT; i++) {
+      region.put("key" + i, "value" + i);
+    }
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void testBunchOfInvalidEntries() throws Exception {
+    // make sure iterator works while values are valid
+    Collection<String> valuesBefore = region.values();
+    assertThat(valuesBefore).hasSize(PUT_COUNT);
+
+    int iteratorCount = 0;
+    for (Iterator iterator = valuesBefore.iterator(); iterator.hasNext(); iterator.next()) {
+      iteratorCount++;
+    }
+
+    assertThat(iteratorCount).isEqualTo(PUT_COUNT);
+
+    region.localInvalidateRegion();
+
+    // now we expect iterator to stackOverflow if bug 34583 exists
+    Collection<String> valuesAfter = region.values();
+    assertThat(valuesAfter).isEmpty();
+
+    iteratorCount = 0;
+    for (Iterator iterator = valuesAfter.iterator(); iterator.hasNext(); iterator.next()) {
+      iteratorCount++;
+    }
+
+    assertThat(iteratorCount).isZero();
+  }
+}

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

[geode] 07/19: GEODE-1279: Rename Bug37377DUnitTest as ClearDuringGiiOplogWithMissingCreateRegressionTest

Posted by kl...@apache.org.
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 3e2619fe630f4b6bcb124908a7354e7bc10e4b4c
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Wed Mar 21 15:16:42 2018 -0700

    GEODE-1279: Rename Bug37377DUnitTest as ClearDuringGiiOplogWithMissingCreateRegressionTest
---
 .../geode/internal/cache/Bug37377DUnitTest.java    | 317 ---------------------
 ...ingGiiOplogWithMissingCreateRegressionTest.java | 229 +++++++++++++++
 2 files changed, 229 insertions(+), 317 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37377DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37377DUnitTest.java
deleted file mode 100644
index 35e00c1..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug37377DUnitTest.java
+++ /dev/null
@@ -1,317 +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 java.io.File;
-import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
-
-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.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.cache.entries.VersionedThinDiskRegionEntryHeapObjectKey;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Bug37377 DUNIT Test: The Clear operation during a GII in progress can leave a Entry in the Oplog
- * due to a race condition wherein the clearFlag getting set after the entry gets written to the
- * disk, The Test verifies the existence of the scenario.
- *
- */
-
-@Category(DistributedTest.class)
-public class Bug37377DUnitTest extends JUnit4CacheTestCase {
-
-  protected static String regionName = "TestRegion";
-
-  static Properties props = new Properties();
-
-  protected static DistributedSystem distributedSystem = null;
-
-  VM vm0, vm1;
-
-  protected static Cache cache = null;
-
-  protected static File[] dirs = null;
-
-  private static final int maxEntries = 10000;
-
-  private static transient CountDownLatch clearLatch = new CountDownLatch(1);
-
-  static Boolean clearOccurred = false;
-
-  public Bug37377DUnitTest() {
-    super();
-    File file1 = new File(getTestMethodName() + "1");
-    file1.mkdir();
-    file1.deleteOnExit();
-    File file2 = new File(getTestMethodName() + "2");
-    file2.mkdir();
-    file2.deleteOnExit();
-    dirs = new File[2];
-    dirs[0] = file1;
-    dirs[1] = file2;
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    final Host host = Host.getHost(0);
-    vm0 = host.getVM(0);
-    vm1 = host.getVM(1);
-  }
-
-  @Override
-  public final void preTearDownCacheTestCase() throws Exception {
-    vm1.invoke(() -> destroyRegion());
-    vm0.invoke(() -> destroyRegion());
-  }
-
-  /**
-   * This method is used to create Cache in VM0
-   */
-
-  @SuppressWarnings("deprecation")
-  private void createCacheForVM0() {
-    try {
-
-      distributedSystem = (new Bug37377DUnitTest()).getSystem(props);
-      assertTrue(distributedSystem != null);
-      cache = CacheFactory.create(distributedSystem);
-      assertTrue(cache != null);
-      AttributesFactory factory = new AttributesFactory();
-      factory.setScope(Scope.DISTRIBUTED_ACK);
-      factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-      factory.setDiskSynchronous(false);
-      factory.setDiskStoreName(
-          cache.createDiskStoreFactory().setDiskDirs(dirs).create("Bug37377DUnitTest").getName());
-      RegionAttributes attr = factory.create();
-      cache.createRegion(regionName, attr);
-    } catch (Exception ex) {
-      ex.printStackTrace();
-      fail("Error Creating cache / region ");
-    }
-  }
-
-  /**
-   * This method is used to create Cache in VM1
-   */
-  @SuppressWarnings("deprecation")
-  private void createCacheForVM1() {
-    try {
-      distributedSystem = (new Bug37377DUnitTest()).getSystem(props);
-      assertTrue(distributedSystem != null);
-      cache = CacheFactory.create(distributedSystem);
-      assertTrue("cache found null", cache != null);
-
-      AttributesFactory factory = new AttributesFactory();
-      factory.setScope(Scope.DISTRIBUTED_ACK);
-      factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-      factory.setDiskSynchronous(false);
-      factory.setDiskStoreName(
-          cache.createDiskStoreFactory().setDiskDirs(dirs).create("Bug37377DUnitTest").getName());
-      RegionAttributes attr = factory.create();
-      DistributedRegion distRegion = new DistributedRegion(regionName, attr, null,
-          (GemFireCacheImpl) cache, new InternalRegionArguments().setDestroyLockFlag(true)
-              .setRecreateFlag(false).setSnapshotInputStream(null).setImageTarget(null));
-      // assertTrue("Distributed Region is null", distRegion != null); (cannot be null)
-
-      TestAbstractDiskRegionEntry.setMembers(vm1, vm0); // vm1 is thisVM, vm0 is otherVM
-
-      ((AbstractRegionMap) distRegion.entries)
-          .setEntryFactory(TestAbstractDiskRegionEntry.getEntryFactory());
-
-      LocalRegion region = (LocalRegion) ((GemFireCacheImpl) cache).createVMRegion(regionName, attr,
-          new InternalRegionArguments().setInternalMetaRegion(distRegion).setDestroyLockFlag(true)
-              .setSnapshotInputStream(null).setImageTarget(null));
-      assertTrue("Local Region is null", region != null);
-
-    } catch (Exception ex) {
-      ex.printStackTrace();
-      fail("Error Creating cache / region " + ex);
-    }
-  }
-
-  /**
-   * This method puts in maxEntries in the Region
-   */
-  private void putSomeEntries() {
-    assertTrue("Cache is found as null ", cache != null);
-    Region rgn = cache.getRegion(regionName);
-    for (int i = 0; i < maxEntries; i++) {
-      rgn.put(new Long(i), new Long(i));
-    }
-  }
-
-  /**
-   * This method clears the region and notifies the other member when complete
-   */
-  private static void invokeRemoteClearAndWait(VM remoteVM, VM thisVM) {
-    remoteVM.invoke(() -> clearRegionAndNotify(thisVM));
-    try {
-      clearLatch.await();
-    } catch (InterruptedException e) {
-      fail("wait for remote clear to complete failed");
-    }
-  }
-
-  /**
-   * This method clears the region and notifies the other member when complete
-   */
-  private static void clearRegionAndNotify(VM otherVM) {
-    assertTrue("Cache is found as null ", cache != null);
-    Region rgn = cache.getRegion(regionName);
-    rgn.clear();
-    otherVM.invoke(() -> notifyClearComplete());
-  }
-
-  /**
-   * Decrement countdown latch to notify clear complete
-   */
-  private static void notifyClearComplete() {
-    clearLatch.countDown();
-  }
-
-  /**
-   * This method destroys the Region
-   */
-  private void destroyRegion() {
-    try {
-      assertTrue("Cache is found as null ", cache != null);
-      Region rgn = cache.getRegion(regionName);
-      rgn.localDestroyRegion();
-      cache.close();
-    } catch (Exception ex) {
-    }
-  }
-
-  /**
-   * This method closes the cache on the specified VM
-   */
-  private void closeCacheForVM(final int vmNo) {
-    if (vmNo == 0) {
-      cache.getRegion(regionName).localDestroyRegion();
-    }
-    assertTrue("Cache is found as null ", cache != null);
-    cache.close();
-  }
-
-  /**
-   * This method verifies that the reintialized region size is zero
-   */
-  private void verifyExtraEntryFromOpLogs() {
-    assertTrue("Cache is found as null ", cache != null);
-    Region rgn = cache.getRegion(regionName);
-    // should be zero after clear
-    assertEquals(0, rgn.size());
-  }
-
-  /**
-   * The Clear operation during a GII in progress can leave a Entry in the Oplog due to a race
-   * condition wherein the clearFlag getting set after the entry gets written to the disk, The Test
-   * verifies the existence of the scenario.
-   *
-   */
-
-  @Test
-  public void testGIIputWithClear() {
-    vm0.invoke(() -> createCacheForVM0());
-    vm0.invoke(() -> putSomeEntries());
-
-    vm1.invoke(() -> createCacheForVM1());
-
-    vm0.invoke(() -> closeCacheForVM(0));
-    vm1.invoke(() -> closeCacheForVM(1));
-
-    vm1.invoke(() -> createCacheForVM1());
-    vm1.invoke(() -> verifyExtraEntryFromOpLogs());
-  }
-
-  static class TestAbstractDiskRegionEntry extends VersionedThinDiskRegionEntryHeapObjectKey {
-    private static VM thisVM, otherVM;
-
-    static void setMembers(VM localVM, VM remoteVM) {
-      thisVM = localVM;
-      otherVM = remoteVM;
-    }
-
-    protected TestAbstractDiskRegionEntry(RegionEntryContext r, Object key, Object value) {
-      super(r, key, value);
-    }
-
-    private static RegionEntryFactory factory = new RegionEntryFactory() {
-
-      public RegionEntry createEntry(RegionEntryContext r, Object key, Object value) {
-        return new TestAbstractDiskRegionEntry(r, key, value);
-      }
-
-      public Class getEntryClass() {
-        return TestAbstractDiskRegionEntry.class;
-      }
-
-      public RegionEntryFactory makeVersioned() {
-        return this;
-      }
-
-      public RegionEntryFactory makeOnHeap() {
-        return this;
-      }
-    };
-
-    /**
-     * Overridden setValue method to call clear Region before actually writing the entry
-     */
-    @Override
-    public boolean initialImageInit(final InternalRegion r, final long lastModifiedTime,
-        final Object newValue, final boolean create, final boolean wasRecovered,
-        final boolean versionTagAccepted) throws RegionClearedException {
-      synchronized (clearOccurred) {
-        if (!clearOccurred) {
-          // Force other member to perform a clear during our GII
-          invokeRemoteClearAndWait(otherVM, thisVM);
-          clearOccurred = true;
-        }
-      }
-
-      // Continue GII processing, which should throw RegionClearedException after the clear
-      try {
-        boolean result = super.initialImageInit(r, lastModifiedTime, newValue, create, wasRecovered,
-            versionTagAccepted);
-      } catch (RegionClearedException rce) {
-        throw rce;
-      } catch (Exception ex) {
-        fail("Caught exception during initialImageInit: " + ex);
-      }
-
-      return true;
-    }
-
-    public static RegionEntryFactory getEntryFactory() {
-      return factory;
-    }
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringGiiOplogWithMissingCreateRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringGiiOplogWithMissingCreateRegressionTest.java
new file mode 100644
index 0000000..066de28
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ClearDuringGiiOplogWithMissingCreateRegressionTest.java
@@ -0,0 +1,229 @@
+/*
+ * 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.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+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.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.internal.cache.entries.VersionedThinDiskRegionEntryHeapObjectKey;
+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;
+
+/**
+ * Bug37377 DUNIT Test: The Clear operation during a GII in progress can leave a Entry in the Oplog
+ * due to a race condition wherein the clearFlag getting set after the entry gets written to the
+ * disk, The Test verifies the existence of the scenario.
+ *
+ * <p>
+ * TRAC #37377: Clear operation with GII in progress may result in a deleted entry to be logged in
+ * the oplog without accompanying create
+ */
+@Category(DistributedTest.class)
+public class ClearDuringGiiOplogWithMissingCreateRegressionTest extends CacheTestCase {
+
+  private static final int PUT_COUNT = 10000;
+
+  private String uniqueName;
+  private String regionName;
+  private File[] foldersForServer1;
+  private File[] foldersForServer2;
+
+  private VM server1;
+  private VM server2;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server1 = getHost(0).getVM(0);
+    server2 = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    regionName = uniqueName;
+
+    File server1Disk1 = temporaryFolder.newFolder(uniqueName + "_server1_disk1");
+    foldersForServer1 = new File[] {server1Disk1};
+
+    File server2Disk1 = temporaryFolder.newFolder(uniqueName + "_server2_disk1");
+    foldersForServer2 = new File[] {server2Disk1};
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  /**
+   * The Clear operation during a GII in progress can leave a Entry in the Oplog due to a race
+   * condition wherein the clearFlag getting set after the entry gets written to the disk, The Test
+   * verifies the existence of the scenario.
+   */
+  @Test
+  public void clearDuringGiiShouldOplogCreateAndDelete() {
+    server1.invoke(() -> createCacheForVM0());
+    server1.invoke(() -> {
+      Region<Integer, Integer> region = getCache().getRegion(regionName);
+      for (int i = 0; i < PUT_COUNT; i++) {
+        region.put(i, i);
+      }
+    });
+
+    server2.invoke(() -> createCacheForVM1());
+
+    server1.invoke(() -> {
+      getCache().getRegion(regionName).localDestroyRegion();
+      getCache().close();
+    });
+
+    server2.invoke(() -> getCache().close());
+
+    server2.invoke(() -> createCacheForVM1());
+    server2.invoke(() -> assertThatRegionSizeIsZero());
+  }
+
+  /**
+   * This method is used to create Cache in VM0
+   */
+  private void createCacheForVM0() {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(foldersForServer1);
+
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+
+    getCache().createRegion(regionName, factory.create());
+  }
+
+  /**
+   * This method is used to create Cache in VM1
+   */
+  private void createCacheForVM1() throws IOException, ClassNotFoundException {
+    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
+    dsf.setDiskDirs(foldersForServer2);
+
+    DiskStore diskStore = dsf.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+
+    DistributedRegion distRegion = new DistributedRegion(regionName, factory.create(), null,
+        getCache(), new InternalRegionArguments().setDestroyLockFlag(true).setRecreateFlag(false)
+            .setSnapshotInputStream(null).setImageTarget(null));
+
+    distRegion.entries.setEntryFactory(new TestableDiskRegionEntryFactory());
+
+    getCache().createVMRegion(regionName, factory.create(),
+        new InternalRegionArguments().setInternalMetaRegion(distRegion).setDestroyLockFlag(true)
+            .setSnapshotInputStream(null).setImageTarget(null));
+  }
+
+  /**
+   * This method clears the region and notifies the other member when complete
+   */
+  private void invokeRemoteClearAndWait() {
+    server1.invoke(() -> {
+      Region region = getCache().getRegion(regionName);
+      region.clear();
+    });
+  }
+
+  private void assertThatRegionSizeIsZero() {
+    assertThat(getCache().getRegion(regionName).size()).isZero();
+  }
+
+  private class TestableDiskRegionEntry extends VersionedThinDiskRegionEntryHeapObjectKey {
+
+    TestableDiskRegionEntry(RegionEntryContext context, Object key, Object value) {
+      super(context, key, value);
+    }
+
+    /**
+     * Overridden setValue method to call clear Region before actually writing the entry
+     */
+    @Override
+    public boolean initialImageInit(final InternalRegion region, final long lastModified,
+        final Object newValue, final boolean create, final boolean wasRecovered,
+        final boolean acceptedVersionTag) throws RegionClearedException {
+
+      invokeRemoteClearAndWait();
+
+      // Continue GII processing, which should throw RegionClearedException after the clear
+      boolean result;
+      try {
+        result = super.initialImageInit(region, lastModified, newValue, create, wasRecovered,
+            acceptedVersionTag);
+      } catch (RegionClearedException e) {
+        throw e;
+      } catch (Exception e) {
+        throw new RuntimeException("initialImageInit threw " + e.getClass().getSimpleName(), e);
+      }
+
+      return result;
+    }
+  }
+
+  private class TestableDiskRegionEntryFactory implements RegionEntryFactory {
+
+    @Override
+    public RegionEntry createEntry(RegionEntryContext r, Object key, Object value) {
+      return new TestableDiskRegionEntry(r, key, value);
+    }
+
+    @Override
+    public Class getEntryClass() {
+      return TestableDiskRegionEntry.class;
+    }
+
+    @Override
+    public RegionEntryFactory makeVersioned() {
+      return this;
+    }
+
+    @Override
+    public RegionEntryFactory makeOnHeap() {
+      return this;
+    }
+  }
+}

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

[geode] 13/19: GEODE-1279: Rename Bug41733DUnitTest as BucketCreationRequesterCrashHARegressionTest

Posted by kl...@apache.org.
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 d93f3d554ed4d0746fedc90b220dd8a701c08f47
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Mar 22 19:48:11 2018 -0700

    GEODE-1279: Rename Bug41733DUnitTest as BucketCreationRequesterCrashHARegressionTest
---
 ...cketCreationRequesterCrashHARegressionTest.java | 261 +++++++++++++++++++++
 .../geode/internal/cache/Bug41733DUnitTest.java    | 211 -----------------
 2 files changed, 261 insertions(+), 211 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationRequesterCrashHARegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationRequesterCrashHARegressionTest.java
new file mode 100644
index 0000000..c0e124f
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/BucketCreationRequesterCrashHARegressionTest.java
@@ -0,0 +1,261 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_NETWORK_PARTITION_DETECTION;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
+import static org.apache.geode.test.dunit.DistributedTestUtils.crashDistributedSystem;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.ForcedDisconnectException;
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.distributed.DistributedSystemDisconnectedException;
+import org.apache.geode.distributed.Locator;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.partitioned.ManageBucketMessage;
+import org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage;
+import org.apache.geode.test.dunit.NetworkUtils;
+import org.apache.geode.test.dunit.RMIException;
+import org.apache.geode.test.dunit.SerializableRunnableIF;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.CacheTestCase;
+import org.apache.geode.test.dunit.rules.SharedErrorCollector;
+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;
+
+/**
+ * Test to make sure that we can handle a crash of the member directing bucket creation.
+ *
+ * BucketCreationRequesterCrashHARegressionTest
+ *
+ * <p>
+ * TRAC #41733: Hang in BucketAdvisor.waitForPrimaryMember
+ */
+@Category(DistributedTest.class)
+public class BucketCreationRequesterCrashHARegressionTest extends CacheTestCase {
+
+  private String uniqueName;
+  private String hostName;
+  private int locatorPort;
+  private File locatorLog;
+
+  private VM server1;
+  private VM server2;
+  private VM locator;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Rule
+  public SharedErrorCollector errorCollector = new SharedErrorCollector();
+
+  @Before
+  public void setUp() throws Exception {
+    server1 = getHost(0).getVM(0);
+    server2 = getHost(0).getVM(1);
+    locator = getHost(0).getVM(2);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    hostName = NetworkUtils.getServerHostName(server1.getHost());
+    locatorLog = new File(temporaryFolder.newFolder(uniqueName), "locator.log");
+
+    locatorPort = locator.invoke(() -> startLocator());
+    assertThat(locatorPort).isGreaterThan(0);
+
+    server1.invoke(() -> createServerCache());
+    server2.invoke(() -> createServerCache());
+
+    // cluster should ONLY have 3 members (our 2 servers and 1 locator)
+    assertThat(server1.invoke(
+        () -> getCache().getDistributionManager().getDistributionManagerIdsIncludingAdmin()))
+            .hasSize(3);
+
+    addIgnoredException(ForcedDisconnectException.class);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    DistributionMessageObserver.setInstance(null);
+    invokeInEveryVM(() -> {
+      DistributionMessageObserver.setInstance(null);
+    });
+
+    disconnectAllFromDS();
+  }
+
+  /**
+   * Test the we can handle a member departing after creating a bucket on the remote node but before
+   * we choose a primary
+   */
+  @Test
+  public void putShouldNotHangAfterBucketCrashesBeforePrimarySelection() throws Exception {
+    server1.invoke(
+        () -> handleBeforeProcessMessage(ManageBucketReplyMessage.class, () -> crashServer()));
+    server1.invoke(() -> createPartitionedRegion());
+
+    // Create a couple of buckets in VM0. This will make sure
+    // the next bucket we create will be created in VM 1.
+    server1.invoke(() -> putData(0, 2, "a"));
+
+    server2.invoke(() -> createPartitionedRegion());
+
+    // Trigger a bucket creation in VM1, which should cause server1 to close it's cache.
+    assertThatThrownBy(() -> server1.invoke(() -> putData(3, 4, "a")))
+        .isInstanceOf(RMIException.class)
+        .hasCauseInstanceOf(DistributedSystemDisconnectedException.class);
+
+    assertThat(server2.invoke(() -> getBucketList())).containsExactly(3);
+
+    // This shouldn't hang, because the bucket creation should finish,.
+    server2.invoke(() -> putData(3, 4, "a"));
+  }
+
+  /**
+   * Test the we can handle a member departing while we are in the process of creating the bucket on
+   * the remote node.
+   */
+  @Test
+  public void putShouldNotHangAfterServerWithBucketCrashes() throws Exception {
+    server2.invoke(() -> handleBeforeProcessMessage(ManageBucketMessage.class,
+        () -> server1.invoke(() -> crashServer())));
+    server1.invoke(() -> createPartitionedRegion());
+
+    // Create a couple of buckets in VM0. This will make sure
+    // the next bucket we create will be created in VM 1.
+    server1.invoke(() -> putData(0, 2, "a"));
+
+    server2.invoke(() -> createPartitionedRegion());
+
+    // Trigger a bucket creation in VM1, which should cause server1 to close it's cache.
+    assertThatThrownBy(() -> server1.invoke(() -> putData(3, 4, "a")))
+        .isInstanceOf(RMIException.class)
+        .hasCauseInstanceOf(DistributedSystemDisconnectedException.class);
+
+    assertThat(server2.invoke(() -> getBucketList())).containsExactly(3);
+
+    // This shouldn't hang, because the bucket creation should finish.
+    server2.invoke(() -> putData(3, 4, "a"));
+  }
+
+  private Properties createLocatorConfig() {
+    Properties config = new Properties();
+    config.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
+    config.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
+    config.setProperty(USE_CLUSTER_CONFIGURATION, "false");
+    return config;
+  }
+
+  private Properties createServerConfig() {
+    Properties config = createLocatorConfig();
+    config.setProperty(LOCATORS, hostName + "[" + locatorPort + "]");
+    return config;
+  }
+
+  private int startLocator() throws IOException {
+    Properties config = createLocatorConfig();
+    InetAddress bindAddress = InetAddress.getByName(hostName);
+    Locator locator = Locator.startLocatorAndDS(locatorPort, locatorLog, bindAddress, config);
+    return locator.getPort();
+  }
+
+  private void createServerCache() {
+    getCache(createServerConfig());
+  }
+
+  private void createPartitionedRegion() {
+    PartitionAttributesFactory paf = new PartitionAttributesFactory();
+    paf.setRedundantCopies(0);
+
+    AttributesFactory af = new AttributesFactory();
+    af.setDataPolicy(DataPolicy.PARTITION);
+    af.setPartitionAttributes(paf.create());
+
+    getCache().createRegion(uniqueName, af.create());
+  }
+
+  private void putData(final int startKey, final int endKey, final String value) {
+    Region<Integer, String> region = getCache().getRegion(uniqueName);
+
+    for (int i = startKey; i < endKey; i++) {
+      region.put(i, value);
+    }
+  }
+
+  private Set<Integer> getBucketList() {
+    PartitionedRegion region = (PartitionedRegion) getCache().getRegion(uniqueName);
+    return new TreeSet<>(region.getDataStore().getAllLocalBucketIds());
+  }
+
+  private void handleBeforeProcessMessage(final Class<? extends DistributionMessage> messageClass,
+      final SerializableRunnableIF runnable) {
+    DistributionMessageObserver
+        .setInstance(new RunnableBeforeProcessMessageObserver(messageClass, runnable));
+  }
+
+  private void crashServer() {
+    crashDistributedSystem(getSystem());
+  }
+
+  private class RunnableBeforeProcessMessageObserver extends DistributionMessageObserver {
+
+    private final Class<? extends DistributionMessage> messageClass;
+    private final SerializableRunnableIF runnable;
+
+    RunnableBeforeProcessMessageObserver(final Class<? extends DistributionMessage> messageClass,
+        final SerializableRunnableIF runnable) {
+      this.messageClass = messageClass;
+      this.runnable = runnable;
+    }
+
+    @Override
+    public void beforeProcessMessage(ClusterDistributionManager dm, DistributionMessage message) {
+      if (messageClass.isInstance(message)) {
+        try {
+          runnable.run();
+        } catch (Exception e) {
+          errorCollector.addError(e);
+        }
+      }
+    }
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41733DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41733DUnitTest.java
deleted file mode 100644
index ae2e664..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug41733DUnitTest.java
+++ /dev/null
@@ -1,211 +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 java.util.*;
-
-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.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.distributed.*;
-import org.apache.geode.distributed.internal.ClusterDistributionManager;
-import org.apache.geode.distributed.internal.DistributionMessage;
-import org.apache.geode.distributed.internal.DistributionMessageObserver;
-import org.apache.geode.internal.cache.partitioned.ManageBucketMessage;
-import org.apache.geode.internal.cache.partitioned.ManageBucketMessage.ManageBucketReplyMessage;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.RMIException;
-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.junit.categories.DistributedTest;
-
-/**
- * Test to make sure that we can handle a crash of the member directing bucket creation.
- */
-@Category(DistributedTest.class)
-public class Bug41733DUnitTest extends JUnit4CacheTestCase {
-
-  @Override
-  public final void preTearDownCacheTestCase() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public Properties getDistributedSystemProperties() {
-    Properties result = super.getDistributedSystemProperties();
-    result.put(ConfigurationProperties.ENABLE_NETWORK_PARTITION_DETECTION, "false");
-    return result;
-  }
-
-  /**
-   * Test the we can handle a member departing after creating a bucket on the remote node but before
-   * we choose a primary
-   */
-  @Test
-  public void testCrashAfterBucketCreation() throws Throwable {
-    Host host = Host.getHost(0);
-    VM vm0 = host.getVM(0);
-    VM vm1 = host.getVM(1);
-
-    vm0.invoke(new SerializableRunnable("Install observer") {
-
-      public void run() {
-        DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
-
-
-          @Override
-          public void beforeProcessMessage(ClusterDistributionManager dm,
-              DistributionMessage message) {
-            if (message instanceof ManageBucketReplyMessage) {
-              disconnectFromDS();
-            }
-          }
-        });
-
-      }
-    });
-    createPR(vm0, 0);
-
-    // Create a couple of buckets in VM0. This will make sure
-    // the next bucket we create will be created in VM 1.
-    putData(vm0, 0, 2, "a");
-
-    createPR(vm1, 0);
-
-    // Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
-    try {
-      putData(vm0, 3, 4, "a");
-      fail("should have received a cache closed exception");
-    } catch (RMIException e) {
-      if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
-        throw e;
-      }
-    }
-
-    assertEquals(Collections.singleton(3), getBucketList(vm1));
-
-    // This shouldn't hang, because the bucket creation should finish,.
-    putData(vm1, 3, 4, "a");
-  }
-
-  /**
-   * Test the we can handle a member departing while we are in the process of creating the bucket on
-   * the remote node.
-   */
-  @Test
-  public void testCrashDuringBucketCreation() throws Throwable {
-    Host host = Host.getHost(0);
-    final VM vm0 = host.getVM(0);
-    VM vm1 = host.getVM(1);
-
-    vm1.invoke(new SerializableRunnable("Install observer") {
-
-      public void run() {
-
-        DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
-
-          @Override
-          public void beforeProcessMessage(ClusterDistributionManager dm,
-              DistributionMessage message) {
-            if (message instanceof ManageBucketMessage) {
-              vm0.invoke(() -> disconnectFromDS());
-            }
-          }
-        });
-
-      }
-    });
-    createPR(vm0, 0);
-
-    // Create a couple of buckets in VM0. This will make sure
-    // the next bucket we create will be created in VM 1.
-    putData(vm0, 0, 2, "a");
-
-    createPR(vm1, 0);
-
-    // Trigger a bucket creation in VM1, which should cause vm0 to close it's cache.
-    try {
-      putData(vm0, 3, 4, "a");
-      fail("should have received a cache closed exception");
-    } catch (RMIException e) {
-      if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
-        throw e;
-      }
-    }
-
-    assertEquals(Collections.singleton(3), getBucketList(vm1));
-
-    // This shouldn't hang, because the bucket creation should finish,.
-    putData(vm1, 3, 4, "a");
-  }
-
-  private void createPR(VM vm0, final int redundancy) {
-    vm0.invoke(new SerializableRunnable("Create PR") {
-
-      public void run() {
-        Cache cache = getCache();
-        AttributesFactory af = new AttributesFactory();
-        PartitionAttributesFactory paf = new PartitionAttributesFactory();
-        paf.setRedundantCopies(redundancy);
-        af.setPartitionAttributes(paf.create());
-        af.setDataPolicy(DataPolicy.PARTITION);
-        cache.createRegion("region", af.create());
-      }
-
-    });
-  }
-
-  protected void putData(VM vm, final int startKey, final int endKey, final String value) {
-    SerializableRunnable createData = new SerializableRunnable() {
-
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion("region");
-
-        for (int i = startKey; i < endKey; i++) {
-          region.put(i, value);
-        }
-      }
-    };
-    vm.invoke(createData);
-  }
-
-  protected Set<Integer> getBucketList(VM vm0) {
-    return getBucketList(vm0, "region");
-  }
-
-  protected Set<Integer> getBucketList(VM vm0, final String regionName) {
-    SerializableCallable getBuckets = new SerializableCallable("get buckets") {
-
-      public Object call() throws Exception {
-        Cache cache = getCache();
-        PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
-        return new TreeSet<Integer>(region.getDataStore().getAllLocalBucketIds());
-      }
-    };
-
-    return (Set<Integer>) vm0.invoke(getBuckets);
-  }
-
-}

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

[geode] 11/19: GEODE-1279: Rename Bug40632DUnitTest as CreatePRWithLocalExpirationRegressionTest

Posted by kl...@apache.org.
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 f542032fa73c483c82eef1a5ac56def5c3d499dd
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Mar 22 12:40:13 2018 -0700

    GEODE-1279: Rename Bug40632DUnitTest as CreatePRWithLocalExpirationRegressionTest
    
    * Changed to IntegrationTest
    * Cleaned up test
---
 .../geode/internal/cache/Bug40632DUnitTest.java    | 109 ---------------------
 .../CreatePRWithLocalExpirationRegressionTest.java |  96 ++++++++++++++++++
 2 files changed, 96 insertions(+), 109 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40632DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40632DUnitTest.java
deleted file mode 100644
index 76f46fb..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug40632DUnitTest.java
+++ /dev/null
@@ -1,109 +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.ExpirationAction;
-import org.apache.geode.cache.ExpirationAttributes;
-import org.apache.geode.cache.PartitionAttributes;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-@Category(DistributedTest.class)
-public class Bug40632DUnitTest extends JUnit4CacheTestCase {
-
-  @Test
-  public void testLocalDestroyIdleTimeout() throws Exception {
-    Cache cache = getCache();
-    AttributesFactory attr = new AttributesFactory();
-    PartitionAttributesFactory paf = new PartitionAttributesFactory();
-    paf.setRedundantCopies(1);
-    paf.setRecoveryDelay(-1);
-    paf.setStartupRecoveryDelay(-1);
-    PartitionAttributes prAttr = paf.create();
-    attr.setStatisticsEnabled(true);
-    attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
-    attr.setPartitionAttributes(prAttr);
-    try {
-      cache.createRegion("region1", attr.create());
-      fail("We should not have been able to create the region");
-    } catch (IllegalStateException expected) {
-    }
-  }
-
-  @Test
-  public void testLocalDestroyTimeToLive() throws Exception {
-    Cache cache = getCache();
-    AttributesFactory attr = new AttributesFactory();
-    PartitionAttributesFactory paf = new PartitionAttributesFactory();
-    paf.setRedundantCopies(1);
-    paf.setRecoveryDelay(-1);
-    paf.setStartupRecoveryDelay(-1);
-    PartitionAttributes prAttr = paf.create();
-    attr.setStatisticsEnabled(true);
-    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
-    attr.setPartitionAttributes(prAttr);
-    try {
-      cache.createRegion("region1", attr.create());
-      fail("We should not have been able to create the region");
-    } catch (IllegalStateException expected) {
-    }
-  }
-
-  @Test
-  public void testLocalInvalidateIdleTimeout() throws Exception {
-    Cache cache = getCache();
-    AttributesFactory attr = new AttributesFactory();
-    PartitionAttributesFactory paf = new PartitionAttributesFactory();
-    paf.setRedundantCopies(1);
-    paf.setRecoveryDelay(-1);
-    paf.setStartupRecoveryDelay(-1);
-    PartitionAttributes prAttr = paf.create();
-    attr.setStatisticsEnabled(true);
-    attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
-    attr.setPartitionAttributes(prAttr);
-    try {
-      cache.createRegion("region1", attr.create());
-      fail("We should not have been able to create the region");
-    } catch (IllegalStateException expected) {
-    }
-  }
-
-  @Test
-  public void testLocalInvalidateTimeToLive() throws Exception {
-    Cache cache = getCache();
-    AttributesFactory attr = new AttributesFactory();
-    PartitionAttributesFactory paf = new PartitionAttributesFactory();
-    paf.setRedundantCopies(1);
-    paf.setRecoveryDelay(-1);
-    paf.setStartupRecoveryDelay(-1);
-    PartitionAttributes prAttr = paf.create();
-    attr.setStatisticsEnabled(true);
-    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
-    attr.setPartitionAttributes(prAttr);
-    try {
-      cache.createRegion("region1", attr.create());
-      fail("We should not have been able to create the region");
-    } catch (IllegalStateException expected) {
-    }
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/CreatePRWithLocalExpirationRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/CreatePRWithLocalExpirationRegressionTest.java
new file mode 100644
index 0000000..c88f8bf
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/CreatePRWithLocalExpirationRegressionTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.apache.geode.cache.ExpirationAction.LOCAL_DESTROY;
+import static org.apache.geode.cache.ExpirationAction.LOCAL_INVALIDATE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+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.CacheFactory;
+import org.apache.geode.cache.ExpirationAttributes;
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * PRWithLocalExpirationRegressionTest
+ *
+ * TRAC #40632: PR expiration with localDestroy fails with InternalGemFireError
+ */
+@Category(IntegrationTest.class)
+public class CreatePRWithLocalExpirationRegressionTest {
+
+  private Cache cache;
+  private AttributesFactory attributesFactory;
+
+  @Before
+  public void setUp() {
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+
+    PartitionAttributesFactory paf = new PartitionAttributesFactory();
+    paf.setRecoveryDelay(-1);
+    paf.setRedundantCopies(1);
+    paf.setStartupRecoveryDelay(-1);
+
+    attributesFactory = new AttributesFactory();
+    attributesFactory.setPartitionAttributes(paf.create());
+    attributesFactory.setStatisticsEnabled(true);
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void createPrWithEntryIdleTimeoutLocalDestroyThrows() throws Exception {
+    attributesFactory.setEntryIdleTimeout(new ExpirationAttributes(1000, LOCAL_DESTROY));
+
+    assertThatThrownBy(() -> cache.createRegion("region1", attributesFactory.create()))
+        .isInstanceOf(IllegalStateException.class);
+  }
+
+  @Test
+  public void createPrWithEntryTimeToLiveLocalDestroyThrows() throws Exception {
+    attributesFactory.setEntryTimeToLive(new ExpirationAttributes(1000, LOCAL_DESTROY));
+
+    assertThatThrownBy(() -> cache.createRegion("region1", attributesFactory.create()))
+        .isInstanceOf(IllegalStateException.class);
+  }
+
+  @Test
+  public void createPrWithEntryIdleTimeoutLocalInvalidateThrows() throws Exception {
+    attributesFactory.setEntryIdleTimeout(new ExpirationAttributes(1000, LOCAL_INVALIDATE));
+
+    assertThatThrownBy(() -> cache.createRegion("region1", attributesFactory.create()))
+        .isInstanceOf(IllegalStateException.class);
+  }
+
+  @Test
+  public void createPrWithEntryTimeToLiveLocalInvalidateThrows() throws Exception {
+    attributesFactory.setEntryTimeToLive(new ExpirationAttributes(1000, LOCAL_INVALIDATE));
+
+    assertThatThrownBy(() -> cache.createRegion("region1", attributesFactory.create()))
+        .isInstanceOf(IllegalStateException.class);
+  }
+}

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

[geode] 19/19: GEODE-1279: Rename Bug36853EventsExpiryDUnitTest as ClientSubscriptionExpiryDataLossRegressionTest

Posted by kl...@apache.org.
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 3b32fd569b196f7ad1d3e9460f3d5debf67d3ae0
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Mar 23 16:38:33 2018 -0700

    GEODE-1279: Rename Bug36853EventsExpiryDUnitTest as ClientSubscriptionExpiryDataLossRegressionTest
    
    * Rewrite test with a spy CacheListener.
---
 .../cache/ha/Bug36853EventsExpiryDUnitTest.java    | 268 ---------------------
 ...ntSubscriptionExpiryDataLossRegressionTest.java | 195 +++++++++++++++
 2 files changed, 195 insertions(+), 268 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ha/Bug36853EventsExpiryDUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/Bug36853EventsExpiryDUnitTest.java
deleted file mode 100755
index 8dee70b..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/ha/Bug36853EventsExpiryDUnitTest.java
+++ /dev/null
@@ -1,268 +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.ha;
-
-import static org.apache.geode.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Properties;
-
-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.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.EntryEvent;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.cache.util.CacheListenerAdapter;
-import org.apache.geode.cache30.CacheTestCase;
-import org.apache.geode.cache30.ClientServerTestCase;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.IgnoredException;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * This is a bug test for 36853 (Expiry logic in HA is used to expire early data that a secondary
- * picks up that is not in the primary. But it is also possible that it would cause data that is in
- * the primary queue to be expired. And this can cause a data loss. This issue is mostly related to
- * Expiry mechanism and not HA, but it affects HA functionality).
- *
- * This test has a cache-client connected to one cache-server. The expiry-time of events in the
- * queue for the client at the server is set low and dispatcher is set for delayed start. This will
- * make some of the events in the queue expire before dispatcher can start picking them up for
- * delivery to the client.
- */
-@Category({DistributedTest.class, ClientSubscriptionTest.class})
-public class Bug36853EventsExpiryDUnitTest extends JUnit4CacheTestCase {
-
-  /** Cache-server */
-  private VM server = null;
-
-  /** Client , connected to Cache-server */
-  private VM client = null;
-
-  /** Name of the test region */
-  private static final String REGION_NAME =
-      Bug36853EventsExpiryDUnitTest.class.getSimpleName() + "_region";
-
-  /** The cache instance for test cases */
-  private static Cache cache = null;
-
-  /** Boolean to indicate the client to proceed for validation */
-  private static volatile boolean proceedForValidation = false;
-
-  /** Counter to indicate number of puts recieved by client */
-  private static volatile int putsRecievedByClient;
-
-  /** The last key for operations, to notify for proceeding to validation */
-  private static final String LAST_KEY = "LAST_KEY";
-
-  /** The time in milliseconds by which the start of dispatcher will be delayed */
-  private static final int DISPATCHER_SLOWSTART_TIME = 10000;
-
-  /** Number of puts done for the test */
-  private static final int TOTAL_PUTS = 5;
-
-  @Override
-  public final void preSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    final Host host = Host.getHost(0);
-    server = host.getVM(0);
-    client = host.getVM(1);
-    server.invoke(() -> ConflationDUnitTest.setIsSlowStart());
-    int PORT2 = ((Integer) server.invoke(() -> Bug36853EventsExpiryDUnitTest.createServerCache()))
-        .intValue();
-
-    client.invoke(() -> Bug36853EventsExpiryDUnitTest
-        .createClientCache(NetworkUtils.getServerHostName(host), new Integer(PORT2)));
-  }
-
-  /**
-   * Creates the cache
-   *
-   * @param props - distributed system props
-   * @throws Exception - thrown in any problem occurs in creating cache
-   */
-  private void createCache(Properties props) throws Exception {
-    DistributedSystem ds = getSystem(props);
-    cache = CacheFactory.create(ds);
-    assertNotNull(cache);
-  }
-
-  /**
-   * Creates cache and starts the bridge-server
-   */
-  private static Integer createServerCache() throws Exception {
-    System.setProperty(HARegionQueue.REGION_ENTRY_EXPIRY_TIME, "1");
-    System.setProperty("slowStartTimeForTesting", String.valueOf(DISPATCHER_SLOWSTART_TIME));
-    new Bug36853EventsExpiryDUnitTest().createCache(new Properties());
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setDataPolicy(DataPolicy.REPLICATE);
-    RegionAttributes attrs = factory.create();
-    cache.createRegion(REGION_NAME, attrs);
-
-    CacheServer server = cache.addCacheServer();
-    assertNotNull(server);
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    server.setPort(port);
-    server.setNotifyBySubscription(true);
-    server.start();
-    return new Integer(server.getPort());
-  }
-
-  /**
-   * Creates the client cache
-   *
-   * @param hostName the name of the server's machine
-   * @param port - bridgeserver port
-   * @throws Exception - thrown if any problem occurs in setting up the client
-   */
-  private static void createClientCache(String hostName, Integer port) throws Exception {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOCATORS, "");
-    new Bug36853EventsExpiryDUnitTest().createCache(props);
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    ClientServerTestCase.configureConnectionPool(factory, hostName, port.intValue(), -1, true, -1,
-        2, null);
-
-    factory.addCacheListener(new CacheListenerAdapter() {
-      public void afterCreate(EntryEvent event) {
-        String key = (String) event.getKey();
-        LogWriterUtils.getLogWriter().info("client2 : afterCreate : key =" + key);
-        if (key.equals(LAST_KEY)) {
-
-          synchronized (Bug36853EventsExpiryDUnitTest.class) {
-            LogWriterUtils.getLogWriter().info("Notifying client2 to proceed for validation");
-            proceedForValidation = true;
-            Bug36853EventsExpiryDUnitTest.class.notify();
-          }
-        } else {
-          putsRecievedByClient++;
-        }
-      }
-    });
-    RegionAttributes attrs = factory.create();
-    Region region = cache.createRegion(REGION_NAME, attrs);
-
-    region.registerInterest("ALL_KEYS");
-  }
-
-  /**
-   * First generates some events, then waits for the time equal to that of delayed start of the
-   * dispatcher and then does put on the last key for few iterations. The idea is to let the events
-   * added, before waiting, to expire before the dispatcher to pick them up and then do a put on a
-   * LAST_KEY couple of times so that atleast one of these is dispatched to client and when client
-   * recieves this in the listener, the test is notified to proceed for validation.
-   *
-   * @throws Exception - thrown if any problem occurs in put operation
-   */
-  private static void generateEvents() throws Exception {
-    String regionName = Region.SEPARATOR + REGION_NAME;
-    Region region = cache.getRegion(regionName);
-    for (int i = 0; i < TOTAL_PUTS; i++) {
-
-      region.put("key" + i, "val-" + i);
-    }
-    Thread.sleep(DISPATCHER_SLOWSTART_TIME + 1000);
-    for (int i = 0; i < 25; i++) {
-
-      region.put(LAST_KEY, "LAST_VALUE");
-    }
-  }
-
-  /**
-   * First generates some events, then waits for the time equal to that of delayed start of the
-   * dispatcher and then does put on the last key for few iterations. Whenever the client the create
-   * corresponding to the LAST_KEY in the listener, the test is notified to proceed for validation.
-   * Then, it is validated that all the events that were added prior to the LAST_KEY are dispatched
-   * to the client. Due to the bug#36853, those events will expire and validation will fail.
-   *
-   * @throws Exception - thrown if any exception occurs in test
-   */
-  @Test
-  public void testEventsExpiryBug() throws Exception {
-    IgnoredException.addIgnoredException("Unexpected IOException");
-    IgnoredException.addIgnoredException("Connection reset");
-    server.invoke(() -> Bug36853EventsExpiryDUnitTest.generateEvents());
-    client.invoke(() -> Bug36853EventsExpiryDUnitTest.validateEventCountAtClient());
-  }
-
-  /**
-   * Waits for the listener to receive all events and validates that no exception occurred in client
-   */
-  private static void validateEventCountAtClient() throws Exception {
-    if (!proceedForValidation) {
-      synchronized (Bug36853EventsExpiryDUnitTest.class) {
-        if (!proceedForValidation)
-          try {
-            LogWriterUtils.getLogWriter().info("Client2 going in wait before starting validation");
-            Bug36853EventsExpiryDUnitTest.class.wait(5000);
-          } catch (InterruptedException e) {
-            fail("interrupted");
-          }
-      }
-    }
-    LogWriterUtils.getLogWriter().info("Starting validation on client2");
-    assertEquals("Puts recieved by client not equal to the puts done at server.", TOTAL_PUTS,
-        putsRecievedByClient);
-    LogWriterUtils.getLogWriter().info("putsRecievedByClient = " + putsRecievedByClient);
-    LogWriterUtils.getLogWriter().info("Validation complete on client2");
-
-  }
-
-  /**
-   * Closes the cache
-   *
-   */
-  private static void unSetExpiryTimeAndCloseCache() {
-    System.clearProperty(HARegionQueue.REGION_ENTRY_EXPIRY_TIME);
-    CacheTestCase.closeCache();
-  }
-
-  /**
-   * Closes the caches on clients and servers
-   *
-   * @throws Exception - thrown if any problem occurs in closing client and server caches.
-   */
-  @Override
-  public final void preTearDownCacheTestCase() throws Exception {
-    // close client
-    client.invoke(() -> Bug36853EventsExpiryDUnitTest.unSetExpiryTimeAndCloseCache());
-    // close server
-    server.invoke(() -> Bug36853EventsExpiryDUnitTest.unSetExpiryTimeAndCloseCache());
-
-  }
-
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ha/ClientSubscriptionExpiryDataLossRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/ClientSubscriptionExpiryDataLossRegressionTest.java
new file mode 100755
index 0000000..668ea8b
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ha/ClientSubscriptionExpiryDataLossRegressionTest.java
@@ -0,0 +1,195 @@
+/*
+ * 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.ha;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.geode.cache30.ClientServerTestCase.configureConnectionPool;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest.setIsSlowStart;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
+import static org.awaitility.Awaitility.await;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+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.CacheListener;
+import org.apache.geode.cache.DataPolicy;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.CacheTestCase;
+import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties;
+import org.apache.geode.test.junit.categories.ClientSubscriptionTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * This is a bug test for 36853 (Expiry logic in HA is used to expire early data that a secondary
+ * picks up that is not in the primary. But it is also possible that it would cause data that is in
+ * the primary queue to be expired. And this can cause a data loss. This issue is mostly related to
+ * Expiry mechanism and not HA, but it affects HA functionality).
+ *
+ * <p>
+ * This test has a cache-client connected to one cache-server. The expiry-time of events in the
+ * queue for the client at the server is set low and dispatcher is set for delayed start. This will
+ * make some of the events in the queue expire before dispatcher can start picking them up for
+ * delivery to the client.
+ *
+ * <p>
+ * TRAC #36853: HA events can expire on primary server and this can cause data loss.
+ */
+@Category({DistributedTest.class, ClientSubscriptionTest.class})
+public class ClientSubscriptionExpiryDataLossRegressionTest extends CacheTestCase {
+
+  /** The time in milliseconds by which the start of dispatcher will be delayed */
+  private static final int DISPATCHER_SLOWSTART_TIME = 10_000;
+  private static final int PUT_COUNT = 5;
+
+  private static CacheListener<String, String> spyCacheListener;
+
+  private String uniqueName;
+  private String hostName;
+  private int serverPort;
+
+  private VM server;
+  private VM client;
+
+  @Rule
+  public DistributedRestoreSystemProperties restoreSystemProperties =
+      new DistributedRestoreSystemProperties();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server = getHost(0).getVM(0);
+    client = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    hostName = getServerHostName(getHost(0));
+
+    server.invoke(() -> setIsSlowStart());
+    serverPort = server.invoke(() -> createServerCache());
+
+    client.invoke(() -> createClientCache());
+
+    addIgnoredException("Unexpected IOException");
+    addIgnoredException("Connection reset");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+  }
+
+  /**
+   * First generate some events, then wait for some time to let the initial events expire before
+   * the dispatcher sends them to the client. Then do one final put so that the client knows when
+   * to being validation.
+   *
+   * <p>
+   * Client is waiting for afterCreate to be invoked number of PUT_COUNT times before proceeding
+   * with validation.
+   *
+   * <p>
+   * If the bug exists or is reintroduced, then the events will expire without reaching the client.
+   */
+  @Test
+  public void allEventsShouldReachClientWithoutExpiring() throws Exception {
+    server.invoke(() -> generateEvents());
+    client.invoke(() -> validateEventCountAtClient());
+  }
+
+  private int createServerCache() throws IOException {
+    System.setProperty(HARegionQueue.REGION_ENTRY_EXPIRY_TIME, String.valueOf(1));
+    System.setProperty("slowStartTimeForTesting", String.valueOf(DISPATCHER_SLOWSTART_TIME));
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.REPLICATE);
+
+    getCache().createRegion(uniqueName, factory.create());
+
+    CacheServer server = getCache().addCacheServer();
+    server.setPort(0);
+    server.setNotifyBySubscription(true);
+    server.start();
+    return server.getPort();
+  }
+
+  private void createClientCache() {
+    Properties config = new Properties();
+    config.setProperty(MCAST_PORT, "0");
+    config.setProperty(LOCATORS, "");
+
+    getCache(config);
+
+    spyCacheListener = spy(CacheListener.class);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.addCacheListener(spyCacheListener);
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+
+    configureConnectionPool(factory, hostName, serverPort, -1, true, -1, 2, null);
+
+    Region region = getCache().createRegion(uniqueName, factory.create());
+
+    region.registerInterest("ALL_KEYS");
+  }
+
+  /**
+   * First generate some events, then wait for some time to let the initial events expire before
+   * the dispatcher sends them to the client. Then do one final put so that the client knows when
+   * to being validation.
+   *
+   * <p>
+   * Client is waiting for afterCreate to be invoked number of PUT_COUNT times before proceeding
+   * with validation.
+   */
+  private void generateEvents() throws InterruptedException {
+    Region<String, String> region = getCache().getRegion(uniqueName);
+    for (int i = 0; i < PUT_COUNT - 1; i++) {
+      region.put("key" + i, "val-" + i);
+    }
+
+    Thread.sleep(DISPATCHER_SLOWSTART_TIME + 1000);
+
+    region.put("key" + PUT_COUNT, "LAST_VALUE");
+  }
+
+  /**
+   * Waits for the listener to receive all events
+   */
+  private void validateEventCountAtClient() {
+    await().atMost(1, MINUTES)
+        .until(() -> verify(spyCacheListener, times(PUT_COUNT)).afterCreate(any()));
+  }
+}

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

[geode] 09/19: GEODE-1279: Rename Bug39079DUnitTest

Posted by kl...@apache.org.
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 0e6a1b9e0ea0b3cbfeac8c18f4b67ada1972a0bb
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Wed Mar 21 17:49:33 2018 -0700

    GEODE-1279: Rename Bug39079DUnitTest
    
    This test has been split into:
    * GiiDiskAccessExceptionRegressionTest
    * InitializedDiskRegionWithIoExceptionRegressionTest
---
 .../geode/internal/cache/Bug39079DUnitTest.java    | 341 ---------------------
 .../GiiDiskAccessExceptionRegressionTest.java      | 211 +++++++++++++
 ...zedDiskRegionWithIoExceptionRegressionTest.java | 174 +++++++++++
 3 files changed, 385 insertions(+), 341 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug39079DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug39079DUnitTest.java
deleted file mode 100644
index 15a9a4d..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug39079DUnitTest.java
+++ /dev/null
@@ -1,341 +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.apache.geode.distributed.ConfigurationProperties.*;
-import static org.apache.geode.test.dunit.Assert.*;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-
-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.DiskAccessException;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.cache30.CacheSerializableRunnable;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.entries.VMThinDiskRegionEntryHeapObjectKey;
-import org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * Tests that if a node doing GII experiences DiskAccessException, it should also not try to recover
- * from the disk
- */
-@Category(DistributedTest.class)
-public class Bug39079DUnitTest extends JUnit4CacheTestCase {
-
-  private static final String REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase =
-      "IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase";
-  private static final String REGION_NAME_testGIIDiskAccessException =
-      "IGNORE_EXCEPTION_testGIIDiskAccessException";
-
-  private VM vm0;
-  private VM vm1;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-
-    final Host host = Host.getHost(0);
-    vm0 = host.getVM(0);
-    vm1 = host.getVM(1);
-
-    vm0.invoke(() -> ignorePreAllocate(true));
-    vm1.invoke(() -> ignorePreAllocate(true));
-  }
-
-  @Override
-  public final void postTearDownCacheTestCase() throws Exception {
-    disconnectAllFromDS();
-
-    vm0.invoke(() -> ignorePreAllocate(false));
-    vm1.invoke(() -> ignorePreAllocate(false));
-  }
-
-  /**
-   * If the node experiences disk access exception during GII, it should get destroyed & not attempt
-   * to recover from the disk
-   */
-  @Test
-  public void testGIIDiskAccessException() throws Exception {
-    vm0.invoke(createCacheForVM0());
-    vm1.invoke(createCacheForVM1());
-
-    // Create DiskRegion locally in controller VM also
-    getSystem();
-
-
-    assertTrue(getCache() != null);
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-    factory.setDiskSynchronous(false);
-    factory.setDiskStoreName(getCache().createDiskStoreFactory().setDiskDirs(getDiskDirs())
-        .create(getClass().getSimpleName()).getName());
-    RegionAttributes attr = factory.create();
-    Region region = getCache().createRegion(REGION_NAME_testGIIDiskAccessException, attr);
-
-    // Now put entries in the disk region
-    for (int i = 0; i < 100; ++i) {
-      region.put(new Integer(i), new Integer(i));
-    }
-
-    // Now close the region in the controller VM
-    region.close();
-
-    // Now recreate the region but set the factory such that disk region entry object
-    // used is customized by us to throw exception while writing to disk
-
-    DistributedRegion distRegion =
-        new DistributedRegion(REGION_NAME_testGIIDiskAccessException, attr, null,
-            (GemFireCacheImpl) getCache(), new InternalRegionArguments().setDestroyLockFlag(true)
-                .setRecreateFlag(false).setSnapshotInputStream(null).setImageTarget(null));
-
-    distRegion.entries.setEntryFactory(TestAbstractDiskRegionEntry.getEntryFactory());
-    region = null;
-
-    try {
-      region =
-          ((GemFireCacheImpl) getCache()).createVMRegion(REGION_NAME_testGIIDiskAccessException,
-              attr, new InternalRegionArguments().setInternalMetaRegion(distRegion)
-                  .setDestroyLockFlag(true).setSnapshotInputStream(null).setImageTarget(null));
-      fail("Expected DiskAccessException");
-    } catch (DiskAccessException expected) {
-    }
-
-    assertTrue(region == null || region.isDestroyed()); // TODO: why is this an OR instead of
-                                                        // deterministic?
-  }
-
-  /**
-   * If IOException occurs while updating an entry in an already initialized DiskRegion ,then the
-   * bridge servers should be stopped , if any running
-   */
-  @Test
-  public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() throws Exception {
-    // create server cache
-    Integer port = vm0.invoke(() -> createServerCache());
-
-    // create cache client
-    vm1.invoke(() -> createClientCache(NetworkUtils.getServerHostName(vm0.getHost()), port));
-
-    // validate
-    vm0.invoke(() -> validateRunningBridgeServerList());
-
-    // close server cache
-    vm0.invoke(() -> closeCacheAndDisconnect());
-
-    // close client cache
-    vm1.invoke(() -> closeCacheAndDisconnect());
-  }
-
-  private int createServerCache() throws IOException {
-    createCache(new Properties());
-    DiskRegionProperties props = new DiskRegionProperties();
-    props.setRegionName(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase);
-    props.setOverflow(true);
-    props.setRolling(true);
-    props.setDiskDirs(getDiskDirs());
-    props.setPersistBackup(true);
-
-    Region region =
-        DiskRegionHelperFactory.getSyncPersistOnlyRegion(getCache(), props, Scope.DISTRIBUTED_ACK);
-    assertNotNull(region);
-    CacheServer bs1 = getCache().addCacheServer();
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    bs1.setPort(port);
-    bs1.start();
-    return bs1.getPort();
-  }
-
-  private void closeCacheAndDisconnect() {
-    closeCache();
-    disconnectFromDS();
-  }
-
-  private void createCache(Properties props) {
-    getSystem(props);
-    assertNotNull(getCache());
-  }
-
-  private void validateRunningBridgeServerList() throws IOException {
-    Region region = getCache()
-        .getRegion(REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase);
-    try {
-      region.create("key1", new byte[16]);
-      region.create("key2", new byte[16]);
-
-      // Get the oplog handle & hence the underlying file & close it
-      UninterruptibleFileChannel oplogFileChannel =
-          ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
-
-      try {
-        oplogFileChannel.close();
-        region.put("key2", new byte[16]);
-        fail("Expected DiskAccessException");
-      } catch (DiskAccessException expected) {
-      }
-
-      ((LocalRegion) region).getDiskStore().waitForClose();
-      assertTrue(region.getRegionService().isClosed());
-
-      region = null;
-      List bsRunning = getCache().getCacheServers();
-      assertTrue(bsRunning.isEmpty());
-    } finally {
-      if (region != null) {
-        region.destroyRegion();
-      }
-    }
-  }
-
-  private void createClientCache(String host, Integer port1) {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOCATORS, "");
-    createCache(props);
-
-    PoolImpl pool = (PoolImpl) PoolManager.createFactory().addServer(host, port1.intValue())
-        .setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true)
-        .setMinConnections(0).setReadTimeout(20000).setRetryAttempts(1)
-        .create(getClass().getSimpleName());
-
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setPoolName(pool.getName());
-
-    RegionAttributes attrs = factory.create();
-    Region region = getCache().createRegion(
-        REGION_NAME_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase, attrs);
-    region.registerInterest("ALL_KEYS");
-  }
-
-  /**
-   * This method is used to create Cache in VM0
-   */
-  private CacheSerializableRunnable createCacheForVM0() {
-    return new CacheSerializableRunnable("createCache") {
-      @Override
-      public void run2() {
-        try {
-          getSystem();
-          assertNotNull(getCache());
-
-          AttributesFactory factory = new AttributesFactory();
-          factory.setScope(Scope.DISTRIBUTED_ACK);
-          factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-          factory.setDiskSynchronous(false);
-          factory.setDiskStoreName(getCache().createDiskStoreFactory().setDiskDirs(getDiskDirs())
-              .create(getClass().getSimpleName()).getName());
-
-          RegionAttributes attr = factory.create();
-          getCache().createRegion(REGION_NAME_testGIIDiskAccessException, attr);
-        } catch (Exception ex) {
-          fail("Error Creating cache / region ", ex);
-        }
-      }
-    };
-  }
-
-  /**
-   * This method is used to create Cache in VM1
-   */
-  private CacheSerializableRunnable createCacheForVM1() {
-    return new CacheSerializableRunnable("createCache") {
-      @Override
-      public void run2() {
-        try {
-          getSystem();
-          assertNotNull(getCache());
-
-          AttributesFactory factory = new AttributesFactory();
-          factory.setScope(Scope.DISTRIBUTED_ACK);
-          factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-          factory.setDiskSynchronous(false);
-          factory.setDiskStoreName(getCache().createDiskStoreFactory().setDiskDirs(getDiskDirs())
-              .create(getClass().getSimpleName()).getName());
-
-          RegionAttributes attr = factory.create();
-          getCache().createRegion(REGION_NAME_testGIIDiskAccessException, attr);
-        } catch (Exception ex) {
-          fail("Error Creating cache / region ", ex);
-        }
-      }
-    };
-  }
-
-  private void ignorePreAllocate(boolean flag) throws Exception {
-    DiskStoreImpl.SET_IGNORE_PREALLOCATE = flag;
-  }
-
-  private static class TestAbstractDiskRegionEntry extends VMThinDiskRegionEntryHeapObjectKey {
-
-    protected TestAbstractDiskRegionEntry(RegionEntryContext r, Object key, Object value) {
-      super(r, key, value);
-    }
-
-    private static RegionEntryFactory factory = new RegionEntryFactory() {
-
-      @Override
-      public RegionEntry createEntry(RegionEntryContext r, Object key, Object value) {
-        throw new DiskAccessException(new IOException("Test Exception"));
-      }
-
-      @Override
-      public Class getEntryClass() {
-        return getClass();
-      }
-
-      @Override
-      public RegionEntryFactory makeVersioned() {
-        return this;
-      }
-
-      @Override
-      public RegionEntryFactory makeOnHeap() {
-        return this;
-      }
-    };
-
-    /**
-     * Overridden setValue method to throw exception
-     */
-    @Override
-    protected void setValueField(Object v) {
-      throw new DiskAccessException(new IOException("Test Exception"));
-    }
-
-    public static RegionEntryFactory getEntryFactory() {
-      return factory;
-    }
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/GiiDiskAccessExceptionRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/GiiDiskAccessExceptionRegressionTest.java
new file mode 100644
index 0000000..78de8bc
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/GiiDiskAccessExceptionRegressionTest.java
@@ -0,0 +1,211 @@
+/*
+ * 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.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+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.DiskAccessException;
+import org.apache.geode.cache.DiskStore;
+import org.apache.geode.cache.DiskStoreFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+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;
+
+/**
+ * Tests that if a node doing GII experiences DiskAccessException, it should also not try to recover
+ * from the disk
+ *
+ * GiiDiskAccessExceptionRegressionTest
+ *
+ * <p>
+ * TRAC #39079: Regions with persistence remain in use after IOException have occurred
+ */
+@Category(DistributedTest.class)
+public class GiiDiskAccessExceptionRegressionTest extends CacheTestCase {
+
+  private String uniqueName;
+
+  private File[] vm0DiskDirs;
+  private File[] vm1DiskDirs;
+  private File[] controllerDiskDirs;
+
+  private VM vm0;
+  private VM vm1;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    vm0 = getHost(0).getVM(0);
+    vm1 = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    vm0DiskDirs = new File[] {temporaryFolder.newFolder(uniqueName + "_vm0_disk")};
+    vm1DiskDirs = new File[] {temporaryFolder.newFolder(uniqueName + "_vm1_disk")};
+    controllerDiskDirs = new File[] {temporaryFolder.newFolder(uniqueName + "_controller_disk")};
+
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = true;
+
+    invokeInEveryVM(() -> {
+      DiskStoreImpl.SET_IGNORE_PREALLOCATE = true;
+    });
+
+    addIgnoredException(uniqueName);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = false;
+
+    invokeInEveryVM(() -> {
+      DiskStoreImpl.SET_IGNORE_PREALLOCATE = false;
+    });
+  }
+
+  /**
+   * If the node experiences disk access exception during GII, it should get destroyed & not attempt
+   * to recover from the disk
+   */
+  @Test
+  public void diskAccessExceptionDuringGiiShouldShutdown() throws Exception {
+    vm0.invoke(() -> createCacheForVM0());
+    vm1.invoke(() -> createCacheForVM1());
+
+    // Create DiskRegion locally in controller VM also
+    DiskStoreFactory diskStoreFactory = getCache().createDiskStoreFactory();
+    diskStoreFactory.setDiskDirs(controllerDiskDirs);
+
+    DiskStore diskStore = diskStoreFactory.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskSynchronous(false);
+    factory.setDiskStoreName(diskStore.getName());
+
+    Region<Integer, Integer> region = getCache().createRegion(uniqueName, factory.create());
+
+    // Now put entries in the disk region
+    for (int i = 0; i < 100; ++i) {
+      region.put(i, i);
+    }
+
+    // Now close the region in the controller VM
+    region.close();
+
+    // Now recreate the region but set the factory such that disk region entry object
+    // used is customized by us to throw exception while writing to disk
+
+    DistributedRegion distributedRegion = new DistributedRegion(uniqueName, factory.create(), null,
+        getCache(), new InternalRegionArguments().setDestroyLockFlag(true).setRecreateFlag(false)
+            .setSnapshotInputStream(null).setImageTarget(null));
+
+    distributedRegion.entries.setEntryFactory(new DiskRegionEntryThrowsFactory());
+
+    InternalRegionArguments internalRegionArguments = new InternalRegionArguments();
+    internalRegionArguments.setInternalMetaRegion(distributedRegion);
+    internalRegionArguments.setDestroyLockFlag(true);
+    internalRegionArguments.setSnapshotInputStream(null);
+    internalRegionArguments.setImageTarget(null);
+
+    assertThatThrownBy(
+        () -> getCache().createVMRegion(uniqueName, factory.create(), internalRegionArguments))
+            .isInstanceOf(DiskAccessException.class);
+  }
+
+  /**
+   * This method is used to create Cache in VM0
+   */
+  private void createCacheForVM0() {
+    DiskStoreFactory diskStoreFactory = getCache().createDiskStoreFactory();
+    diskStoreFactory.setDiskDirs(vm0DiskDirs);
+
+    DiskStore diskStore = diskStoreFactory.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskStoreName(diskStore.getName());
+    factory.setDiskSynchronous(false);
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+
+    getCache().createRegion(uniqueName, factory.create());
+  }
+
+  /**
+   * This method is used to create Cache in VM1
+   */
+  private void createCacheForVM1() {
+    DiskStoreFactory diskStoreFactory = getCache().createDiskStoreFactory();
+    diskStoreFactory.setDiskDirs(vm1DiskDirs);
+
+    DiskStore diskStore = diskStoreFactory.create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
+    factory.setDiskStoreName(diskStore.getName());
+    factory.setDiskSynchronous(false);
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+
+    getCache().createRegion(uniqueName, factory.create());
+  }
+
+  private class DiskRegionEntryThrowsFactory implements RegionEntryFactory {
+
+    @Override
+    public RegionEntry createEntry(RegionEntryContext context, Object key, Object value) {
+      throw new DiskAccessException(new IOException(uniqueName));
+    }
+
+    @Override
+    public Class getEntryClass() {
+      return getClass();
+    }
+
+    @Override
+    public RegionEntryFactory makeVersioned() {
+      return this;
+    }
+
+    @Override
+    public RegionEntryFactory makeOnHeap() {
+      return this;
+    }
+  }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/InitializedDiskRegionWithIoExceptionRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/InitializedDiskRegionWithIoExceptionRegressionTest.java
new file mode 100644
index 0000000..53b0823
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/InitializedDiskRegionWithIoExceptionRegressionTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+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.DiskAccessException;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.cache.persistence.DiskRecoveryStore;
+import org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel;
+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;
+
+/**
+ * If IOException occurs while updating an entry in an already initialized DiskRegion, then the
+ * cache server should be stopped.
+ *
+ * <p>
+ * TRAC #39079: Regions with persistence remain in use after IOException have occurred
+ */
+@Category(DistributedTest.class)
+public class InitializedDiskRegionWithIoExceptionRegressionTest extends CacheTestCase {
+
+  private String hostName;
+  private String uniqueName;
+
+  private File[] serverDiskDirs;
+
+  private VM server;
+  private VM client;
+
+  @Rule
+  public SerializableTemporaryFolder temporaryFolder = new SerializableTemporaryFolder();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server = getHost(0).getVM(0);
+    client = getHost(0).getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    serverDiskDirs = new File[] {temporaryFolder.newFolder(uniqueName + "_server1_disk")};
+
+    hostName = getServerHostName(server.getHost());
+
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = true;
+
+    invokeInEveryVM(() -> {
+      DiskStoreImpl.SET_IGNORE_PREALLOCATE = true;
+    });
+
+    addIgnoredException(uniqueName);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    disconnectAllFromDS();
+
+    DiskStoreImpl.SET_IGNORE_PREALLOCATE = false;
+
+    invokeInEveryVM(() -> {
+      DiskStoreImpl.SET_IGNORE_PREALLOCATE = false;
+    });
+  }
+
+  @Test
+  public void cacheServerPersistWithIOExceptionShouldShutdown() throws Exception {
+    // create server cache
+    int port = server.invoke(() -> createServerCache());
+
+    // create cache client
+    client.invoke(() -> createClientCache(hostName, port));
+
+    // validate
+    server.invoke(() -> validateNoCacheServersRunning());
+  }
+
+  private int createServerCache() throws IOException {
+    DiskRegionProperties props = new DiskRegionProperties();
+    props.setRegionName(uniqueName);
+    props.setOverflow(true);
+    props.setRolling(true);
+    props.setDiskDirs(serverDiskDirs);
+    props.setPersistBackup(true);
+
+    DiskRegionHelperFactory.getSyncPersistOnlyRegion(getCache(), props, Scope.DISTRIBUTED_ACK);
+
+    CacheServer cacheServer = getCache().addCacheServer();
+    cacheServer.setPort(0);
+    cacheServer.start();
+    return cacheServer.getPort();
+  }
+
+  private void validateNoCacheServersRunning() throws IOException {
+    Region<String, byte[]> region = getCache().getRegion(uniqueName);
+
+    region.create("key1", new byte[16]);
+    region.create("key2", new byte[16]);
+
+    // Get the oplog handle & hence the underlying file & close it
+    UninterruptibleFileChannel oplogFileChannel =
+        ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
+    oplogFileChannel.close();
+
+    assertThatThrownBy(() -> region.put("key2", new byte[16]))
+        .isInstanceOf(DiskAccessException.class);
+
+    ((DiskRecoveryStore) region).getDiskStore().waitForClose();
+    assertThat(region.getRegionService().isClosed()).isTrue();
+
+    List<CacheServer> cacheServers = getCache().getCacheServers();
+    assertThat(cacheServers).isEmpty();
+  }
+
+  private void createClientCache(String host, int port) {
+    Properties config = new Properties();
+    config.setProperty(MCAST_PORT, "0");
+    config.setProperty(LOCATORS, "");
+    getCache(config);
+
+    Pool pool = PoolManager.createFactory().addServer(host, port).setSubscriptionEnabled(true)
+        .setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(0)
+        .setReadTimeout(20000).setRetryAttempts(1).create(uniqueName);
+
+    AttributesFactory factory = new AttributesFactory();
+    factory.setScope(Scope.DISTRIBUTED_ACK);
+    factory.setPoolName(pool.getName());
+
+    Region region = getCache().createRegion(uniqueName, factory.create());
+
+    region.registerInterest("ALL_KEYS");
+  }
+}

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

[geode] 18/19: GEODE-1279: Rename Bug47667DUnitTest as ClientTxCommitShouldNotHangRegressionTest

Posted by kl...@apache.org.
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 534944752fdff0c0934db5e20d92f598eb1d28fa
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Mar 23 15:31:10 2018 -0700

    GEODE-1279: Rename Bug47667DUnitTest as ClientTxCommitShouldNotHangRegressionTest
---
 .../geode/internal/cache/Bug47667DUnitTest.java    |  96 -----------
 .../ClientTxCommitShouldNotHangRegressionTest.java | 175 +++++++++++++++++++++
 2 files changed, 175 insertions(+), 96 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug47667DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug47667DUnitTest.java
deleted file mode 100644
index eecddd5..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug47667DUnitTest.java
+++ /dev/null
@@ -1,96 +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.CacheTransactionManager;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
-import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.LocatorTestBase;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.NetworkUtils;
-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;
-
-@Category(DistributedTest.class)
-public class Bug47667DUnitTest extends LocatorTestBase {
-
-  private static final long serialVersionUID = 2859534245283086765L;
-
-  public Bug47667DUnitTest() {
-    super();
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Override
-  protected final void postTearDownLocatorTestBase() throws Exception {
-    disconnectAllFromDS();
-  }
-
-  @Test
-  public void testbug47667() {
-    Host host = Host.getHost(0);
-    VM locator = host.getVM(0);
-    VM server1 = host.getVM(1);
-    VM server2 = host.getVM(2);
-    VM client = host.getVM(3);
-
-    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    final String locatorHost = NetworkUtils.getServerHostName(host);
-    locator.invoke("Start Locator", () -> startLocator(locatorHost, locatorPort, ""));
-
-    String locString = getLocatorString(host, locatorPort);
-    server1.invoke("Start BridgeServer",
-        () -> startBridgeServer(new String[] {"R1"}, locString, new String[] {"R1"}));
-    server2.invoke("Start BridgeServer",
-        () -> startBridgeServer(new String[] {"R2"}, locString, new String[] {"R2"}));
-
-    client.invoke("create region and insert data in transaction", () -> {
-      ClientCacheFactory ccf = new ClientCacheFactory();
-      ccf.addPoolLocator(locatorHost, locatorPort);
-      ClientCache cache = ccf.create();
-      PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R1")
-          .create("R1");
-      PoolManager.createFactory().addLocator(locatorHost, locatorPort).setServerGroup("R2")
-          .create("R2");
-      Region region1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
-          .setPoolName("R1").create("R1");
-      Region region2 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
-          .setPoolName("R2").create("R2");
-      CacheTransactionManager transactionManager = cache.getCacheTransactionManager();
-      transactionManager.begin();
-      region1.put(1, "value1");
-      transactionManager.commit();
-      transactionManager.begin();
-      region2.put(2, "value2");
-      transactionManager.commit();
-      return null;
-    });
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ClientTxCommitShouldNotHangRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ClientTxCommitShouldNotHangRegressionTest.java
new file mode 100644
index 0000000..42a8f15
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ClientTxCommitShouldNotHangRegressionTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.CacheTransactionManager;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.internal.LocatorTestBase;
+import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.test.dunit.NetworkUtils;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * Client should NOT hang in tx commit when server does not define all regions.
+ *
+ * <pre>
+ * 1. Server side
+ *    ServerA: creating only RegionA with replicated region and setting distributed-ack
+ *    ServerB: creating only RegionB with replicated region and setting distributed-ack
+ * 2. Client side
+ *    ClientTransactionA: put something and commit to RegionA with using transaction
+ *    ClientTransactionB: put something and commit to RegionB with using transaction
+ *
+ * Start server processes
+ *   (1) start ServerA
+ *   (2) start ServerB
+ *
+ * Execute clients
+ *   (1) execute ClientTransactionA -> you can finish it successfully.
+ *   (2) execute ClientTransactionB -> no responses from ServerB while committing the transaction.
+ *   Then if stopping ServerA process, then the response is back from ServerB.
+ * </pre>
+ *
+ * <p>
+ * TRAC #47667: Delay in Multi-transaction Committing for Replicated Regions with distributed-ack
+ * Scope
+ *
+ * <p>
+ * Better description of bug: Client hangs in tx commit when server does not define all regions.
+ * Underlying exception that caused the hang was:
+ *
+ * <pre>
+ * [severe 2013/05/15 17:53:07.037 PDT gemfire_2_1 <P2P message reader for mclaren(16125)<v1>:49192/33706 SHARED=true ORDERED=false UID=2> tid=0x31] Error deserializing message
+ *     java.lang.IllegalArgumentException: Illegal initial capacity: -1
+ *     at java.util.HashMap.<init>(HashMap.java:172)
+ *     at java.util.HashMap.<init>(HashMap.java:199)
+ *     at java.util.HashSet.<init>(HashSet.java:125)
+ *     at com.gemstone.gemfire.internal.cache.TXRegionLockRequestImpl.readEntryKeySet(TXRegionLockRequestImpl.java:108)
+ *     at com.gemstone.gemfire.internal.cache.TXRegionLockRequestImpl.fromData(TXRegionLockRequestImpl.java:89)
+ *     at com.gemstone.gemfire.internal.cache.TXRegionLockRequestImpl.createFromData(TXRegionLockRequestImpl.java:135)
+ *     at com.gemstone.gemfire.internal.cache.locks.TXLockBatch.fromData(TXLockBatch.java:111)
+ *     at com.gemstone.gemfire.internal.DSFIDFactory.readTXLockBatch(DSFIDFactory.java:2474)
+ *     at com.gemstone.gemfire.internal.DSFIDFactory.create(DSFIDFactory.java:726)
+ *     at com.gemstone.gemfire.internal.InternalDataSerializer.basicReadObject(InternalDataSerializer.java:2632)
+ *     at com.gemstone.gemfire.DataSerializer.readObject(DataSerializer.java:3217)
+ *     at com.gemstone.gemfire.distributed.internal.locks.DLockRequestProcessor$DLockResponseMessage.fromData(DLockRequestProcessor.java:1228)
+ *     at com.gemstone.gemfire.internal.DSFIDFactory.readDLockResponseMessage(DSFIDFactory.java:1325)
+ *     at com.gemstone.gemfire.internal.DSFIDFactory.create(DSFIDFactory.java:235)
+ *     at com.gemstone.gemfire.internal.InternalDataSerializer.readDSFID(InternalDataSerializer.java:2524)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.processNIOBuffer(Connection.java:3484)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.runNioReader(Connection.java:1794)
+ *     at com.gemstone.gemfire.internal.tcp.Connection.run(Connection.java:1675)
+ *     at java.lang.Thread.run(Thread.java:662)
+ * </pre>
+ */
+@Category(DistributedTest.class)
+@SuppressWarnings("serial")
+public class ClientTxCommitShouldNotHangRegressionTest extends LocatorTestBase {
+
+  private static ClientCache clientCache;
+
+  private String hostName;
+  private int locatorPort;
+  private String region1Name;
+  private String region2Name;
+
+  private VM client;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUpTest() throws Exception {
+    VM locator = getHost(0).getVM(0);
+    VM server1 = getHost(0).getVM(1);
+    VM server2 = getHost(0).getVM(2);
+    client = getHost(0).getVM(3);
+
+    String uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    region1Name = uniqueName + "_R1";
+    region2Name = uniqueName + "_R2";
+
+    hostName = NetworkUtils.getServerHostName(getHost(0));
+    locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+
+    locator.invoke("Start locator", () -> startLocator(hostName, locatorPort, ""));
+
+    String locators = getLocatorString(getHost(0), locatorPort);
+
+    server1.invoke("Start server",
+        () -> startBridgeServer(new String[] {region1Name}, locators, new String[] {region1Name}));
+    server2.invoke("Start server",
+        () -> startBridgeServer(new String[] {region2Name}, locators, new String[] {region2Name}));
+
+    client.invoke("Create client", () -> {
+      ClientCacheFactory ccf = new ClientCacheFactory();
+      ccf.addPoolLocator(hostName, locatorPort);
+
+      clientCache = ccf.create();
+
+      PoolManager.createFactory().addLocator(hostName, locatorPort).setServerGroup(region1Name)
+          .create(region1Name);
+      PoolManager.createFactory().addLocator(hostName, locatorPort).setServerGroup(region2Name)
+          .create(region2Name);
+
+      clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+          .setPoolName(region1Name).create(region1Name);
+      clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+          .setPoolName(region2Name).create(region2Name);
+    });
+  }
+
+  @After
+  public void tearDownTest() throws Exception {
+    disconnectAllFromDS();
+
+    invokeInEveryVM(() -> {
+      clientCache = null;
+    });
+  }
+
+  @Test
+  public void clientTxCommitShouldNotHangWhenServerDoesNotDefineAllRegions() {
+    client.invoke("insert data in transaction", () -> {
+      Region<Integer, String> region1 = clientCache.getRegion(region1Name);
+      Region<Integer, String> region2 = clientCache.getRegion(region2Name);
+
+      CacheTransactionManager transactionManager = clientCache.getCacheTransactionManager();
+
+      transactionManager.begin();
+      region1.put(1, "value1");
+      transactionManager.commit();
+
+      transactionManager.begin();
+      region2.put(2, "value2");
+      transactionManager.commit();
+    });
+  }
+}

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