Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] test: fix tempdir leak in KerberizedHdfs tests #721

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.net.BindException;
import java.net.ServerSocket;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -75,8 +73,7 @@ public class KerberizedHdfs implements Serializable {

private MiniKdc kdc;
private File workDir;
private Path tempDir;
private Path kerberizedDfsBaseDir;
private File kerberizedDfsBaseDir;

private MiniDFSCluster kerberizedDfsCluster;

Expand All @@ -91,9 +88,12 @@ public class KerberizedHdfs implements Serializable {
// krb5.conf file path
private String krb5ConfFile;

KerberizedHdfs(File workDir, File kerberizedDfsBaseDir) {
this.workDir = workDir;
this.kerberizedDfsBaseDir = kerberizedDfsBaseDir;
}

protected void setup() throws Exception {
tempDir = Files.createTempDirectory("tempDir").toFile().toPath();
kerberizedDfsBaseDir = Files.createTempDirectory("kerberizedDfsBaseDir").toFile().toPath();

startKDC();
try {
Expand Down Expand Up @@ -159,7 +159,7 @@ private Configuration createSecureDFSConfig() throws Exception {
CommonConfigurationKeysPublic.HADOOP_SECURITY_IMPERSONATION_PROVIDER_CLASS,
TestDummyImpersonationProvider.class.getName());

String keystoresDir = kerberizedDfsBaseDir.toFile().getAbsolutePath();
String keystoresDir = kerberizedDfsBaseDir.getAbsolutePath();
String sslConfDir = KeyStoreTestUtil.getClasspathDir(testRunnerCls);
KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false);

Expand Down Expand Up @@ -222,7 +222,6 @@ private void startKDC() throws Exception {
kdcConf.setProperty(MiniKdc.ORG_DOMAIN, "COM");
kdcConf.setProperty(MiniKdc.KDC_BIND_ADDRESS, hostName);
kdcConf.setProperty(MiniKdc.KDC_PORT, "0");
workDir = tempDir.toFile();
kdc = new MiniKdc(kdcConf, workDir);
kdc.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package org.apache.uniffle.common;

import java.io.File;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.io.TempDir;

import org.apache.uniffle.common.security.HadoopSecurityContext;
import org.apache.uniffle.common.security.NoOpSecurityContext;
Expand All @@ -30,8 +33,13 @@ public class KerberizedHdfsBase {
protected static KerberizedHdfs kerberizedHdfs;
protected static Class<?> testRunner = KerberizedHdfsBase.class;

@TempDir
private static File workDir;
@TempDir
private static File kerberizedDfsBaseDir;

public static void init() throws Exception {
kerberizedHdfs = new KerberizedHdfs();
kerberizedHdfs = new KerberizedHdfs(workDir, kerberizedDfsBaseDir);
kerberizedHdfs.setTestRunner(testRunner);
kerberizedHdfs.setup();
}
Expand Down