HDFS-13746. Still occasional "Should be different group" failure in TestRefreshUserMappings#testGroupMappingRefresh
(Contributed by Siyao Meng via Daniel Templeton) Change-Id: I9fad1537ace38367a463d9fe67aaa28d3178fc69
This commit is contained in:
parent
5ef29087ad
commit
8512e1a91b
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue