Repository: hadoop
Updated Branches:
  refs/heads/branch-3.1 97c193424 -> fbedf8937


HDFS-13746. Still occasional "Should be different group" failure in 
TestRefreshUserMappings#testGroupMappingRefresh
(Contributed by Siyao Meng via Daniel Templeton)

Change-Id: I9fad1537ace38367a463d9fe67aaa28d3178fc69
(cherry picked from commit 8512e1a91be3e340d919c7cdc9c09dfb762a6a4e)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/fbedf893
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/fbedf893
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/fbedf893

Branch: refs/heads/branch-3.1
Commit: fbedf89377e540fb10239a880fc2e01ef7021b93
Parents: 97c1934
Author: Daniel Templeton <templ...@apache.org>
Authored: Thu Aug 16 13:43:49 2018 -0700
Committer: Daniel Templeton <templ...@apache.org>
Committed: Thu Aug 16 15:01:34 2018 -0700

----------------------------------------------------------------------
 .../security/TestRefreshUserMappings.java       | 51 +++++++++++---------
 1 file changed, 27 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/fbedf893/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestRefreshUserMappings.java
----------------------------------------------------------------------
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestRefreshUserMappings.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestRefreshUserMappings.java
index 0e7dfc3..2d7410a 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestRefreshUserMappings.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/security/TestRefreshUserMappings.java
@@ -34,7 +34,6 @@ import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
@@ -46,6 +45,8 @@ import 
org.apache.hadoop.security.authorize.AuthorizationException;
 import org.apache.hadoop.security.authorize.DefaultImpersonationProvider;
 import org.apache.hadoop.security.authorize.ProxyUsers;
 import org.apache.hadoop.test.GenericTestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.slf4j.event.Level;
 import org.junit.After;
 import org.junit.Before;
@@ -53,6 +54,8 @@ import org.junit.Test;
 
 
 public class TestRefreshUserMappings {
+  private static final Logger LOG = LoggerFactory.getLogger(
+      TestRefreshUserMappings.class);
   private MiniDFSCluster cluster;
   Configuration config;
   private static final long groupRefreshTimeoutSec = 1;
@@ -119,42 +122,42 @@ public class TestRefreshUserMappings {
     Groups groups = Groups.getUserToGroupsMappingService(config);
     String user = UserGroupInformation.getCurrentUser().getUserName();
 
-    System.out.println("First attempt:");
+    LOG.debug("First attempt:");
     List<String> g1 = groups.getGroups(user);
-    String [] str_groups = new String [g1.size()];
-    g1.toArray(str_groups);
-    System.out.println(Arrays.toString(str_groups));
-    
-    System.out.println("Second attempt, should be the same:");
+    LOG.debug(g1.toString());
+
+    LOG.debug("Second attempt, should be the same:");
     List<String> g2 = groups.getGroups(user);
-    g2.toArray(str_groups);
-    System.out.println(Arrays.toString(str_groups));
+    LOG.debug(g2.toString());
     for(int i=0; i<g2.size(); i++) {
       assertEquals("Should be same group ", g1.get(i), g2.get(i));
     }
 
     // Test refresh command
     admin.run(args);
-    System.out.println("Third attempt(after refresh command), should be 
different:");
+    LOG.debug("Third attempt(after refresh command), should be different:");
     List<String> g3 = groups.getGroups(user);
-    g3.toArray(str_groups);
-    System.out.println(Arrays.toString(str_groups));
+    LOG.debug(g3.toString());
     for(int i=0; i<g3.size(); i++) {
-      assertFalse("Should be different group: " + g1.get(i) + " and " + 
g3.get(i), 
-          g1.get(i).equals(g3.get(i)));
+      assertFalse("Should be different group: "
+              + g1.get(i) + " and " + g3.get(i), g1.get(i).equals(g3.get(i)));
     }
-    
+
     // Test timeout
-    Thread.sleep(groupRefreshTimeoutSec * 1500);
-    System.out.println("Fourth attempt(after timeout), should be different:");
-    List<String> g4 = groups.getGroups(user);
-    g4.toArray(str_groups);
-    System.out.println(Arrays.toString(str_groups));
-    for(int i=0; i<g4.size(); i++) {
-      assertFalse("Should be different group ", g3.get(i).equals(g4.get(i)));
-    }
+    LOG.debug("Fourth attempt(after timeout), should be different:");
+    GenericTestUtils.waitFor(() -> {
+      List<String> g4;
+      try {
+        g4 = groups.getGroups(user);
+      } catch (IOException e) {
+        return false;
+      }
+      LOG.debug(g4.toString());
+      // if g4 is the same as g3, wait and retry
+      return !g3.equals(g4);
+    }, 50, Math.toIntExact(groupRefreshTimeoutSec * 1000 * 30));
   }
-  
+
   @Test
   public void testRefreshSuperUserGroupsConfiguration() throws Exception {
     final String SUPER_USER = "super_user";


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to