Skip to content

Commit

Permalink
[apache#708] test: do not assume hostname of hdfs mini-cluster (apach…
Browse files Browse the repository at this point in the history
…e#709)

### What changes were proposed in this pull request?

Do not assume hostname in hdfs URL.
Also, let exception be thrown in `ShuffleHdfsStorageUtilsTest` to print verbose message.

### Why are the changes needed?

Fix apache#708 

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Tested manually
  • Loading branch information
kaijchen authored and xianjingfeng committed Apr 5, 2023
1 parent 25f5dc5 commit 2f16baa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private List<Integer> findAvailablePorts(int num) throws IOException {
}

public String getSchemeAndAuthorityPrefix() {
return String.format("hdfs://localhost:%s/", kerberizedDfsCluster.getNameNodePort());
return kerberizedDfsCluster.getURI().toString() + "/";
}

public Configuration getConf() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void writeTest() throws Exception {
StorageManager storageManager =
StorageManagerFactory.getInstance().createStorageManager(shuffleServerConf);
storageManager.registerRemoteStorage(appId, remoteStorage);
String storageHost = "localhost";
String storageHost = cluster.getURI().getHost();
assertEquals(0.0, ShuffleServerMetrics.counterRemoteStorageTotalWrite.get(storageHost).get(), 0.5);
assertEquals(0.0, ShuffleServerMetrics.counterRemoteStorageRetryWrite.get(storageHost).get(), 0.5);
assertEquals(0.0, ShuffleServerMetrics.counterRemoteStorageFailedWrite.get(storageHost).get(), 0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void setUpHdfs(@TempDir File tempDir) throws Exception {
conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR,
baseDir.getAbsolutePath());
cluster = (new MiniDFSCluster.Builder(conf)).build();
HDFS_URI = "hdfs://localhost:" + cluster.getNameNodePort() + "/";
HDFS_URI = cluster.getURI().toString() + "/";
fs = (new Path(HDFS_URI)).getFileSystem(conf);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.uniffle.storage.handler.impl.HdfsFileWriter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class ShuffleHdfsStorageUtilsTest extends HdfsTestBase {

Expand All @@ -46,27 +45,20 @@ public static void createAndRunCases(
FileSystem fileSystem,
String clusterPathPrefix,
Configuration hadoopConf) throws Exception {
FileOutputStream fileOut = null;
DataOutputStream dataOut = null;
try {
File file = new File(tempDir, "test");
fileOut = new FileOutputStream(file);
dataOut = new DataOutputStream(fileOut);
byte[] buf = new byte[2096];
new Random().nextBytes(buf);
dataOut.write(buf);
dataOut.close();
fileOut.close();
String path = clusterPathPrefix + "test";
HdfsFileWriter writer = new HdfsFileWriter(fileSystem, new Path(path), hadoopConf);
long size = ShuffleStorageUtils.uploadFile(file, writer, 1024);
assertEquals(2096, size);
size = ShuffleStorageUtils.uploadFile(file, writer, 100);
assertEquals(2096, size);
writer.close();
} catch (Exception e) {
e.printStackTrace();
fail();
}
File file = new File(tempDir, "test");
FileOutputStream fileOut = new FileOutputStream(file);
DataOutputStream dataOut = new DataOutputStream(fileOut);
byte[] buf = new byte[2096];
new Random().nextBytes(buf);
dataOut.write(buf);
dataOut.close();
fileOut.close();
String path = clusterPathPrefix + "test";
HdfsFileWriter writer = new HdfsFileWriter(fileSystem, new Path(path), hadoopConf);
long size = ShuffleStorageUtils.uploadFile(file, writer, 1024);
assertEquals(2096, size);
size = ShuffleStorageUtils.uploadFile(file, writer, 100);
assertEquals(2096, size);
writer.close();
}
}

0 comments on commit 2f16baa

Please sign in to comment.