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 8512e1a91b
)
This commit is contained in:
parent
97c1934247
commit
fbedf89377
|
@ -34,7 +34,6 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
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.DefaultImpersonationProvider;
|
||||||
import org.apache.hadoop.security.authorize.ProxyUsers;
|
import org.apache.hadoop.security.authorize.ProxyUsers;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.event.Level;
|
import org.slf4j.event.Level;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -53,6 +54,8 @@ import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestRefreshUserMappings {
|
public class TestRefreshUserMappings {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(
|
||||||
|
TestRefreshUserMappings.class);
|
||||||
private MiniDFSCluster cluster;
|
private MiniDFSCluster cluster;
|
||||||
Configuration config;
|
Configuration config;
|
||||||
private static final long groupRefreshTimeoutSec = 1;
|
private static final long groupRefreshTimeoutSec = 1;
|
||||||
|
@ -119,42 +122,42 @@ public class TestRefreshUserMappings {
|
||||||
Groups groups = Groups.getUserToGroupsMappingService(config);
|
Groups groups = Groups.getUserToGroupsMappingService(config);
|
||||||
String user = UserGroupInformation.getCurrentUser().getUserName();
|
String user = UserGroupInformation.getCurrentUser().getUserName();
|
||||||
|
|
||||||
System.out.println("First attempt:");
|
LOG.debug("First attempt:");
|
||||||
List<String> g1 = groups.getGroups(user);
|
List<String> g1 = groups.getGroups(user);
|
||||||
String [] str_groups = new String [g1.size()];
|
LOG.debug(g1.toString());
|
||||||
g1.toArray(str_groups);
|
|
||||||
System.out.println(Arrays.toString(str_groups));
|
LOG.debug("Second attempt, should be the same:");
|
||||||
|
|
||||||
System.out.println("Second attempt, should be the same:");
|
|
||||||
List<String> g2 = groups.getGroups(user);
|
List<String> g2 = groups.getGroups(user);
|
||||||
g2.toArray(str_groups);
|
LOG.debug(g2.toString());
|
||||||
System.out.println(Arrays.toString(str_groups));
|
|
||||||
for(int i=0; i<g2.size(); i++) {
|
for(int i=0; i<g2.size(); i++) {
|
||||||
assertEquals("Should be same group ", g1.get(i), g2.get(i));
|
assertEquals("Should be same group ", g1.get(i), g2.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test refresh command
|
// Test refresh command
|
||||||
admin.run(args);
|
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);
|
List<String> g3 = groups.getGroups(user);
|
||||||
g3.toArray(str_groups);
|
LOG.debug(g3.toString());
|
||||||
System.out.println(Arrays.toString(str_groups));
|
|
||||||
for(int i=0; i<g3.size(); i++) {
|
for(int i=0; i<g3.size(); i++) {
|
||||||
assertFalse("Should be different group: " + g1.get(i) + " and " + g3.get(i),
|
assertFalse("Should be different group: "
|
||||||
g1.get(i).equals(g3.get(i)));
|
+ g1.get(i) + " and " + g3.get(i), g1.get(i).equals(g3.get(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test timeout
|
// Test timeout
|
||||||
Thread.sleep(groupRefreshTimeoutSec * 1500);
|
LOG.debug("Fourth attempt(after timeout), should be different:");
|
||||||
System.out.println("Fourth attempt(after timeout), should be different:");
|
GenericTestUtils.waitFor(() -> {
|
||||||
List<String> g4 = groups.getGroups(user);
|
List<String> g4;
|
||||||
g4.toArray(str_groups);
|
try {
|
||||||
System.out.println(Arrays.toString(str_groups));
|
g4 = groups.getGroups(user);
|
||||||
for(int i=0; i<g4.size(); i++) {
|
} catch (IOException e) {
|
||||||
assertFalse("Should be different group ", g3.get(i).equals(g4.get(i)));
|
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
|
@Test
|
||||||
public void testRefreshSuperUserGroupsConfiguration() throws Exception {
|
public void testRefreshSuperUserGroupsConfiguration() throws Exception {
|
||||||
final String SUPER_USER = "super_user";
|
final String SUPER_USER = "super_user";
|
||||||
|
|
Loading…
Reference in New Issue