Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package org.apache.hadoop.yarn;

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

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
Expand All @@ -28,50 +28,54 @@
import org.apache.hadoop.yarn.factories.impl.pb.RpcClientFactoryPBImpl;
import org.apache.hadoop.yarn.factories.impl.pb.RpcServerFactoryPBImpl;
import org.apache.hadoop.yarn.factory.providers.RpcFactoryProvider;
import org.junit.Test;

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

public class TestRpcFactoryProvider {

@Test
public void testFactoryProvider() {
void testFactoryProvider() {
Configuration conf = new Configuration();
RpcClientFactory clientFactory = null;
RpcServerFactory serverFactory = null;


clientFactory = RpcFactoryProvider.getClientFactory(conf);
serverFactory = RpcFactoryProvider.getServerFactory(conf);
Assert.assertEquals(RpcClientFactoryPBImpl.class, clientFactory.getClass());
Assert.assertEquals(RpcServerFactoryPBImpl.class, serverFactory.getClass());
assertEquals(RpcClientFactoryPBImpl.class, clientFactory.getClass());
assertEquals(RpcServerFactoryPBImpl.class, serverFactory.getClass());

conf.set(YarnConfiguration.IPC_CLIENT_FACTORY_CLASS, "unknown");
conf.set(YarnConfiguration.IPC_SERVER_FACTORY_CLASS, "unknown");
conf.set(YarnConfiguration.IPC_RECORD_FACTORY_CLASS, "unknown");

try {
clientFactory = RpcFactoryProvider.getClientFactory(conf);
Assert.fail("Expected an exception - unknown serializer");
fail("Expected an exception - unknown serializer");
} catch (YarnRuntimeException e) {
}
try {
serverFactory = RpcFactoryProvider.getServerFactory(conf);
Assert.fail("Expected an exception - unknown serializer");
fail("Expected an exception - unknown serializer");
} catch (YarnRuntimeException e) {
}

conf = new Configuration();
conf.set(YarnConfiguration.IPC_CLIENT_FACTORY_CLASS, "NonExistantClass");
conf.set(YarnConfiguration.IPC_SERVER_FACTORY_CLASS, RpcServerFactoryPBImpl.class.getName());

try {
clientFactory = RpcFactoryProvider.getClientFactory(conf);
Assert.fail("Expected an exception - unknown class");
fail("Expected an exception - unknown class");
} catch (YarnRuntimeException e) {
}
try {
serverFactory = RpcFactoryProvider.getServerFactory(conf);
} catch (YarnRuntimeException e) {
Assert.fail("Error while loading factory using reflection: [" + RpcServerFactoryPBImpl.class.getName() + "]");
fail(
"Error while loading factory using reflection: [" + RpcServerFactoryPBImpl.class.getName()
+ "]");
}
}
}
Loading