You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2019/08/19 19:07:12 UTC

[geode] branch feature/GEODE-7103 created (now d935f76)

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

bschuchardt pushed a change to branch feature/GEODE-7103
in repository https://gitbox.apache.org/repos/asf/geode.git.


      at d935f76  GEODE-7103:CI Failure: org.apache.geode.internal.cache.PartitionedRegionCreationJUnitTest

This branch includes the following new commits:

     new d935f76  GEODE-7103:CI Failure: org.apache.geode.internal.cache.PartitionedRegionCreationJUnitTest

The 1 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.



[geode] 01/01: GEODE-7103:CI Failure: org.apache.geode.internal.cache.PartitionedRegionCreationJUnitTest

Posted by bs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch feature/GEODE-7103
in repository https://gitbox.apache.org/repos/asf/geode.git

commit d935f7667548f65d271c1114865e081d669669f1
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Mon Aug 19 12:02:32 2019 -0700

    GEODE-7103:CI Failure: org.apache.geode.internal.cache.PartitionedRegionCreationJUnitTest
    
    replaced while-loops with await() or with a timeout
    
    replaced static variables with instance variables
    
    added tearDown to close the static cache held in
    PartitionedRegionTestHelper and shut down region-creation threads
    
    removed requirement to run tests in alphabetical order
---
 .../cache/PartitionedRegionCreationJUnitTest.java  | 195 +++++++--------------
 1 file changed, 59 insertions(+), 136 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PartitionedRegionCreationJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PartitionedRegionCreationJUnitTest.java
index 1b4f969..3a26b40 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PartitionedRegionCreationJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/PartitionedRegionCreationJUnitTest.java
@@ -22,12 +22,10 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
+import org.junit.After;
 import org.junit.Before;
-import org.junit.FixMethodOrder;
 import org.junit.Test;
-import org.junit.runners.MethodSorters;
 
-import org.apache.geode.LogWriter;
 import org.apache.geode.cache.AttributesFactory;
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.DataPolicy;
@@ -36,66 +34,59 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.cache.RegionExistsException;
 import org.apache.geode.cache.Scope;
+import org.apache.geode.test.awaitility.GeodeAwaitility;
 
-/**
- * This is a test for creation of Partition region(PR).
- * <p>
- * Following tests are included in PartitionedRegionCreationJUnitTest :
- * </p>
- * <p>
- * 1) testpartionedRegionCreate - Tests the PR creation.
- * </p>
- * <p>
- * 2) testpartionedRegionInitialization - Tests the PR initialization
- * </p>
- * <p>
- * 3) testpartionedRegionRegistration - Tests the PR registration
- * </p>
- * <p>
- * 4) testpartionedRegionBucketToNodeCreate - Tests the PR's BUCKET_2_NODE region creation
- * </p>
- *
- *
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class PartitionedRegionCreationJUnitTest {
-  static volatile int PRNumber = 0;
+  private volatile int PRNumber = 0;
 
-  static Region root = null;
+  private volatile boolean incrementFlag = false;
 
-  static volatile boolean increamentFlag = false;
+  private final int TOTAL_THREADS = 10;
 
-  static final int TOTAL_THREADS = 10;
+  private volatile int TOTAL_PR_CREATED = 0;
 
-  static volatile int TOTAL_PR_CREATED = 0;
+  private volatile int TOTAL_RETURNS = 0;
 
-  static volatile int TOTAL_RETURNS = 0;
+  private volatile int TOTAL_PR_CREATION_FAIL = 0;
 
-  static volatile int TOTAL_PR_CREATION_FAIL = 0;
+  private final Object PR_CREATE = new Object();
 
-  static final Object PR_CREATE = new Object();
+  private final Object PR_CREATE_FAIL = new Object();
 
-  static final Object PR_CREATE_FAIL = new Object();
+  private final Object PR_INCREMENT = new Object();
 
-  static final Object PR_INCREMENT = new Object();
+  private final Object PR_TOTAL_RETURNS = new Object();
 
-  static final Object PR_TOTAL_RETURNS = new Object();
+  private boolean PRCreateDone = false;
 
-  public boolean PRCreateDone = false;
-
-  List PRRegionList = new ArrayList();
-
-  LogWriter logger = null;
+  private List PRRegionList = new ArrayList();
 
   private Object CREATE_COMPLETE_LOCK = new Object();
 
   private volatile boolean createComplete = false;
 
+  private List<Thread> regionCreationThreads = new ArrayList<>(20);
+
   @Before
   public void setUp() throws Exception {
     TOTAL_RETURNS = 0;
-    if (logger == null)
-      logger = PartitionedRegionTestHelper.getLogger();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    PartitionedRegionTestHelper.closeCache();
+    long numThreads = regionCreationThreads.size();
+    int numAlive = 0;
+    for (Thread thread : regionCreationThreads) {
+      thread.interrupt();
+      thread.join(GeodeAwaitility.getTimeout().getValueInMS() / numThreads);
+      if (thread.isAlive()) {
+        numAlive++;
+      }
+    }
+    if (numAlive > 0) {
+      throw new IllegalStateException("Test is leaving behind " + numAlive + " live threads");
+    }
   }
 
   /*
@@ -105,13 +96,9 @@ public class PartitionedRegionCreationJUnitTest {
    * </p> 5) Test for localMaxMemory < 0 </p>
    */
   @Test
-  public void test000PartitionedRegionCreate() {
+  public void testPartitionedRegionCreate() {
     createMultiplePartitionedRegions();
     verifyCreateResults();
-    if (logger.fineEnabled()) {
-      logger.fine(
-          " PartitionedRegionCreationTest-testpartionedRegionCreate() Successfully Complete ..  ");
-    }
 
     final String regionname = "testPartionedRegionCreate";
     int localMaxMemory = 0;
@@ -154,11 +141,8 @@ public class PartitionedRegionCreationJUnitTest {
     try {
       pr = (PartitionedRegion) PartitionedRegionTestHelper.createPartitionedRegion(regionname,
           String.valueOf(localMaxMemory), redundancy);
+      fail("expected redundancy of 10 to cause an exception");
     } catch (IllegalStateException illex) {
-      if (logger.fineEnabled()) {
-        logger.fine(
-            "testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy > 3 ");
-      }
     }
 
     // test for redundancy < 0
@@ -171,26 +155,12 @@ public class PartitionedRegionCreationJUnitTest {
       fail(
           "testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy < 0 ");
     } catch (IllegalStateException illex) {
-      if (logger.fineEnabled()) {
-        logger.fine(
-            "testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy < 0 ");
-      }
     }
 
-    // test for localMaxMemory < 0
-    /*
-     * if (pr!= null && !pr.isDestroyed()) pr.destroyRegion(); ; localMaxMemory = -5; try { pr =
-     * (PartitionedRegion)PartitionedRegionTestHelper .createPartitionedRegion(regionname,
-     * String.valueOf(localMaxMemory), 2, Scope.DISTRIBUTED_ACK);
-     * fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for localMaxMemory < 0 "
-     * ); } catch (IllegalStateException illex) { if (logger.fineEnabled()) { logger
-     * .fine("testpartionedRegionCreate() Got a correct exception-IllegalStateException for  localMaxMemory < 0  "
-     * ); } }
-     */
   }
 
   @Test
-  public void test001PersistentPartitionedRegionCreate() {
+  public void testPersistentPartitionedRegionCreate() {
     final String regionname = "testPersistentPartionedRegionCreate";
     PartitionedRegion pr = null;
 
@@ -245,7 +215,7 @@ public class PartitionedRegionCreationJUnitTest {
       af.setDataPolicy(DataPolicy.PARTITION);
       af.setDiskStoreName("existentDiskStore");
       RegionAttributes ra = af.create();
-      pr = (PartitionedRegion) cache.createRegion(regionname, ra);
+      cache.createRegion(regionname, ra);
       fail("testpartionedRegionCreate() Expected IllegalStateException not thrown");
     } catch (IllegalStateException expected) {
       assertEquals("Only regions with persistence or overflow to disk can specify DiskStore",
@@ -262,7 +232,7 @@ public class PartitionedRegionCreationJUnitTest {
         af.setScope(scopes[i]);
         RegionAttributes ra = af.create();
         Cache cache = PartitionedRegionTestHelper.createCache();
-        pr = (PartitionedRegion) cache.createRegion(regionname, ra);
+        cache.createRegion(regionname, ra);
         fail("testpartionedRegionCreate() Expected IllegalStateException not thrown for Scope "
             + scopes[i]);
       } catch (IllegalStateException expected) {
@@ -276,10 +246,6 @@ public class PartitionedRegionCreationJUnitTest {
       fail(
           "testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy > 3 ");
     } catch (IllegalStateException illex) {
-      if (logger.fineEnabled()) {
-        logger.fine(
-            "testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy > 3 ");
-      }
     }
 
     // test for redundancy < 0
@@ -289,10 +255,6 @@ public class PartitionedRegionCreationJUnitTest {
       fail(
           "testpartionedRegionCreate() Expected IllegalStateException not thrown for redundancy < 0 ");
     } catch (IllegalStateException illex) {
-      if (logger.fineEnabled()) {
-        logger.fine(
-            "testpartionedRegionCreate() Got a correct exception-IllegalStateException for  redundancy < 0 ");
-      }
     }
   }
 
@@ -310,7 +272,7 @@ public class PartitionedRegionCreationJUnitTest {
    *
    */
   @Test
-  public void test002PartionedRegionInitialization() throws RegionExistsException {
+  public void testPartionedRegionInitialization() throws RegionExistsException {
     String PRName = "testpartionedRegionInitialization";
     PartitionedRegionTestHelper.createPartionedRegion(PRName);
 
@@ -326,29 +288,6 @@ public class PartitionedRegionCreationJUnitTest {
           + PartitionedRegionHelper.PR_ROOT_REGION_NAME + " scope is not distributed_ack");
     assertEquals(DataPolicy.REPLICATE, regionAttribs.getDataPolicy());
 
-    // Region allPartitionedRegions = root
-    // .getSubregion(PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME);
-    // if (allPartitionedRegions == null)
-    // fail("testpartionedRegionInitialization() - the "
-    // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
-    // + " do not exists");
-    //
-    // regionAttribs = allPartitionedRegions.getAttributes();
-    // scope = regionAttribs.getScope();
-    // if (!scope.isDistributedAck())
-    // fail("testpartionedRegionInitialization() - the "
-    // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
-    // + " scope is not distributed_ack");
-    // MirrorType mirrortype = regionAttribs.getMirrorType();
-    // if (mirrortype != MirrorType.KEYS_VALUES)
-    // fail("testpartionedRegionInitialization() - the "
-    // + PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME
-    // + " mirror type is not KEYS_VALUES ");
-
-    if (logger.fineEnabled()) {
-      logger.fine("testpartionedRegionInitialization() Successfully Complete ..  ");
-    }
-    // System.out.println("testpartionedRegionInitialization");
   }
 
   /**
@@ -358,13 +297,10 @@ public class PartitionedRegionCreationJUnitTest {
    *
    */
   @Test
-  public void test003partionedRegionRegistration() {
+  public void testPartionedRegionRegistration() {
     createMultiplePartitionedRegions();
     Region root = (PartitionedRegionTestHelper
         .getExistingRegion(PartitionedRegionHelper.PR_ROOT_REGION_NAME));
-    //
-    // Region allPartitionedRegions = root
-    // .getSubregion(PartitionedRegionHelper.PARTITIONED_REGION_CONFIG_NAME);
 
     Iterator itr = PRRegionList.iterator();
     while (itr.hasNext()) {
@@ -376,10 +312,6 @@ public class PartitionedRegionCreationJUnitTest {
             + " configs do not exists in  region - " + root.getName());
     }
 
-    if (logger.fineEnabled()) {
-      logger.fine(" testpartionedRegionRegistration() Successfully Complete ..  ");
-    }
-    // System.out.println("testpartionedRegionRegistration");
   }
 
   /**
@@ -390,21 +322,19 @@ public class PartitionedRegionCreationJUnitTest {
     if (PRCreateDone)
       return;
     int numthread = 0;
-    while (numthread < TOTAL_THREADS) {
+    long giveupTime = System.currentTimeMillis() + GeodeAwaitility.getTimeout().getValueInMS();
+    while (numthread < TOTAL_THREADS && giveupTime > System.currentTimeMillis()) {
       PartionedRegionCreateThread pregionThread = new PartionedRegionCreateThread();
       pregionThread.start();
+      regionCreationThreads.add(pregionThread);
       numthread++;
     }
-    while (!createComplete) {
+    assertTrue(numthread >= TOTAL_THREADS);
+    GeodeAwaitility.await().until(() -> {
       synchronized (CREATE_COMPLETE_LOCK) {
-        if (!createComplete) {
-          try {
-            CREATE_COMPLETE_LOCK.wait();
-          } catch (Exception ex) { // no action }
-          }
-        }
+        return createComplete;
       }
-    }
+    });
     PRCreateDone = true;
   }
 
@@ -413,14 +343,17 @@ public class PartitionedRegionCreationJUnitTest {
    *
    */
   private void verifyCreateResults() {
-    if (TOTAL_RETURNS != TOTAL_THREADS)
-      fail("Failed -- Total thread returned is not same as number of threads created");
+    GeodeAwaitility.await().untilAsserted(() -> {
+      if (TOTAL_RETURNS != TOTAL_THREADS)
+        fail("Failed -- Total thread returned is not same as number of threads created");
 
-    if (TOTAL_PR_CREATED != (TOTAL_THREADS / 2))
-      fail("Failed -- Total Partioned Region created is not correct");
+      if (TOTAL_PR_CREATED != (TOTAL_THREADS / 2))
+        fail("Failed -- Total Partioned Region created is not correct.  Total created = "
+            + TOTAL_PR_CREATED + " but expected " + (TOTAL_THREADS / 2));
 
-    if (TOTAL_PR_CREATION_FAIL != (TOTAL_THREADS / 2))
-      fail("Failed -- Total Partioned Region creation failures is not correct");
+      if (TOTAL_PR_CREATION_FAIL != (TOTAL_THREADS / 2))
+        fail("Failed -- Total Partioned Region creation failures is not correct");
+    });
   }
 
   /**
@@ -434,17 +367,8 @@ public class PartitionedRegionCreationJUnitTest {
       try {
         Region region = PartitionedRegionTestHelper.createPartionedRegion(prName);
         PRRegionList.add(region);
-        if (logger.fineEnabled()) {
-          logger.fine(
-              "PartitionedRegionCreationJUnitTest - partitioned region -" + prName + "Created");
-        }
         updatePRCreate();
       } catch (RegionExistsException rex) {
-        if (logger.fineEnabled()) {
-          logger
-              .fine("PartitionedRegionCreationTest -  Thread - " + Thread.currentThread().getName()
-                  + " Failed to create a PartitionedRegion. Region already exists");
-        }
         updatePRCreateFail();
       }
 
@@ -460,12 +384,12 @@ public class PartitionedRegionCreationJUnitTest {
   protected int getPRNumber() {
     int retNum = 0;
     synchronized (PR_INCREMENT) {
-      if (increamentFlag) {
+      if (incrementFlag) {
         retNum = PRNumber;
         PRNumber++;
-        increamentFlag = false;
+        incrementFlag = false;
       } else {
-        increamentFlag = true;
+        incrementFlag = true;
       }
     }
     return retNum;
@@ -490,7 +414,6 @@ public class PartitionedRegionCreationJUnitTest {
   protected void updateTotalReturns() {
     synchronized (PR_TOTAL_RETURNS) {
       TOTAL_RETURNS++;
-      System.out.println("TOTAL_RETURNS is " + TOTAL_RETURNS);
     }
     if (TOTAL_RETURNS == TOTAL_THREADS) {
       synchronized (CREATE_COMPLETE_LOCK) {