Skip to content

Commit

Permalink
YARN-6946. Upgrade JUnit from 4 to 5 in hadoop-yarn-common
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh Gupta committed Nov 8, 2022
1 parent 1cda2dc commit 2778068
Show file tree
Hide file tree
Showing 106 changed files with 3,599 additions and 3,247 deletions.
25 changes: 20 additions & 5 deletions hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-annotations</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down Expand Up @@ -138,6 +133,26 @@
<artifactId>bcprov-jdk15on</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import java.util.Iterator;

import org.apache.hadoop.thirdparty.com.google.common.collect.Iterators;

import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.YarnApplicationState;

import org.apache.hadoop.thirdparty.com.google.common.collect.Iterators;

/**
* Utilities to generate fake test apps
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.Server;
import org.apache.hadoop.net.NetUtils;
Expand All @@ -35,12 +37,12 @@
import org.apache.hadoop.yarn.api.protocolrecords.CommitResponse;
import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateRequest;
import org.apache.hadoop.yarn.api.protocolrecords.ContainerUpdateResponse;
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse;
import org.apache.hadoop.yarn.api.protocolrecords.GetLocalizationStatusesRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetLocalizationStatusesResponse;
import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceRequest;
import org.apache.hadoop.yarn.api.protocolrecords.IncreaseContainersResourceResponse;
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesRequest;
import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusesResponse;
import org.apache.hadoop.yarn.api.protocolrecords.ReInitializeContainerRequest;
import org.apache.hadoop.yarn.api.protocolrecords.ReInitializeContainerResponse;
import org.apache.hadoop.yarn.api.protocolrecords.ResourceLocalizationRequest;
Expand Down Expand Up @@ -70,8 +72,9 @@
import org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC;
import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
import org.junit.Assert;
import org.junit.Test;

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

/*
* Test that the container launcher rpc times out properly. This is used
Expand All @@ -86,7 +89,7 @@ public class TestContainerLaunchRPC {
.getRecordFactory(null);

@Test
public void testHadoopProtoRPCTimeout() throws Exception {
void testHadoopProtoRPCTimeout() throws Exception {
testRPCTimeout(HadoopYarnProtoRPC.class.getName());
}

Expand Down Expand Up @@ -136,16 +139,15 @@ private void testRPCTimeout(String rpcClass) throws Exception {
proxy.startContainers(allRequests);
} catch (Exception e) {
LOG.info(StringUtils.stringifyException(e));
Assert.assertEquals("Error, exception is not: "
+ SocketTimeoutException.class.getName(),
SocketTimeoutException.class.getName(), e.getClass().getName());
assertEquals(SocketTimeoutException.class.getName(), e.getClass().getName(),
"Error, exception is not: " + SocketTimeoutException.class.getName());
return;
}
} finally {
server.stop();
}

Assert.fail("timeout exception should have occurred!");
fail("timeout exception should have occurred!");
}

public static Token newContainerToken(NodeId nodeId, byte[] password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

package org.apache.hadoop.yarn;

import org.junit.jupiter.api.Test;

import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.junit.Test;

public class TestContainerLogAppender {

@Test
public void testAppendInClose() throws Exception {
void testAppendInClose() throws Exception {
final ContainerLogAppender claAppender = new ContainerLogAppender();
claAppender.setName("testCLA");
claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

package org.apache.hadoop.yarn;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.Server;
import org.apache.hadoop.net.NetUtils;
Expand Down Expand Up @@ -59,14 +67,9 @@
import org.apache.hadoop.yarn.ipc.HadoopYarnProtoRPC;
import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/*
* Test that the container resource increase rpc times out properly.
Expand All @@ -78,7 +81,7 @@ public class TestContainerResourceIncreaseRPC {
TestContainerResourceIncreaseRPC.class);

@Test
public void testHadoopProtoRPCTimeout() throws Exception {
void testHadoopProtoRPCTimeout() throws Exception {
testRPCTimeout(HadoopYarnProtoRPC.class.getName());
}

Expand Down Expand Up @@ -122,15 +125,14 @@ private void testRPCTimeout(String rpcClass) throws Exception {
proxy.updateContainer(request);
} catch (Exception e) {
LOG.info(StringUtils.stringifyException(e));
Assert.assertEquals("Error, exception is not: "
+ SocketTimeoutException.class.getName(),
SocketTimeoutException.class.getName(), e.getClass().getName());
assertEquals(SocketTimeoutException.class.getName(), e.getClass().getName(),
"Error, exception is not: " + SocketTimeoutException.class.getName());
return;
}
} finally {
server.stop();
}
Assert.fail("timeout exception should have occurred!");
fail("timeout exception should have occurred!");
}

public static Token newContainerToken(NodeId nodeId, byte[] password,
Expand All @@ -157,11 +159,9 @@ public StartContainersResponse startContainers(
}

@Override
public StopContainersResponse
stopContainers(StopContainersRequest requests) throws YarnException,
IOException {
Exception e = new Exception("Dummy function", new Exception(
"Dummy function cause"));
public StopContainersResponse stopContainers(StopContainersRequest requests)
throws YarnException, IOException {
Exception e = new Exception("Dummy function", new Exception("Dummy function cause"));
throw new YarnException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.Server;
Expand All @@ -37,16 +37,16 @@
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.factories.impl.pb.RpcClientFactoryPBImpl;
import org.apache.hadoop.yarn.factories.impl.pb.RpcServerFactoryPBImpl;
import org.junit.Test;

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

public class TestRPCFactories {





@Test
public void test() {
void test() {
testPbServerFactory();

testPbClientFactory();
}

Expand All @@ -64,7 +64,7 @@ private void testPbServerFactory() {
server.start();
} catch (YarnRuntimeException e) {
e.printStackTrace();
Assert.fail("Failed to create server");
fail("Failed to create server");
} finally {
if (server != null) {
server.stop();
Expand Down Expand Up @@ -92,12 +92,12 @@ private void testPbClientFactory() {
amrmClient = (ApplicationMasterProtocol) RpcClientFactoryPBImpl.get().getClient(ApplicationMasterProtocol.class, 1, NetUtils.getConnectAddress(server), conf);
} catch (YarnRuntimeException e) {
e.printStackTrace();
Assert.fail("Failed to create client");
fail("Failed to create client");
}

} catch (YarnRuntimeException e) {
e.printStackTrace();
Assert.fail("Failed to create server");
fail("Failed to create server");
} finally {
if (server != null) {
server.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,41 @@

package org.apache.hadoop.yarn;

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factories.impl.pb.RecordFactoryPBImpl;
import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateRequestPBImpl;
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.AllocateResponsePBImpl;
import org.junit.Test;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factories.impl.pb.RecordFactoryPBImpl;

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

public class TestRecordFactory {

@Test
public void testPbRecordFactory() {
void testPbRecordFactory() {
RecordFactory pbRecordFactory = RecordFactoryPBImpl.get();

try {
AllocateResponse response =
pbRecordFactory.newRecordInstance(AllocateResponse.class);
Assert.assertEquals(AllocateResponsePBImpl.class, response.getClass());
assertEquals(AllocateResponsePBImpl.class, response.getClass());
} catch (YarnRuntimeException e) {
e.printStackTrace();
Assert.fail("Failed to crete record");
fail("Failed to crete record");
}

try {
AllocateRequest response =
pbRecordFactory.newRecordInstance(AllocateRequest.class);
Assert.assertEquals(AllocateRequestPBImpl.class, response.getClass());
assertEquals(AllocateRequestPBImpl.class, response.getClass());
} catch (YarnRuntimeException e) {
e.printStackTrace();
Assert.fail("Failed to crete record");
fail("Failed to crete record");
}
}

Expand Down
Loading

0 comments on commit 2778068

Please sign in to comment.