HADOOP-14949. TestKMS#testACLs fails intermittently.

This commit is contained in:
Xiao Chen 2017-10-16 13:53:31 -07:00
parent 1fcbe7cf5f
commit b7ff624c76
3 changed files with 13 additions and 3 deletions

View File

@ -326,4 +326,8 @@ public class KMSACLs implements Runnable, KeyACLs {
|| whitelistKeyAcls.containsKey(opType));
}
@VisibleForTesting
void forceNextReloadForTesting() {
lastReload = 0;
}
}

View File

@ -20,6 +20,8 @@ package org.apache.hadoop.crypto.key.kms.server;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.MalformedURLException;
@ -31,6 +33,8 @@ import java.net.URL;
@InterfaceAudience.Private
public class KMSConfiguration {
static final Logger LOG = LoggerFactory.getLogger(KMSConfiguration.class);
public static final String KMS_CONFIG_DIR = "kms.config.dir";
public static final String KMS_DEFAULT_XML = "kms-default.xml";
public static final String KMS_SITE_XML = "kms-site.xml";
@ -138,6 +142,8 @@ public class KMSConfiguration {
"' must be an absolute path: " + confDir);
}
File f = new File(confDir, KMS_ACLS_XML);
LOG.trace("Checking file {}, modification time is {}, last reload time is"
+ " {}", f.getPath(), f.lastModified(), time);
// at least 100ms newer than time, we do this to ensure the file
// has been properly closed/flushed
newer = f.lastModified() - time > 100;

View File

@ -54,6 +54,7 @@ import org.junit.Test;
import org.junit.rules.Timeout;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.slf4j.event.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -1637,13 +1638,12 @@ public class TestKMS {
//stop the reloader, to avoid running while we are writing the new file
KMSWebApp.getACLs().stopReloader();
GenericTestUtils.setLogLevel(KMSConfiguration.LOG, Level.TRACE);
// test ACL reloading
Thread.sleep(10); // to ensure the ACLs file modifiedTime is newer
conf.set(KMSACLs.Type.CREATE.getAclConfigKey(), "foo");
conf.set(KMSACLs.Type.GENERATE_EEK.getAclConfigKey(), "foo");
writeConf(testDir, conf);
Thread.sleep(1000);
KMSWebApp.getACLs().forceNextReloadForTesting();
KMSWebApp.getACLs().run(); // forcing a reload by hand.
// should not be able to create a key now