HADOOP-18289. Remove WhiteBox in hadoop-kms module. (#4433)

Co-authored-by: slfan1989 <louj1988@@>
This commit is contained in:
slfan1989 2022-06-16 18:13:16 -07:00 committed by GitHub
parent 9e3fc40ecb
commit 7bfff63774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -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<String, LinkedBlockingQueue<EncryptedKeyVersion>> kq =
((LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>>)
Whitebox.getInternalState(vq, "keyQueues"));
(LoadingCache<String, LinkedBlockingQueue<EncryptedKeyVersion>>)
FieldUtils.getField(ValueQueue.class, "keyQueues", true).get(vq);
EncryptedKeyVersion mockEKV = Mockito.mock(EncryptedKeyVersion.class);
when(mockEKV.getEncryptionKeyName()).thenReturn(keyName);
when(mockEKV.getEncryptionKeyVersionName()).thenReturn(mockVersionName);

View File

@ -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<KMSAuditLogger> loggers = (List<KMSAuditLogger>) Whitebox
.getInternalState(kmsAudit, "auditLoggers");
List<KMSAuditLogger> loggers = (List<KMSAuditLogger>) 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<KMSAuditLogger>) Whitebox.getInternalState(audit, "auditLoggers");
loggers = (List<KMSAuditLogger>) FieldUtils.
getField(KMSAudit.class, "auditLoggers", true).get(kmsAudit);
Assert.assertEquals(1, loggers.size());
Assert.assertEquals(SimpleKMSAuditLogger.class, loggers.get(0).getClass());