YARN-10460. Upgrading to JUnit 4.13 causes tests in TestNodeStatusUpdater to fail. Contributed by Peter Bacsko

(cherry picked from commit 31477a224f)
This commit is contained in:
Eric Badger 2021-04-16 20:21:01 +00:00
parent 49f6326a9f
commit f7e382c62e
3 changed files with 20 additions and 0 deletions

View File

@ -29,6 +29,8 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting;
/* Cache a client using its socket factory as the hash key */
@InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"})
@InterfaceStability.Evolving
@ -114,4 +116,10 @@ public class ClientCache {
client.stop();
}
}
@VisibleForTesting
public void clearCache() {
clients.values().forEach(c -> c.stop());
clients.clear();
}
}

View File

@ -352,6 +352,11 @@ public class ProtobufRpcEngine2 implements RpcEngine {
portRangeConfig, alignmentContext);
}
@VisibleForTesting
public static void clearClientCache() {
CLIENTS.clearCache();
}
public static class Server extends RPC.Server {
static final ThreadLocal<ProtobufRpcEngineCallback2> CURRENT_CALLBACK =

View File

@ -54,6 +54,7 @@ import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.retry.RetryPolicy;
import org.apache.hadoop.io.retry.RetryProxy;
import org.apache.hadoop.ipc.ProtobufRpcEngine2;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.net.ServerSocketUtil;
@ -137,6 +138,12 @@ public class TestNodeStatusUpdater extends NodeManagerTestBase {
private NodeManager nm;
private AtomicBoolean assertionFailedInThread = new AtomicBoolean(false);
@Before
public void before() {
// to avoid threading issues with JUnit 4.13+
ProtobufRpcEngine2.clearClientCache();
}
@After
public void tearDown() {
this.registeredNodes.clear();