geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [geode] branch develop updated: GEODE-5629: Changing GMSEncryptJUnitTest to use ConcurrencyRule
Date Fri, 24 Aug 2018 23:26:06 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/develop by this push:
     new e719331  GEODE-5629: Changing GMSEncryptJUnitTest to use ConcurrencyRule
e719331 is described below

commit e719331d03b3e3b1ae069b9db5b04cc928b96e3f
Author: Dan Smith <upthewaterspout@apache.org>
AuthorDate: Fri Aug 24 12:14:36 2018 -0700

    GEODE-5629: Changing GMSEncryptJUnitTest to use ConcurrencyRule
    
    This test was not capturing exceptions from the background threads.
    Using ConcurrenyRule to execute the background tests.
---
 .../gms/messenger/GMSEncryptJUnitTest.java         | 122 ++++++++-------------
 1 file changed, 48 insertions(+), 74 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java
b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java
index 53fa083..5a2a5c1 100755
--- a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/messenger/GMSEncryptJUnitTest.java
@@ -21,7 +21,7 @@ import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
-import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Callable;
 
 import org.junit.Assert;
 import org.junit.Rule;
@@ -37,7 +37,7 @@ import org.apache.geode.distributed.internal.membership.gms.ServiceConfig;
 import org.apache.geode.distributed.internal.membership.gms.Services;
 import org.apache.geode.internal.admin.remote.RemoteTransportConfig;
 import org.apache.geode.test.junit.categories.MembershipTest;
-import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+import org.apache.geode.test.junit.rules.ConcurrencyRule;
 
 @Category({MembershipTest.class})
 public class GMSEncryptJUnitTest {
@@ -52,8 +52,7 @@ public class GMSEncryptJUnitTest {
   NetView netView;
 
   @Rule
-  public ExecutorServiceRule executorServiceRule =
-      ExecutorServiceRule.builder().threadCount(THREAD_COUNT).build();
+  public ConcurrencyRule concurrencyRule = new ConcurrencyRule();
 
   private void initMocks() throws Exception {
     initMocks(DEFAULT_ALGO);
@@ -143,52 +142,39 @@ public class GMSEncryptJUnitTest {
 
     sender.overrideInstallViewForTest(netView);
     receiver.overrideInstallViewForTest(netView);
-    final CountDownLatch countDownLatch = new CountDownLatch(THREAD_COUNT);
 
-    for (int j = 0; j < THREAD_COUNT; j++)
-      executorServiceRule.execute(new Runnable() {
-        public void run() {
-          // sender encrypts a message, so use receiver's public key
-          try {
-            int count = 0;
-            for (int i = 0; i < runs; i++) {
-              // System.out.println("another run " + i + " threadid " +
-              // Thread.currentThread().getId());
-              String ch = "Hello world";
-              byte[] challenge = ch.getBytes();
-              byte[] encryptedChallenge = sender.encryptData(challenge, mockMembers[2]);
+    for (int j = 0; j < THREAD_COUNT; j++) {
+      Callable<Object> callable = () -> {
+        String ch = "Hello world";
+        byte[] challenge = ch.getBytes();
+        byte[] encryptedChallenge = sender.encryptData(challenge, mockMembers[2]);
 
-              // receiver decrypts the message using the sender's public key
-              byte[] decryptBytes = receiver.decryptData(encryptedChallenge, mockMembers[1]);
+        // receiver decrypts the message using the sender's public key
+        byte[] decryptBytes = receiver.decryptData(encryptedChallenge, mockMembers[1]);
 
-              // now send a response
-              String response = "Hello yourself!";
-              byte[] responseBytes = response.getBytes();
-              byte[] encryptedResponse = receiver.encryptData(responseBytes, mockMembers[1]);
+        // now send a response
+        String response = "Hello yourself!";
+        byte[] responseBytes = response.getBytes();
+        byte[] encryptedResponse = receiver.encryptData(responseBytes, mockMembers[1]);
 
-              // receiver decodes the response
-              byte[] decryptedResponse = sender.decryptData(encryptedResponse, mockMembers[2]);
+        // receiver decodes the response
+        byte[] decryptedResponse = sender.decryptData(encryptedResponse, mockMembers[2]);
 
-              Assert.assertFalse(Arrays.equals(challenge, encryptedChallenge));
+        Assert.assertFalse(Arrays.equals(challenge, encryptedChallenge));
 
-              Assert.assertTrue(Arrays.equals(challenge, decryptBytes));
+        Assert.assertTrue(Arrays.equals(challenge, decryptBytes));
 
-              Assert.assertFalse(Arrays.equals(responseBytes, encryptedResponse));
+        Assert.assertFalse(Arrays.equals(responseBytes, encryptedResponse));
 
-              Assert.assertTrue(Arrays.equals(responseBytes, decryptedResponse));
-              count++;
-            }
-            Assert.assertEquals(runs, count);
-            countDownLatch.countDown();
-          } catch (Exception e) {
-            e.printStackTrace();
+        Assert.assertTrue(Arrays.equals(responseBytes, decryptedResponse));
 
-          }
+        return null;
+      };
 
-        }
-      });
+      concurrencyRule.add(callable).repeatForIterations(runs);
+    }
 
-    countDownLatch.await();
+    concurrencyRule.executeInParallel();
   }
 
   @Test
@@ -322,51 +308,39 @@ public class GMSEncryptJUnitTest {
     receiver.overrideInstallViewForTest(netView);
 
     final int runs = 100000;
-    final CountDownLatch countDownLatch = new CountDownLatch(THREAD_COUNT);
-
-    for (int j = 0; j < THREAD_COUNT; j++)
-      executorServiceRule.execute(new Runnable() {
-        public void run() {
-          // sender encrypts a message, so use receiver's public key
-          try {
-            int count = 0;
-            for (int i = 0; i < runs; i++) {
-              String ch = "Hello world";
-              byte[] challenge = ch.getBytes();
-              byte[] encryptedChallenge = sender.encryptData(challenge);
 
-              // receiver decrypts the message using the sender's public key
-              byte[] decryptBytes = receiver.decryptData(encryptedChallenge);
+    for (int j = 0; j < THREAD_COUNT; j++) {
+      Callable<Void> callable = () -> {
+        // sender encrypts a message, so use receiver's public key
 
-              // now send a response
-              String response = "Hello yourself!";
-              byte[] responseBytes = response.getBytes();
-              byte[] encryptedResponse = receiver.encryptData(responseBytes);
+        String ch = "Hello world";
+        byte[] challenge = ch.getBytes();
+        byte[] encryptedChallenge = sender.encryptData(challenge);
 
-              // receiver decodes the response
-              byte[] decryptedResponse = sender.decryptData(encryptedResponse);
+        // receiver decrypts the message using the sender's public key
+        byte[] decryptBytes = receiver.decryptData(encryptedChallenge);
 
-              Assert.assertFalse(Arrays.equals(challenge, encryptedChallenge));
+        // now send a response
+        String response = "Hello yourself!";
+        byte[] responseBytes = response.getBytes();
+        byte[] encryptedResponse = receiver.encryptData(responseBytes);
 
-              Assert.assertTrue(Arrays.equals(challenge, decryptBytes));
+        // receiver decodes the response
+        byte[] decryptedResponse = sender.decryptData(encryptedResponse);
 
-              Assert.assertFalse(Arrays.equals(responseBytes, encryptedResponse));
+        Assert.assertFalse(Arrays.equals(challenge, encryptedChallenge));
 
-              Assert.assertTrue(Arrays.equals(responseBytes, decryptedResponse));
+        Assert.assertTrue(Arrays.equals(challenge, decryptBytes));
 
-              count++;
-            }
+        Assert.assertFalse(Arrays.equals(responseBytes, encryptedResponse));
 
-            Assert.assertEquals(runs, count);
+        Assert.assertTrue(Arrays.equals(responseBytes, decryptedResponse));
 
-            countDownLatch.countDown();
-          } catch (Exception e) {
-            e.printStackTrace();
-          }
+        return null;
+      };
+      concurrencyRule.add(callable).repeatForIterations(runs);
 
-        }
-      });
-
-    countDownLatch.await();
+    }
+    concurrencyRule.executeInParallel();
   }
 }


Mime
View raw message