HADOOP-18289. Remove WhiteBox in hadoop-kms module. (#4433)
Co-authored-by: slfan1989 <louj1988@@>
This commit is contained in:
parent
9e3fc40ecb
commit
7bfff63774
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.crypto.key.kms.server;
|
package org.apache.hadoop.crypto.key.kms.server;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.apache.hadoop.thirdparty.com.google.common.cache.LoadingCache;
|
import org.apache.hadoop.thirdparty.com.google.common.cache.LoadingCache;
|
||||||
import org.apache.curator.test.TestingServer;
|
import org.apache.curator.test.TestingServer;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -48,7 +49,6 @@
|
|||||||
import org.apache.hadoop.security.token.TokenIdentifier;
|
import org.apache.hadoop.security.token.TokenIdentifier;
|
||||||
import org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier;
|
import org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.test.Whitebox;
|
|
||||||
import org.apache.hadoop.util.Time;
|
import org.apache.hadoop.util.Time;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -929,6 +929,7 @@ public Void call() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testKMSProviderCaching() throws Exception {
|
public void testKMSProviderCaching() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
File confDir = getTestDir();
|
File confDir = getTestDir();
|
||||||
@ -946,11 +947,12 @@ public Void call() throws Exception {
|
|||||||
KMSClientProvider kmscp = createKMSClientProvider(uri, conf);
|
KMSClientProvider kmscp = createKMSClientProvider(uri, conf);
|
||||||
|
|
||||||
// get the reference to the internal cache, to test invalidation.
|
// get the reference to the internal cache, to test invalidation.
|
||||||
ValueQueue vq =
|
ValueQueue vq = (ValueQueue) FieldUtils.getField(KMSClientProvider.class,
|
||||||
(ValueQueue) Whitebox.getInternalState(kmscp, "encKeyVersionQueue");
|
"encKeyVersionQueue", true).get(kmscp);
|
||||||
LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>> kq =
|
LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>> kq =
|
||||||
((LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>>)
|
(LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>>)
|
||||||
Whitebox.getInternalState(vq, "keyQueues"));
|
FieldUtils.getField(ValueQueue.class, "keyQueues", true).get(vq);
|
||||||
|
|
||||||
EncryptedKeyVersion mockEKV = Mockito.mock(EncryptedKeyVersion.class);
|
EncryptedKeyVersion mockEKV = Mockito.mock(EncryptedKeyVersion.class);
|
||||||
when(mockEKV.getEncryptionKeyName()).thenReturn(keyName);
|
when(mockEKV.getEncryptionKeyName()).thenReturn(keyName);
|
||||||
when(mockEKV.getEncryptionKeyVersionName()).thenReturn(mockVersionName);
|
when(mockEKV.getEncryptionKeyVersionName()).thenReturn(mockVersionName);
|
||||||
|
@ -24,13 +24,14 @@
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.crypto.key.kms.server.KMS.KMSOp;
|
import org.apache.hadoop.crypto.key.kms.server.KMS.KMSOp;
|
||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.test.Whitebox;
|
|
||||||
import org.apache.hadoop.util.ThreadUtil;
|
import org.apache.hadoop.util.ThreadUtil;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
@ -63,7 +64,7 @@ public void setOutputStream(OutputStream out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final Timeout testTimeout = new Timeout(180000);
|
public final Timeout testTimeout = new Timeout(180000L, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
@ -207,8 +208,9 @@ public void testAuditLogFormat() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testInitAuditLoggers() throws Exception {
|
public void testInitAuditLoggers() throws Exception {
|
||||||
// Default should be the simple logger
|
// Default should be the simple logger
|
||||||
List<KMSAuditLogger> loggers = (List<KMSAuditLogger>) Whitebox
|
List<KMSAuditLogger> loggers = (List<KMSAuditLogger>) FieldUtils.
|
||||||
.getInternalState(kmsAudit, "auditLoggers");
|
getField(KMSAudit.class, "auditLoggers", true).get(kmsAudit);
|
||||||
|
|
||||||
Assert.assertEquals(1, loggers.size());
|
Assert.assertEquals(1, loggers.size());
|
||||||
Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());
|
Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());
|
||||||
|
|
||||||
@ -218,8 +220,8 @@ public void testInitAuditLoggers() throws Exception {
|
|||||||
SimpleKMSAuditLogger.class.getName() + ", "
|
SimpleKMSAuditLogger.class.getName() + ", "
|
||||||
+ SimpleKMSAuditLogger.class.getName());
|
+ SimpleKMSAuditLogger.class.getName());
|
||||||
final KMSAudit audit = new KMSAudit(conf);
|
final KMSAudit audit = new KMSAudit(conf);
|
||||||
loggers =
|
loggers = (List<KMSAuditLogger>) FieldUtils.
|
||||||
(List<KMSAuditLogger>) Whitebox.getInternalState(audit, "auditLoggers");
|
getField(KMSAudit.class, "auditLoggers", true).get(kmsAudit);
|
||||||
Assert.assertEquals(1, loggers.size());
|
Assert.assertEquals(1, loggers.size());
|
||||||
Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());
|
Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user