From 7bfff63774d01837bcb2d783e9a9630b9bffe1af Mon Sep 17 00:00:00 2001 From: slfan1989 <55643692+slfan1989@users.noreply.github.com> Date: Thu, 16 Jun 2022 18:13:16 -0700 Subject: [PATCH] HADOOP-18289. Remove WhiteBox in hadoop-kms module. (#4433) Co-authored-by: slfan1989 --- .../hadoop/crypto/key/kms/server/TestKMS.java | 12 +++++++----- .../hadoop/crypto/key/kms/server/TestKMSAudit.java | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java index a0a58ff356..f4c7fbe0b3 100644 --- a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java +++ b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMS.java @@ -17,6 +17,7 @@ */ 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.curator.test.TestingServer; import org.apache.hadoop.conf.Configuration; @@ -48,7 +49,6 @@ import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.security.token.delegation.web.DelegationTokenIdentifier; import org.apache.hadoop.test.GenericTestUtils; -import org.apache.hadoop.test.Whitebox; import org.apache.hadoop.util.Time; import org.apache.http.client.utils.URIBuilder; import org.junit.After; @@ -929,6 +929,7 @@ public Void call() throws Exception { } @Test + @SuppressWarnings("unchecked") public void testKMSProviderCaching() throws Exception { Configuration conf = new Configuration(); File confDir = getTestDir(); @@ -946,11 +947,12 @@ public Void call() throws Exception { KMSClientProvider kmscp = createKMSClientProvider(uri, conf); // get the reference to the internal cache, to test invalidation. - ValueQueue vq = - (ValueQueue) Whitebox.getInternalState(kmscp, "encKeyVersionQueue"); + ValueQueue vq = (ValueQueue) FieldUtils.getField(KMSClientProvider.class, + "encKeyVersionQueue", true).get(kmscp); LoadingCache> kq = - ((LoadingCache>) - Whitebox.getInternalState(vq, "keyQueues")); + (LoadingCache>) + FieldUtils.getField(ValueQueue.class, "keyQueues", true).get(vq); + EncryptedKeyVersion mockEKV = Mockito.mock(EncryptedKeyVersion.class); when(mockEKV.getEncryptionKeyName()).thenReturn(keyName); when(mockEKV.getEncryptionKeyVersionName()).thenReturn(mockVersionName); diff --git a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMSAudit.java b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMSAudit.java index 2f47ed794a..3d0fd7de64 100644 --- a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMSAudit.java +++ b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/TestKMSAudit.java @@ -24,13 +24,14 @@ import java.io.OutputStream; import java.io.PrintStream; 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.crypto.key.kms.server.KMS.KMSOp; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.test.GenericTestUtils; -import org.apache.hadoop.test.Whitebox; import org.apache.hadoop.util.ThreadUtil; import org.apache.log4j.LogManager; import org.apache.log4j.PropertyConfigurator; @@ -63,7 +64,7 @@ public void setOutputStream(OutputStream out) { } @Rule - public final Timeout testTimeout = new Timeout(180000); + public final Timeout testTimeout = new Timeout(180000L, TimeUnit.MILLISECONDS); @Before public void setUp() throws IOException { @@ -207,8 +208,9 @@ public void testAuditLogFormat() throws Exception { @Test public void testInitAuditLoggers() throws Exception { // Default should be the simple logger - List loggers = (List) Whitebox - .getInternalState(kmsAudit, "auditLoggers"); + List loggers = (List) FieldUtils. + getField(KMSAudit.class, "auditLoggers", true).get(kmsAudit); + Assert.assertEquals(1, loggers.size()); Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass()); @@ -218,8 +220,8 @@ public void testInitAuditLoggers() throws Exception { SimpleKMSAuditLogger.class.getName() + ", " + SimpleKMSAuditLogger.class.getName()); final KMSAudit audit = new KMSAudit(conf); - loggers = - (List) Whitebox.getInternalState(audit, "auditLoggers"); + loggers = (List) FieldUtils. + getField(KMSAudit.class, "auditLoggers", true).get(kmsAudit); Assert.assertEquals(1, loggers.size()); Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());