From 04b31d7ecfc86564f14055d17765e15d51c46a26 Mon Sep 17 00:00:00 2001 From: slfan1989 <55643692+slfan1989@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:45:20 +0800 Subject: [PATCH] MAPREDUCE-7390. Remove WhiteBox in mapreduce module. (#4462) Signed-off-by: Akira Ajisaka --- .../mapreduce/task/reduce/MergeManagerImpl.java | 5 +++++ .../mapreduce/task/reduce/MergeThread.java | 11 +++++++++++ .../mapreduce/task/reduce/TestMergeManager.java | 17 ++++------------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java index 18f2a33555..ec6ad158dd 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeManagerImpl.java @@ -879,4 +879,9 @@ public int compareTo(Path obj) { return super.compareTo(obj); } } + + @VisibleForTesting + OnDiskMerger getOnDiskMerger() { + return onDiskMerger; + } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeThread.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeThread.java index 4a40cb17d4..c617569da3 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeThread.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/MergeThread.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.hadoop.classification.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,4 +110,14 @@ public void run() { } public abstract void merge(List inputs) throws IOException; + + @VisibleForTesting + int getMergeFactor() { + return mergeFactor; + } + + @VisibleForTesting + LinkedList> getPendingToBeMerged() { + return pendingToBeMerged; + } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMergeManager.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMergeManager.java index 4e718b85a8..063daada6d 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMergeManager.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/test/java/org/apache/hadoop/mapreduce/task/reduce/TestMergeManager.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.mock; import java.io.IOException; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -44,7 +43,6 @@ import org.apache.hadoop.mapreduce.MRJobConfig; import org.apache.hadoop.mapreduce.TaskAttemptID; import org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl.CompressAwarePath; -import org.apache.hadoop.test.Whitebox; import org.junit.Assert; import org.junit.Test; @@ -217,8 +215,7 @@ public void testIoSortDefaults() { @SuppressWarnings({ "unchecked", "deprecation" }) @Test(timeout=10000) - public void testOnDiskMerger() throws IOException, URISyntaxException, - InterruptedException { + public void testOnDiskMerger() throws IOException { JobConf jobConf = new JobConf(); final int SORT_FACTOR = 5; jobConf.setInt(MRJobConfig.IO_SORT_FACTOR, SORT_FACTOR); @@ -229,12 +226,8 @@ public void testOnDiskMerger() throws IOException, URISyntaxException, new MergeManagerImpl(null, jobConf, fs, null , null, null, null, null, null, null, null, null, null, mapOutputFile); - MergeThread, IntWritable, IntWritable> - onDiskMerger = (MergeThread, - IntWritable, IntWritable>) Whitebox.getInternalState(manager, - "onDiskMerger"); - int mergeFactor = (Integer) Whitebox.getInternalState(onDiskMerger, - "mergeFactor"); + MergeThread onDiskMerger = manager.getOnDiskMerger(); + int mergeFactor = onDiskMerger.getMergeFactor(); // make sure the io.sort.factor is set properly assertEquals(mergeFactor, SORT_FACTOR); @@ -252,9 +245,7 @@ public void testOnDiskMerger() throws IOException, URISyntaxException, } //Check that the files pending to be merged are in sorted order. - LinkedList> pendingToBeMerged = - (LinkedList>) Whitebox.getInternalState( - onDiskMerger, "pendingToBeMerged"); + LinkedList> pendingToBeMerged = onDiskMerger.getPendingToBeMerged(); assertTrue("No inputs were added to list pending to merge", pendingToBeMerged.size() > 0); for(int i = 0; i < pendingToBeMerged.size(); ++i) {