Skip to content

Commit 31477a2

Browse files
YARN-10460. Upgrading to JUnit 4.13 causes tests in TestNodeStatusUpdater to fail. Contributed by Peter Bacsko
1 parent 4c65110 commit 31477a2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ClientCache.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.apache.hadoop.io.ObjectWritable;
3030
import org.apache.hadoop.io.Writable;
3131

32+
import com.google.common.annotations.VisibleForTesting;
33+
3234
/* Cache a client using its socket factory as the hash key */
3335
@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
3436
@InterfaceStability.Evolving
@@ -114,4 +116,10 @@ public void stopClient(Client client) {
114116
client.stop();
115117
}
116118
}
119+
120+
@VisibleForTesting
121+
public void clearCache() {
122+
clients.values().forEach(c -> c.stop());
123+
clients.clear();
124+
}
117125
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngine2.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ public RPC.Server getServer(Class<?> protocol, Object protocolImpl,
352352
portRangeConfig, alignmentContext);
353353
}
354354

355+
@VisibleForTesting
356+
public static void clearClientCache() {
357+
CLIENTS.clearCache();
358+
}
359+
355360
public static class Server extends RPC.Server {
356361

357362
static final ThreadLocal<ProtobufRpcEngineCallback2> CURRENT_CALLBACK =

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestNodeStatusUpdater.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.hadoop.io.Text;
5555
import org.apache.hadoop.io.retry.RetryPolicy;
5656
import org.apache.hadoop.io.retry.RetryProxy;
57+
import org.apache.hadoop.ipc.ProtobufRpcEngine2;
5758
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
5859
import org.apache.hadoop.net.NetUtils;
5960
import org.apache.hadoop.net.ServerSocketUtil;
@@ -137,6 +138,12 @@ public class TestNodeStatusUpdater extends NodeManagerTestBase {
137138
private NodeManager nm;
138139
private AtomicBoolean assertionFailedInThread = new AtomicBoolean(false);
139140

141+
@Before
142+
public void before() {
143+
// to avoid threading issues with JUnit 4.13+
144+
ProtobufRpcEngine2.clearClientCache();
145+
}
146+
140147
@After
141148
public void tearDown() {
142149
this.registeredNodes.clear();

0 commit comments

Comments
 (0)