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

(cherry picked from commit bf0d058b69)
This commit is contained in:
Eric Badger 2021-04-19 20:18:20 +00:00
parent bef21ceb14
commit 9c3acb3018
3 changed files with 19 additions and 1 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 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

@ -335,7 +335,10 @@ public class ProtobufRpcEngine implements RpcEngine {
RpcWritable.Buffer.class);
}
@VisibleForTesting
public static void clearClientCache() {
CLIENTS.clearCache();
}
@Override
public RPC.Server getServer(Class<?> protocol, Object protocolImpl,

View File

@ -52,6 +52,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.ProtobufRpcEngine;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.net.ServerSocketUtil;
@ -122,6 +123,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+
ProtobufRpcEngine.clearClientCache();
}
@After
public void tearDown() {
this.registeredNodes.clear();