Skip to content

HADOOP-19426. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-azure-datalake. #7652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;

import com.microsoft.azure.datalake.store.oauth2.DeviceCodeTokenProvider;
import com.microsoft.azure.datalake.store.oauth2.MsiTokenProvider;
Expand All @@ -44,16 +45,16 @@
.AZURE_AD_TOKEN_PROVIDER_TYPE_KEY;
import static org.apache.hadoop.fs.adl.AdlConfKeys.DEVICE_CODE_CLIENT_APP_ID;
import static org.apache.hadoop.fs.adl.TokenProviderType.*;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.hadoop.security.ProviderUtils;
import org.apache.hadoop.security.alias.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/**
* Test appropriate token provider is loaded as per configuration.
Expand All @@ -65,8 +66,8 @@ public class TestAzureADTokenProvider {
private static final String CLIENT_SECRET = "MY_CLIENT_SECRET";
private static final String REFRESH_URL = "http://localhost:8080/refresh";

@Rule
public final TemporaryFolder tempDir = new TemporaryFolder();
@TempDir
private Path tempDir;

@Test
public void testRefreshTokenProvider()
Expand All @@ -81,7 +82,7 @@ public void testRefreshTokenProvider()
AdlFileSystem fileSystem = new AdlFileSystem();
fileSystem.initialize(uri, conf);
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
Assert.assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider);
assertTrue(tokenProvider instanceof RefreshTokenBasedTokenProvider);
}

@Test
Expand All @@ -97,7 +98,7 @@ public void testClientCredTokenProvider()
AdlFileSystem fileSystem = new AdlFileSystem();
fileSystem.initialize(uri, conf);
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
Assert.assertTrue(tokenProvider instanceof ClientCredsTokenProvider);
assertTrue(tokenProvider instanceof ClientCredsTokenProvider);
}

@Test
Expand All @@ -110,7 +111,7 @@ public void testMSITokenProvider()
AdlFileSystem fileSystem = new AdlFileSystem();
fileSystem.initialize(uri, conf);
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
Assert.assertTrue(tokenProvider instanceof MsiTokenProvider);
assertTrue(tokenProvider instanceof MsiTokenProvider);
}

@Test
Expand All @@ -129,7 +130,7 @@ public void testDeviceCodeTokenProvider()
AdlFileSystem fileSystem = new AdlFileSystem();
fileSystem.initialize(uri, conf);
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
Assert.assertTrue(tokenProvider instanceof DeviceCodeTokenProvider);
assertTrue(tokenProvider instanceof DeviceCodeTokenProvider);
}
}

Expand All @@ -145,7 +146,7 @@ public void testCustomCredTokenProvider()
AdlFileSystem fileSystem = new AdlFileSystem();
fileSystem.initialize(uri, conf);
AccessTokenProvider tokenProvider = fileSystem.getTokenProvider();
Assert.assertTrue(tokenProvider instanceof SdkTokenProviderAdapter);
assertTrue(tokenProvider instanceof SdkTokenProviderAdapter);
}

@Test
Expand All @@ -157,7 +158,7 @@ public void testInvalidProviderConfigurationForType()
AdlFileSystem fileSystem = new AdlFileSystem();
try {
fileSystem.initialize(uri, conf);
Assert.fail("Initialization should have failed due no token provider "
fail("Initialization should have failed due no token provider "
+ "configuration");
} catch (IllegalArgumentException e) {
GenericTestUtils.assertExceptionContains(
Expand All @@ -179,17 +180,17 @@ public void testInvalidProviderConfigurationForClassPath()
"wrong.classpath.CustomMockTokenProvider");
try {
fileSystem.initialize(uri, conf);
Assert.fail("Initialization should have failed due invalid provider "
fail("Initialization should have failed due invalid provider "
+ "configuration");
} catch (RuntimeException e) {
Assert.assertTrue(
assertTrue(
e.getMessage().contains("wrong.classpath.CustomMockTokenProvider"));
}
}

private CredentialProvider createTempCredProvider(Configuration conf)
throws URISyntaxException, IOException {
final File file = tempDir.newFile("test.jks");
final File file = tempDir.resolve("test.jks").toFile();
final URI jks = ProviderUtils.nestURIForLocalJavaKeyStoreProvider(
file.toURI());
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
Expand Down Expand Up @@ -217,7 +218,7 @@ public void testRefreshTokenWithCredentialProvider()
fileSystem.initialize(uri, conf);
RefreshTokenBasedTokenProvider expected =
new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN);
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
assertTrue(EqualsBuilder.reflectionEquals(expected,
fileSystem.getTokenProvider()));
}

Expand All @@ -236,7 +237,7 @@ public void testRefreshTokenWithCredentialProviderFallback()
fileSystem.initialize(uri, conf);
RefreshTokenBasedTokenProvider expected =
new RefreshTokenBasedTokenProvider(CLIENT_ID, REFRESH_TOKEN);
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
assertTrue(EqualsBuilder.reflectionEquals(expected,
fileSystem.getTokenProvider()));
}

Expand All @@ -263,7 +264,7 @@ public void testClientCredWithCredentialProvider()
fileSystem.initialize(uri, conf);
ClientCredsTokenProvider expected = new ClientCredsTokenProvider(
REFRESH_URL, CLIENT_ID, CLIENT_SECRET);
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
assertTrue(EqualsBuilder.reflectionEquals(expected,
fileSystem.getTokenProvider()));
}

Expand All @@ -283,7 +284,7 @@ public void testClientCredWithCredentialProviderFallback()
fileSystem.initialize(uri, conf);
ClientCredsTokenProvider expected = new ClientCredsTokenProvider(
REFRESH_URL, CLIENT_ID, CLIENT_SECRET);
Assert.assertTrue(EqualsBuilder.reflectionEquals(expected,
assertTrue(EqualsBuilder.reflectionEquals(expected,
fileSystem.getTokenProvider()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URI;
Expand All @@ -31,6 +30,7 @@
.AZURE_AD_TOKEN_PROVIDER_CLASS_KEY;
import static org.apache.hadoop.fs.adl.AdlConfKeys
.AZURE_AD_TOKEN_PROVIDER_TYPE_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* This class verifies path conversion to SDK.
Expand All @@ -48,17 +48,17 @@ public void testToRelativePath() throws URISyntaxException, IOException {

fs.initialize(new URI("adl://temp.account.net"), configuration);

Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
Assert.assertEquals("/usr",
assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
assertEquals("/usr",
fs.toRelativeFilePath(new Path("adl://temp.account.net/usr")));

// When working directory is set.
fs.setWorkingDirectory(new Path("/a/b/"));
Assert.assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
Assert.assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr")));
Assert.assertEquals("/usr",
assertEquals("/usr", fs.toRelativeFilePath(new Path("/usr")));
assertEquals("/a/b/usr", fs.toRelativeFilePath(new Path("usr")));
assertEquals("/usr",
fs.toRelativeFilePath(new Path("adl://temp.account.net/usr")));
Assert.assertEquals("/usr",
assertEquals("/usr",
fs.toRelativeFilePath(new Path("wasb://temp.account.net/usr")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.apache.hadoop.fs.adl.AdlConfKeys.ADL_BLOCK_SIZE;
import static org.apache.hadoop.fs.adl.AdlConfKeys
Expand Down Expand Up @@ -57,7 +57,7 @@
.TOKEN_PROVIDER_TYPE_REFRESH_TOKEN;
import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY;

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

import java.io.File;
import java.io.FileOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.adl.common.Parallelized;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -39,19 +36,21 @@
import java.util.UUID;

import static org.apache.hadoop.fs.adl.AdlConfKeys.WRITE_BUFFER_SIZE_KEY;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Verify data integrity with different data sizes with buffer size.
*/
@RunWith(Parallelized.class)
public class TestAdlDifferentSizeWritesLive {
private static Random rand = new Random();
private int totalSize;
private int chunkSize;

public TestAdlDifferentSizeWritesLive(int totalSize, int chunkSize) {
this.totalSize = totalSize;
this.chunkSize = chunkSize;
public void initTestAdlDifferentSizeWritesLive(int pTotalSize, int pChunkSize) {
this.totalSize = pTotalSize;
this.chunkSize = pChunkSize;
}

public static byte[] getRandomByteArrayData(int size) {
Expand All @@ -60,8 +59,6 @@ public static byte[] getRandomByteArrayData(int size) {
return b;
}

@Parameterized.Parameters(name = "{index}: Data Size [{0}] ; Chunk Size "
+ "[{1}]")
public static Collection testDataForIntegrityTest() {
return Arrays.asList(
new Object[][] {{4 * 1024, 1 * 1024}, {4 * 1024, 7 * 1024},
Expand All @@ -71,7 +68,7 @@ public static Collection testDataForIntegrityTest() {
{10 * 1024, 8 * 1024}});
}

@BeforeClass
@BeforeAll
public static void cleanUpParent() throws IOException, URISyntaxException {
if (AdlStorageConfiguration.isContractTestEnabled()) {
Path path = new Path("/test/dataIntegrityCheck/");
Expand All @@ -80,14 +77,15 @@ public static void cleanUpParent() throws IOException, URISyntaxException {
}
}

@Before
@BeforeEach
public void setup() throws Exception {
org.junit.Assume
.assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
}

@Test
public void testDataIntegrity() throws IOException {
@MethodSource("testDataForIntegrityTest")
@ParameterizedTest(name = "{index}: Data Size [{0}] ; Chunk Size [{1}]")
public void testDataIntegrity(int pTotalSize, int pChunkSize) throws IOException {
initTestAdlDifferentSizeWritesLive(pTotalSize, pChunkSize);
Path path = new Path(
"/test/dataIntegrityCheck/" + UUID.randomUUID().toString());
FileSystem fs = null;
Expand Down Expand Up @@ -117,7 +115,7 @@ public void testDataIntegrity() throws IOException {
FSDataInputStream in = fs.open(path);
in.readFully(0, actualData);
in.close();
Assert.assertArrayEquals(expectedData, actualData);
Assert.assertTrue(fs.delete(path, true));
assertArrayEquals(expectedData, actualData);
assertTrue(fs.delete(path, true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@
import org.apache.hadoop.fs.FileAlreadyExistsException;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.adl.common.Parallelized;
import org.apache.hadoop.fs.permission.FsPermission;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collection;
import java.util.UUID;

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

/**
* Test createNonRecursive API.
*/
@RunWith(Parallelized.class)
public class TestAdlInternalCreateNonRecursive {
private Path inputFileName;
private FsPermission inputPermission;
Expand All @@ -51,9 +49,9 @@ public class TestAdlInternalCreateNonRecursive {
private Class<IOException> expectedExceptionType;
private FileSystem adlStore;

public TestAdlInternalCreateNonRecursive(String testScenario, String fileName,
public void initTestAdlInternalCreateNonRecursive(String testScenario, String fileName,
FsPermission permission, boolean override, boolean fileAlreadyExist,
boolean parentAlreadyExist, Class<IOException> exceptionType) {
boolean parentAlreadyExist, Class<IOException> exceptionType) throws Exception {

// Random parent path for each test so that parallel execution does not fail
// other running test.
Expand All @@ -64,9 +62,9 @@ public TestAdlInternalCreateNonRecursive(String testScenario, String fileName,
inputOverride = override;
inputParentAlreadyExist = parentAlreadyExist;
expectedExceptionType = exceptionType;
setUp();
}

@Parameterized.Parameters(name = "{0}")
public static Collection adlCreateNonRecursiveTestData()
throws UnsupportedEncodingException {
/*
Expand All @@ -92,14 +90,18 @@ public static Collection adlCreateNonRecursiveTestData()
IOException.class }*/});
}

@Before
public void setUp() throws Exception {
Assume.assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
assumeTrue(AdlStorageConfiguration.isContractTestEnabled());
adlStore = AdlStorageConfiguration.createStorageConnector();
}

@Test
public void testCreateNonRecursiveFunctionality() throws IOException {
@MethodSource("adlCreateNonRecursiveTestData")
@ParameterizedTest(name = "{0}")
public void testCreateNonRecursiveFunctionality(String testScenario, String fileName,
FsPermission permission, boolean override, boolean fileAlreadyExist,
boolean parentAlreadyExist, Class<IOException> exceptionType) throws Exception {
initTestAdlInternalCreateNonRecursive(testScenario, fileName, permission,
override, fileAlreadyExist, parentAlreadyExist, exceptionType);
if (inputFileAlreadyExist) {
FileSystem.create(adlStore, inputFileName, inputPermission);
}
Expand All @@ -122,12 +124,12 @@ public void testCreateNonRecursiveFunctionality() throws IOException {
throw e;
}

Assert.assertEquals(expectedExceptionType, e.getClass());
assertEquals(expectedExceptionType, e.getClass());
return;
}

if (expectedExceptionType != null) {
Assert.fail("CreateNonRecursive should have failed with exception "
fail("CreateNonRecursive should have failed with exception "
+ expectedExceptionType.getName());
}
}
Expand Down
Loading