YARN-11245. Upgrade JUnit from 4 to 5 in hadoop-yarn-csi (#4778)

Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com>
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
Ashutosh Gupta 2022-08-30 09:26:06 +01:00 committed by GitHub
parent 2c05015716
commit 90dba8b614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 172 additions and 145 deletions

View File

@ -91,6 +91,16 @@
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </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> <dependency>
<groupId>org.apache.hadoop</groupId> <groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId> <artifactId>hadoop-common</artifactId>

View File

@ -42,10 +42,9 @@
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.ipc.YarnRPC; import org.apache.hadoop.yarn.ipc.YarnRPC;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -53,6 +52,9 @@
import java.net.ServerSocket; import java.net.ServerSocket;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.AccessMode.MULTI_NODE_MULTI_WRITER; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.AccessMode.MULTI_NODE_MULTI_WRITER;
import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM;
@ -64,7 +66,7 @@ public class TestCsiAdaptorService {
private static File testRoot = null; private static File testRoot = null;
private static String domainSocket = null; private static String domainSocket = null;
@BeforeClass @BeforeAll
public static void setUp() throws IOException { public static void setUp() throws IOException {
testRoot = GenericTestUtils.getTestDir("csi-test"); testRoot = GenericTestUtils.getTestDir("csi-test");
File socketPath = new File(testRoot, "csi.sock"); File socketPath = new File(testRoot, "csi.sock");
@ -72,7 +74,7 @@ public static void setUp() throws IOException {
domainSocket = "unix://" + socketPath.getAbsolutePath(); domainSocket = "unix://" + socketPath.getAbsolutePath();
} }
@AfterClass @AfterAll
public static void tearDown() throws IOException { public static void tearDown() throws IOException {
if (testRoot != null) { if (testRoot != null) {
FileUtils.deleteDirectory(testRoot); FileUtils.deleteDirectory(testRoot);
@ -113,7 +115,7 @@ default NodeUnpublishVolumeResponse nodeUnpublishVolume(
} }
@Test @Test
public void testValidateVolume() throws IOException, YarnException { void testValidateVolume() throws IOException, YarnException {
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
ss.close(); ss.close();
InetSocketAddress address = new InetSocketAddress(ss.getLocalPort()); InetSocketAddress address = new InetSocketAddress(ss.getLocalPort());
@ -145,20 +147,20 @@ public ValidateVolumeCapabilitiesResponse validateVolumeCapacity(
ValidateVolumeCapabilitiesRequest request) throws YarnException, ValidateVolumeCapabilitiesRequest request) throws YarnException,
IOException { IOException {
// validate we get all info from the request // validate we get all info from the request
Assert.assertEquals("volume-id-0000123", request.getVolumeId()); assertEquals("volume-id-0000123", request.getVolumeId());
Assert.assertEquals(1, request.getVolumeCapabilities().size()); assertEquals(1, request.getVolumeCapabilities().size());
Assert.assertEquals(Csi.VolumeCapability.AccessMode assertEquals(Csi.VolumeCapability.AccessMode
.newBuilder().setModeValue(5).build().getMode().name(), .newBuilder().setModeValue(5).build().getMode().name(),
request.getVolumeCapabilities().get(0).getAccessMode().name()); request.getVolumeCapabilities().get(0).getAccessMode().name());
Assert.assertEquals(2, request.getVolumeCapabilities().get(0) assertEquals(2, request.getVolumeCapabilities().get(0)
.getMountFlags().size()); .getMountFlags().size());
Assert.assertTrue(request.getVolumeCapabilities().get(0) assertTrue(request.getVolumeCapabilities().get(0)
.getMountFlags().contains("mountFlag1")); .getMountFlags().contains("mountFlag1"));
Assert.assertTrue(request.getVolumeCapabilities().get(0) assertTrue(request.getVolumeCapabilities().get(0)
.getMountFlags().contains("mountFlag2")); .getMountFlags().contains("mountFlag2"));
Assert.assertEquals(2, request.getVolumeAttributes().size()); assertEquals(2, request.getVolumeAttributes().size());
Assert.assertEquals("v1", request.getVolumeAttributes().get("k1")); assertEquals("v1", request.getVolumeAttributes().get("k1"));
Assert.assertEquals("v2", request.getVolumeAttributes().get("k2")); assertEquals("v2", request.getVolumeAttributes().get("k2"));
// return a fake result // return a fake result
return ValidateVolumeCapabilitiesResponse return ValidateVolumeCapabilitiesResponse
.newInstance(false, "this is a test"); .newInstance(false, "this is a test");
@ -178,22 +180,22 @@ public ValidateVolumeCapabilitiesResponse validateVolumeCapacity(
ImmutableList.of( ImmutableList.of(
new ValidateVolumeCapabilitiesRequest new ValidateVolumeCapabilitiesRequest
.VolumeCapability( .VolumeCapability(
MULTI_NODE_MULTI_WRITER, FILE_SYSTEM, MULTI_NODE_MULTI_WRITER, FILE_SYSTEM,
ImmutableList.of("mountFlag1", "mountFlag2"))), ImmutableList.of("mountFlag1", "mountFlag2"))),
ImmutableMap.of("k1", "v1", "k2", "v2")); ImmutableMap.of("k1", "v1", "k2", "v2"));
ValidateVolumeCapabilitiesResponse response = client ValidateVolumeCapabilitiesResponse response = client
.validateVolumeCapacity(request); .validateVolumeCapacity(request);
Assert.assertEquals(false, response.isSupported()); assertEquals(false, response.isSupported());
Assert.assertEquals("this is a test", response.getResponseMessage()); assertEquals("this is a test", response.getResponseMessage());
} finally { } finally {
service.stop(); service.stop();
} }
} }
@Test @Test
public void testValidateVolumeWithNMProxy() throws Exception { void testValidateVolumeWithNMProxy() throws Exception {
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
ss.close(); ss.close();
InetSocketAddress address = new InetSocketAddress(ss.getLocalPort()); InetSocketAddress address = new InetSocketAddress(ss.getLocalPort());
@ -225,21 +227,21 @@ public ValidateVolumeCapabilitiesResponse validateVolumeCapacity(
ValidateVolumeCapabilitiesRequest request) ValidateVolumeCapabilitiesRequest request)
throws YarnException, IOException { throws YarnException, IOException {
// validate we get all info from the request // validate we get all info from the request
Assert.assertEquals("volume-id-0000123", request.getVolumeId()); assertEquals("volume-id-0000123", request.getVolumeId());
Assert.assertEquals(1, request.getVolumeCapabilities().size()); assertEquals(1, request.getVolumeCapabilities().size());
Assert.assertEquals( assertEquals(
Csi.VolumeCapability.AccessMode.newBuilder().setModeValue(5) Csi.VolumeCapability.AccessMode.newBuilder().setModeValue(5)
.build().getMode().name(), .build().getMode().name(),
request.getVolumeCapabilities().get(0).getAccessMode().name()); request.getVolumeCapabilities().get(0).getAccessMode().name());
Assert.assertEquals(2, assertEquals(2,
request.getVolumeCapabilities().get(0).getMountFlags().size()); request.getVolumeCapabilities().get(0).getMountFlags().size());
Assert.assertTrue(request.getVolumeCapabilities().get(0).getMountFlags() assertTrue(request.getVolumeCapabilities().get(0).getMountFlags()
.contains("mountFlag1")); .contains("mountFlag1"));
Assert.assertTrue(request.getVolumeCapabilities().get(0).getMountFlags() assertTrue(request.getVolumeCapabilities().get(0).getMountFlags()
.contains("mountFlag2")); .contains("mountFlag2"));
Assert.assertEquals(2, request.getVolumeAttributes().size()); assertEquals(2, request.getVolumeAttributes().size());
Assert.assertEquals("v1", request.getVolumeAttributes().get("k1")); assertEquals("v1", request.getVolumeAttributes().get("k1"));
Assert.assertEquals("v2", request.getVolumeAttributes().get("k2")); assertEquals("v2", request.getVolumeAttributes().get("k2"));
// return a fake result // return a fake result
return ValidateVolumeCapabilitiesResponse return ValidateVolumeCapabilitiesResponse
.newInstance(false, "this is a test"); .newInstance(false, "this is a test");
@ -261,50 +263,59 @@ public ValidateVolumeCapabilitiesResponse validateVolumeCapacity(
.newInstance("volume-id-0000123", .newInstance("volume-id-0000123",
ImmutableList.of(new ValidateVolumeCapabilitiesRequest ImmutableList.of(new ValidateVolumeCapabilitiesRequest
.VolumeCapability( .VolumeCapability(
MULTI_NODE_MULTI_WRITER, FILE_SYSTEM, MULTI_NODE_MULTI_WRITER, FILE_SYSTEM,
ImmutableList.of("mountFlag1", "mountFlag2"))), ImmutableList.of("mountFlag1", "mountFlag2"))),
ImmutableMap.of("k1", "v1", "k2", "v2")); ImmutableMap.of("k1", "v1", "k2", "v2"));
ValidateVolumeCapabilitiesResponse response = adaptorClient ValidateVolumeCapabilitiesResponse response = adaptorClient
.validateVolumeCapacity(request); .validateVolumeCapacity(request);
Assert.assertEquals(false, response.isSupported()); assertEquals(false, response.isSupported());
Assert.assertEquals("this is a test", response.getResponseMessage()); assertEquals("this is a test", response.getResponseMessage());
service.stop(); service.stop();
} }
@Test (expected = ServiceStateException.class) @Test
public void testMissingConfiguration() { void testMissingConfiguration() {
Configuration conf = new Configuration(); assertThrows(ServiceStateException.class, () -> {
CsiAdaptorProtocolService service = Configuration conf = new Configuration();
new CsiAdaptorProtocolService(new FakeCsiAdaptor() {}); CsiAdaptorProtocolService service =
service.init(conf); new CsiAdaptorProtocolService(new FakeCsiAdaptor() {
} });
service.init(conf);
@Test (expected = ServiceStateException.class) });
public void testInvalidServicePort() {
Configuration conf = new Configuration();
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "test-driver-0001.address",
"0.0.0.0:-100"); // this is an invalid address
CsiAdaptorProtocolService service =
new CsiAdaptorProtocolService(new FakeCsiAdaptor() {});
service.init(conf);
}
@Test (expected = ServiceStateException.class)
public void testInvalidHost() {
Configuration conf = new Configuration();
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "test-driver-0001.address",
"192.0.1:8999"); // this is an invalid ip address
CsiAdaptorProtocolService service =
new CsiAdaptorProtocolService(new FakeCsiAdaptor() {});
service.init(conf);
} }
@Test @Test
public void testCustomizedAdaptor() throws IOException, YarnException { void testInvalidServicePort() {
assertThrows(ServiceStateException.class, () -> {
Configuration conf = new Configuration();
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "test-driver-0001.address",
"0.0.0.0:-100"); // this is an invalid address
CsiAdaptorProtocolService service =
new CsiAdaptorProtocolService(new FakeCsiAdaptor() {
});
service.init(conf);
});
}
@Test
void testInvalidHost() {
assertThrows(ServiceStateException.class, () -> {
Configuration conf = new Configuration();
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "test-driver-0001.address",
"192.0.1:8999"); // this is an invalid ip address
CsiAdaptorProtocolService service =
new CsiAdaptorProtocolService(new FakeCsiAdaptor() {
});
service.init(conf);
});
}
@Test
void testCustomizedAdaptor() throws IOException, YarnException {
ServerSocket ss = new ServerSocket(0); ServerSocket ss = new ServerSocket(0);
ss.close(); ss.close();
InetSocketAddress address = new InetSocketAddress(ss.getLocalPort()); InetSocketAddress address = new InetSocketAddress(ss.getLocalPort());
@ -349,15 +360,15 @@ public void testCustomizedAdaptor() throws IOException, YarnException {
ValidateVolumeCapabilitiesResponse response = adaptorClient ValidateVolumeCapabilitiesResponse response = adaptorClient
.validateVolumeCapacity(request); .validateVolumeCapacity(request);
Assert.assertEquals(true, response.isSupported()); assertEquals(true, response.isSupported());
Assert.assertEquals("verified via MockCsiAdaptor", assertEquals("verified via MockCsiAdaptor",
response.getResponseMessage()); response.getResponseMessage());
services.stop(); services.stop();
} }
@Test @Test
public void testMultipleCsiAdaptors() throws IOException, YarnException { void testMultipleCsiAdaptors() throws IOException, YarnException {
ServerSocket driver1Addr = new ServerSocket(0); ServerSocket driver1Addr = new ServerSocket(0);
ServerSocket driver2Addr = new ServerSocket(0); ServerSocket driver2Addr = new ServerSocket(0);
@ -374,22 +385,22 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException {
// customized-driver-1 // customized-driver-1
conf.setSocketAddr(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX conf.setSocketAddr(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "customized-driver-1.address", address1); + "customized-driver-1.address", address1);
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "customized-driver-1.class", + "customized-driver-1.class",
"org.apache.hadoop.yarn.csi.adaptor.MockCsiAdaptor"); "org.apache.hadoop.yarn.csi.adaptor.MockCsiAdaptor");
conf.set(YarnConfiguration.NM_CSI_DRIVER_PREFIX conf.set(YarnConfiguration.NM_CSI_DRIVER_PREFIX
+ "customized-driver-1.endpoint", + "customized-driver-1.endpoint",
"unix:///tmp/customized-driver-1.sock"); "unix:///tmp/customized-driver-1.sock");
// customized-driver-2 // customized-driver-2
conf.setSocketAddr(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX conf.setSocketAddr(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "customized-driver-2.address", address2); + "customized-driver-2.address", address2);
conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX conf.set(YarnConfiguration.NM_CSI_ADAPTOR_PREFIX
+ "customized-driver-2.class", + "customized-driver-2.class",
"org.apache.hadoop.yarn.csi.adaptor.MockCsiAdaptor"); "org.apache.hadoop.yarn.csi.adaptor.MockCsiAdaptor");
conf.set(YarnConfiguration.NM_CSI_DRIVER_PREFIX conf.set(YarnConfiguration.NM_CSI_DRIVER_PREFIX
+ "customized-driver-2.endpoint", + "customized-driver-2.endpoint",
"unix:///tmp/customized-driver-2.sock"); "unix:///tmp/customized-driver-2.sock");
driver1Addr.close(); driver1Addr.close();
@ -427,8 +438,8 @@ public void testMultipleCsiAdaptors() throws IOException, YarnException {
ValidateVolumeCapabilitiesResponse response = client1 ValidateVolumeCapabilitiesResponse response = client1
.validateVolumeCapacity(request); .validateVolumeCapacity(request);
Assert.assertEquals(true, response.isSupported()); assertEquals(true, response.isSupported());
Assert.assertEquals("verified via MockCsiAdaptor", assertEquals("verified via MockCsiAdaptor",
response.getResponseMessage()); response.getResponseMessage());

View File

@ -21,8 +21,10 @@
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetPluginInfoRequestPBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetPluginInfoRequestPBImpl;
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetPluginInfoResponsePBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.GetPluginInfoResponsePBImpl;
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/** /**
* Verify the integrity of GetPluginInfoRequest and GetPluginInfoResponse. * Verify the integrity of GetPluginInfoRequest and GetPluginInfoResponse.
@ -30,37 +32,37 @@
public class TestGetPluginInfoRequestResponse { public class TestGetPluginInfoRequestResponse {
@Test @Test
public void testGetPluginInfoRequestPBRecord() { void testGetPluginInfoRequestPBRecord() {
CsiAdaptorProtos.GetPluginInfoRequest requestProto = CsiAdaptorProtos.GetPluginInfoRequest requestProto =
CsiAdaptorProtos.GetPluginInfoRequest.newBuilder().build(); CsiAdaptorProtos.GetPluginInfoRequest.newBuilder().build();
GetPluginInfoRequestPBImpl pbImpl = GetPluginInfoRequestPBImpl pbImpl =
new GetPluginInfoRequestPBImpl(requestProto); new GetPluginInfoRequestPBImpl(requestProto);
Assert.assertNotNull(pbImpl); assertNotNull(pbImpl);
Assert.assertEquals(requestProto, pbImpl.getProto()); assertEquals(requestProto, pbImpl.getProto());
} }
@Test @Test
public void testGetPluginInfoResponsePBRecord() { void testGetPluginInfoResponsePBRecord() {
CsiAdaptorProtos.GetPluginInfoResponse responseProto = CsiAdaptorProtos.GetPluginInfoResponse responseProto =
CsiAdaptorProtos.GetPluginInfoResponse.newBuilder() CsiAdaptorProtos.GetPluginInfoResponse.newBuilder()
.setName("test-driver") .setName("test-driver")
.setVendorVersion("1.0.1") .setVendorVersion("1.0.1")
.build(); .build();
GetPluginInfoResponsePBImpl pbImpl = GetPluginInfoResponsePBImpl pbImpl =
new GetPluginInfoResponsePBImpl(responseProto); new GetPluginInfoResponsePBImpl(responseProto);
Assert.assertEquals("test-driver", pbImpl.getDriverName()); assertEquals("test-driver", pbImpl.getDriverName());
Assert.assertEquals("1.0.1", pbImpl.getVersion()); assertEquals("1.0.1", pbImpl.getVersion());
Assert.assertEquals(responseProto, pbImpl.getProto()); assertEquals(responseProto, pbImpl.getProto());
GetPluginInfoResponse pbImpl2 = GetPluginInfoResponsePBImpl GetPluginInfoResponse pbImpl2 = GetPluginInfoResponsePBImpl
.newInstance("test-driver", "1.0.1"); .newInstance("test-driver", "1.0.1");
Assert.assertEquals("test-driver", pbImpl2.getDriverName()); assertEquals("test-driver", pbImpl2.getDriverName());
Assert.assertEquals("1.0.1", pbImpl2.getVersion()); assertEquals("1.0.1", pbImpl2.getVersion());
CsiAdaptorProtos.GetPluginInfoResponse proto = CsiAdaptorProtos.GetPluginInfoResponse proto =
((GetPluginInfoResponsePBImpl) pbImpl2).getProto(); ((GetPluginInfoResponsePBImpl) pbImpl2).getProto();
Assert.assertEquals("test-driver", proto.getName()); assertEquals("test-driver", proto.getName());
Assert.assertEquals("1.0.1", proto.getVendorVersion()); assertEquals("1.0.1", proto.getVendorVersion());
} }
} }

View File

@ -21,8 +21,10 @@
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos;
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.AccessMode; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.AccessMode;
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.VolumeType; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.VolumeType;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
/** /**
* UT for NodePublishVolumeRequest. * UT for NodePublishVolumeRequest.
@ -30,7 +32,7 @@
public class TestNodePublishVolumeRequest { public class TestNodePublishVolumeRequest {
@Test @Test
public void testPBRecord() { void testPBRecord() {
CsiAdaptorProtos.VolumeCapability capability = CsiAdaptorProtos.VolumeCapability capability =
CsiAdaptorProtos.VolumeCapability.newBuilder() CsiAdaptorProtos.VolumeCapability.newBuilder()
.setAccessMode(AccessMode.MULTI_NODE_READER_ONLY) .setAccessMode(AccessMode.MULTI_NODE_READER_ONLY)
@ -47,9 +49,9 @@ public void testPBRecord() {
NodePublishVolumeRequestPBImpl pbImpl = NodePublishVolumeRequestPBImpl pbImpl =
new NodePublishVolumeRequestPBImpl(proto); new NodePublishVolumeRequestPBImpl(proto);
Assert.assertEquals("test-vol-000001", pbImpl.getVolumeId()); assertEquals("test-vol-000001", pbImpl.getVolumeId());
Assert.assertEquals("/mnt/data", pbImpl.getTargetPath()); assertEquals("/mnt/data", pbImpl.getTargetPath());
Assert.assertEquals("/mnt/staging", pbImpl.getStagingPath()); assertEquals("/mnt/staging", pbImpl.getStagingPath());
Assert.assertFalse(pbImpl.getReadOnly()); assertFalse(pbImpl.getReadOnly());
} }
} }

View File

@ -26,11 +26,11 @@
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.AccessMode; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.AccessMode;
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.VolumeType; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos.VolumeCapability.VolumeType;
import org.apache.hadoop.yarn.proto.YarnProtos; import org.apache.hadoop.yarn.proto.YarnProtos;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.AccessMode.MULTI_NODE_MULTI_WRITER; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.AccessMode.MULTI_NODE_MULTI_WRITER;
import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM; import static org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesRequest.VolumeType.FILE_SYSTEM;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* UT for message exchanges. * UT for message exchanges.
@ -38,7 +38,7 @@
public class TestValidateVolumeCapabilityRequest { public class TestValidateVolumeCapabilityRequest {
@Test @Test
public void testPBRecord() { void testPBRecord() {
CsiAdaptorProtos.VolumeCapability vcProto = CsiAdaptorProtos.VolumeCapability vcProto =
CsiAdaptorProtos.VolumeCapability.newBuilder() CsiAdaptorProtos.VolumeCapability.newBuilder()
.setAccessMode(AccessMode.MULTI_NODE_MULTI_WRITER) .setAccessMode(AccessMode.MULTI_NODE_MULTI_WRITER)
@ -64,22 +64,22 @@ public void testPBRecord() {
ValidateVolumeCapabilitiesRequestPBImpl request = ValidateVolumeCapabilitiesRequestPBImpl request =
new ValidateVolumeCapabilitiesRequestPBImpl(requestProto); new ValidateVolumeCapabilitiesRequestPBImpl(requestProto);
Assert.assertEquals("volume-id-0000001", request.getVolumeId()); assertEquals("volume-id-0000001", request.getVolumeId());
Assert.assertEquals(2, request.getVolumeAttributes().size()); assertEquals(2, request.getVolumeAttributes().size());
Assert.assertEquals("value0", request.getVolumeAttributes().get("attr0")); assertEquals("value0", request.getVolumeAttributes().get("attr0"));
Assert.assertEquals("value1", request.getVolumeAttributes().get("attr1")); assertEquals("value1", request.getVolumeAttributes().get("attr1"));
Assert.assertEquals(1, request.getVolumeCapabilities().size()); assertEquals(1, request.getVolumeCapabilities().size());
VolumeCapability vc = VolumeCapability vc =
request.getVolumeCapabilities().get(0); request.getVolumeCapabilities().get(0);
Assert.assertEquals(MULTI_NODE_MULTI_WRITER, vc.getAccessMode()); assertEquals(MULTI_NODE_MULTI_WRITER, vc.getAccessMode());
Assert.assertEquals(FILE_SYSTEM, vc.getVolumeType()); assertEquals(FILE_SYSTEM, vc.getVolumeType());
Assert.assertEquals(2, vc.getMountFlags().size()); assertEquals(2, vc.getMountFlags().size());
Assert.assertEquals(requestProto, request.getProto()); assertEquals(requestProto, request.getProto());
} }
@Test @Test
public void testNewInstance() { void testNewInstance() {
ValidateVolumeCapabilitiesRequest pbImpl = ValidateVolumeCapabilitiesRequest pbImpl =
ValidateVolumeCapabilitiesRequestPBImpl ValidateVolumeCapabilitiesRequestPBImpl
.newInstance("volume-id-0000123", .newInstance("volume-id-0000123",
@ -89,25 +89,25 @@ public void testNewInstance() {
ImmutableList.of("mountFlag1", "mountFlag2"))), ImmutableList.of("mountFlag1", "mountFlag2"))),
ImmutableMap.of("k1", "v1", "k2", "v2")); ImmutableMap.of("k1", "v1", "k2", "v2"));
Assert.assertEquals("volume-id-0000123", pbImpl.getVolumeId()); assertEquals("volume-id-0000123", pbImpl.getVolumeId());
Assert.assertEquals(1, pbImpl.getVolumeCapabilities().size()); assertEquals(1, pbImpl.getVolumeCapabilities().size());
Assert.assertEquals(FILE_SYSTEM, assertEquals(FILE_SYSTEM,
pbImpl.getVolumeCapabilities().get(0).getVolumeType()); pbImpl.getVolumeCapabilities().get(0).getVolumeType());
Assert.assertEquals(MULTI_NODE_MULTI_WRITER, assertEquals(MULTI_NODE_MULTI_WRITER,
pbImpl.getVolumeCapabilities().get(0).getAccessMode()); pbImpl.getVolumeCapabilities().get(0).getAccessMode());
Assert.assertEquals(2, pbImpl.getVolumeAttributes().size()); assertEquals(2, pbImpl.getVolumeAttributes().size());
CsiAdaptorProtos.ValidateVolumeCapabilitiesRequest proto = CsiAdaptorProtos.ValidateVolumeCapabilitiesRequest proto =
((ValidateVolumeCapabilitiesRequestPBImpl) pbImpl).getProto(); ((ValidateVolumeCapabilitiesRequestPBImpl) pbImpl).getProto();
Assert.assertEquals("volume-id-0000123", proto.getVolumeId()); assertEquals("volume-id-0000123", proto.getVolumeId());
Assert.assertEquals(1, proto.getVolumeCapabilitiesCount()); assertEquals(1, proto.getVolumeCapabilitiesCount());
Assert.assertEquals(AccessMode.MULTI_NODE_MULTI_WRITER, assertEquals(AccessMode.MULTI_NODE_MULTI_WRITER,
proto.getVolumeCapabilities(0).getAccessMode()); proto.getVolumeCapabilities(0).getAccessMode());
Assert.assertEquals(VolumeType.FILE_SYSTEM, assertEquals(VolumeType.FILE_SYSTEM,
proto.getVolumeCapabilities(0).getVolumeType()); proto.getVolumeCapabilities(0).getVolumeType());
Assert.assertEquals(2, proto.getVolumeCapabilities(0) assertEquals(2, proto.getVolumeCapabilities(0)
.getMountFlagsCount()); .getMountFlagsCount());
Assert.assertEquals(2, proto.getVolumeCapabilities(0) assertEquals(2, proto.getVolumeCapabilities(0)
.getMountFlagsList().size()); .getMountFlagsList().size());
} }
} }

View File

@ -20,8 +20,9 @@
import org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesResponse; import org.apache.hadoop.yarn.api.protocolrecords.ValidateVolumeCapabilitiesResponse;
import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.ValidateVolumeCapabilitiesResponsePBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.ValidateVolumeCapabilitiesResponsePBImpl;
import org.apache.hadoop.yarn.proto.CsiAdaptorProtos; import org.apache.hadoop.yarn.proto.CsiAdaptorProtos;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* UT for message exchanges. * UT for message exchanges.
@ -29,33 +30,33 @@
public class TestValidateVolumeCapabilityResponse { public class TestValidateVolumeCapabilityResponse {
@Test @Test
public void testPBRecord() { void testPBRecord() {
CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse proto = CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse proto =
CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse.newBuilder() CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse.newBuilder()
.setSupported(true) .setSupported(true)
.setMessage("capability is supported") .setMessage("capability is supported")
.build(); .build();
ValidateVolumeCapabilitiesResponsePBImpl pbImpl = ValidateVolumeCapabilitiesResponsePBImpl pbImpl =
new ValidateVolumeCapabilitiesResponsePBImpl(proto); new ValidateVolumeCapabilitiesResponsePBImpl(proto);
Assert.assertEquals(true, pbImpl.isSupported()); assertEquals(true, pbImpl.isSupported());
Assert.assertEquals("capability is supported", pbImpl.getResponseMessage()); assertEquals("capability is supported", pbImpl.getResponseMessage());
Assert.assertEquals(proto, pbImpl.getProto()); assertEquals(proto, pbImpl.getProto());
} }
@Test @Test
public void testNewInstance() { void testNewInstance() {
ValidateVolumeCapabilitiesResponse pbImpl = ValidateVolumeCapabilitiesResponse pbImpl =
ValidateVolumeCapabilitiesResponsePBImpl ValidateVolumeCapabilitiesResponsePBImpl
.newInstance(false, "capability not supported"); .newInstance(false, "capability not supported");
Assert.assertEquals(false, pbImpl.isSupported()); assertEquals(false, pbImpl.isSupported());
Assert.assertEquals("capability not supported", assertEquals("capability not supported",
pbImpl.getResponseMessage()); pbImpl.getResponseMessage());
CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse proto = CsiAdaptorProtos.ValidateVolumeCapabilitiesResponse proto =
((ValidateVolumeCapabilitiesResponsePBImpl) pbImpl).getProto(); ((ValidateVolumeCapabilitiesResponsePBImpl) pbImpl).getProto();
Assert.assertEquals(false, proto.getSupported()); assertEquals(false, proto.getSupported());
Assert.assertEquals("capability not supported", proto.getMessage()); assertEquals("capability not supported", proto.getMessage());
} }
} }

View File

@ -20,12 +20,11 @@
import csi.v0.Csi; import csi.v0.Csi;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.Assumptions;
import org.junit.Assume; import org.junit.jupiter.api.BeforeAll;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,6 +32,8 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Test class for CSI client. * Test class for CSI client.
*/ */
@ -42,7 +43,7 @@ public class TestCsiClient {
private static String domainSocket = null; private static String domainSocket = null;
private static FakeCsiDriver driver = null; private static FakeCsiDriver driver = null;
@BeforeClass @BeforeAll
public static void setUp() throws IOException { public static void setUp() throws IOException {
// Use /tmp to fix bind failure caused by the long file name // Use /tmp to fix bind failure caused by the long file name
File tmpDir = new File(System.getProperty("java.io.tmpdir")); File tmpDir = new File(System.getProperty("java.io.tmpdir"));
@ -55,27 +56,27 @@ public static void setUp() throws IOException {
driver = new FakeCsiDriver(domainSocket); driver = new FakeCsiDriver(domainSocket);
} }
@AfterClass @AfterAll
public static void tearDown() throws IOException { public static void tearDown() throws IOException {
if (testRoot != null) { if (testRoot != null) {
FileUtils.deleteDirectory(testRoot); FileUtils.deleteDirectory(testRoot);
} }
} }
@Before @BeforeEach
public void beforeMethod() { public void beforeMethod() {
// Skip tests on non-linux systems // Skip tests on non-linux systems
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
Assume.assumeTrue(osName.contains("nix") || osName.contains("nux")); Assumptions.assumeTrue(osName.contains("nix") || osName.contains("nux"));
} }
@Test @Test
public void testIdentityService() throws IOException { void testIdentityService() throws IOException {
try { try {
driver.start(); driver.start();
CsiClient client = new CsiClientImpl(domainSocket); CsiClient client = new CsiClientImpl(domainSocket);
Csi.GetPluginInfoResponse response = client.getPluginInfo(); Csi.GetPluginInfoResponse response = client.getPluginInfo();
Assert.assertEquals("fake-csi-identity-service", response.getName()); assertEquals("fake-csi-identity-service", response.getName());
} finally { } finally {
driver.stop(); driver.stop();
} }