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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes;
import org.apache.hadoop.hdds.protocol.proto.
ScmBlockLocationProtocolProtos.Status;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Test Result code mappping between SCMException and the protobuf definitions.
Expand All @@ -32,21 +32,18 @@ public class TestSCMExceptionResultCodes {
public void codeMapping() {
// ResultCode = SCMException definition
// Status = protobuf definition
Assert.assertEquals(ResultCodes.values().length, Status.values().length);
Assertions.assertEquals(ResultCodes.values().length,
Status.values().length);
for (int i = 0; i < ResultCodes.values().length; i++) {
ResultCodes codeValue = ResultCodes.values()[i];
Status protoBufValue = Status.values()[i];
Assert.assertTrue(String
.format("Protobuf/Enum constant name mismatch %s %s", codeValue,
protoBufValue), sameName(codeValue.name(), protoBufValue.name()));
Assertions.assertEquals(codeValue.name(), protoBufValue.name(),
String.format("Protobuf/Enum constant name mismatch %s %s",
codeValue, protoBufValue));
ResultCodes converted = ResultCodes.values()[protoBufValue.ordinal()];
Assert.assertEquals(codeValue, converted);
Assertions.assertEquals(codeValue, converted);
}
}

private boolean sameName(String codeValue, String protoBufValue) {
return codeValue.equals(protoBufValue);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
import org.apache.hadoop.security.token.Token;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.hadoop.util.Time;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -72,7 +72,7 @@ public class TestOzoneBlockTokenIdentifier {
private static KeyPair keyPair;
private static X509Certificate cert;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
File base = new File(BASEDIR);
FileUtil.fullyDelete(base);
Expand All @@ -86,7 +86,7 @@ public static void setUp() throws Exception {
.generateCertificate("CN=OzoneMaster", keyPair, 30, "SHA256withRSA");
}

@After
@AfterEach
public void cleanUp() throws Exception {
// KeyStoreTestUtil.cleanupSSLConfig(KEYSTORES_DIR, sslConfsDir);
}
Expand Down Expand Up @@ -174,8 +174,8 @@ public void testTokenSerialization() throws GeneralSecurityException,
decodedTokenId.readFields(new DataInputStream(
new ByteArrayInputStream(decodedToken.getIdentifier())));

Assert.assertEquals(decodedTokenId, tokenId);
Assert.assertEquals(decodedTokenId.getMaxLength(), maxLength);
Assertions.assertEquals(tokenId, decodedTokenId);
Assertions.assertEquals(maxLength, decodedTokenId.getMaxLength());

// Verify a decoded signed Token with public key(certificate)
boolean isValidToken = verifyTokenAsymmetric(decodedTokenId, decodedToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
import org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
import org.apache.hadoop.security.token.Token;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,7 +35,7 @@
import java.util.concurrent.TimeUnit;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import org.apache.hadoop.hdds.security.x509.exceptions.CertificateException;
import org.apache.hadoop.hdds.security.x509.keys.KeyCodec;
import org.bouncycastle.cert.X509CertificateHolder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -56,11 +55,11 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_NAMES;
import static org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient.InitResponse.FAILURE;
import static org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateCodec.getPEMEncodedString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Test class for {@link DefaultCertificateClient}.
Expand All @@ -81,7 +80,7 @@ public class TestDefaultCertificateClient {
private KeyCodec omKeyCodec;
private KeyCodec dnKeyCodec;

@Before
@BeforeEach
public void setUp() throws Exception {
OzoneConfiguration config = new OzoneConfiguration();
config.setStrings(OZONE_SCM_NAMES, "localhost");
Expand Down Expand Up @@ -116,7 +115,7 @@ private void getCertClient() {
dnCertClient = new DNCertificateClient(dnSecurityConfig, certSerialId);
}

@After
@AfterEach
public void tearDown() {
omCertClient = null;
dnCertClient = null;
Expand Down Expand Up @@ -186,7 +185,7 @@ public void testCertificateOps() throws Exception {
x509Certificate.getSerialNumber().toString());
assertNotNull(cert);
assertTrue(cert.getEncoded().length > 0);
assertEquals(cert, x509Certificate);
assertEquals(x509Certificate, cert);

// TODO: test verifyCertificate once implemented.
}
Expand Down Expand Up @@ -230,7 +229,7 @@ private void validateHash(byte[] hash, byte[] data)
omSecurityConfig.getProvider());
rsaSignature.initVerify(omCertClient.getPublicKey());
rsaSignature.update(data);
Assert.assertTrue(rsaSignature.verify(hash));
assertTrue(rsaSignature.verify(hash));
}

/**
Expand Down Expand Up @@ -385,16 +384,14 @@ public void testInitCertAndKeypairValidationFailures() throws Exception {


// Check for DN.
assertEquals(dnCertClient.init(), FAILURE);
assertTrue(dnClientLog.getOutput().contains("Keypair validation " +
"failed"));
assertEquals(FAILURE, dnCertClient.init());
assertTrue(dnClientLog.getOutput().contains("Keypair validation failed"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

// Check for OM.
assertEquals(omCertClient.init(), FAILURE);
assertTrue(omClientLog.getOutput().contains("Keypair validation " +
"failed"));
assertEquals(FAILURE, omCertClient.init());
assertTrue(omClientLog.getOutput().contains("Keypair validation failed"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

Expand All @@ -418,22 +415,21 @@ public void testInitCertAndKeypairValidationFailures() throws Exception {
dnCertCodec.writeCertificate(new X509CertificateHolder(
x509Certificate.getEncoded()));
// Check for DN.
assertEquals(dnCertClient.init(), FAILURE);
assertTrue(dnClientLog.getOutput().contains("Keypair validation " +
"failed"));
assertEquals(FAILURE, dnCertClient.init());
assertTrue(dnClientLog.getOutput().contains("Keypair validation failed"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

// Check for OM.
assertEquals(omCertClient.init(), FAILURE);
assertEquals(FAILURE, omCertClient.init());
assertTrue(omClientLog.getOutput().contains("Keypair validation failed"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

// Case 3. Expect failure when certificate is generated from different
// private key and certificate validation fails.

// Re write the correct public key.
// Re-write the correct public key.
FileUtils.deleteQuietly(Paths.get(
omSecurityConfig.getKeyLocation(OM_COMPONENT).toString(),
omSecurityConfig.getPublicKeyFileName()).toFile());
Expand All @@ -445,16 +441,16 @@ public void testInitCertAndKeypairValidationFailures() throws Exception {
dnKeyCodec.writePublicKey(keyPair.getPublic());

// Check for DN.
assertEquals(dnCertClient.init(), FAILURE);
assertTrue(dnClientLog.getOutput().contains("Stored certificate is " +
"generated with different"));
assertEquals(FAILURE, dnCertClient.init());
assertTrue(dnClientLog.getOutput()
.contains("Stored certificate is generated with different"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

//Check for OM.
assertEquals(omCertClient.init(), FAILURE);
assertTrue(omClientLog.getOutput().contains("Stored certificate is " +
"generated with different"));
assertEquals(FAILURE, omCertClient.init());
assertTrue(omClientLog.getOutput()
.contains("Stored certificate is generated with different"));
dnClientLog.clearOutput();
omClientLog.clearOutput();

Expand All @@ -468,11 +464,11 @@ public void testInitCertAndKeypairValidationFailures() throws Exception {
dnSecurityConfig.getPublicKeyFileName()).toFile());

// Check for DN.
assertEquals(dnCertClient.init(), FAILURE);
assertEquals(FAILURE, dnCertClient.init());
assertTrue(dnClientLog.getOutput().contains("Can't recover public key"));

// Check for OM.
assertEquals(omCertClient.init(), FAILURE);
assertEquals(FAILURE, omCertClient.init());
assertTrue(omClientLog.getOutput().contains("Can't recover public key"));
dnClientLog.clearOutput();
omClientLog.clearOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Test class for HDDS Key Generator.
*/
public class TestHDDSKeyGenerator {
private SecurityConfig config;

@Before
@BeforeEach
public void init() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OZONE_METADATA_DIRS, GenericTestUtils.getTempPath("testpath"));
Expand All @@ -58,11 +58,11 @@ public void testGenerateKey()
throws NoSuchProviderException, NoSuchAlgorithmException {
HDDSKeyGenerator keyGen = new HDDSKeyGenerator(config.getConfiguration());
KeyPair keyPair = keyGen.generateKey();
Assert.assertEquals(config.getKeyAlgo(),
Assertions.assertEquals(config.getKeyAlgo(),
keyPair.getPrivate().getAlgorithm());
PKCS8EncodedKeySpec keySpec =
new PKCS8EncodedKeySpec(keyPair.getPrivate().getEncoded());
Assert.assertEquals("PKCS#8", keySpec.getFormat());
Assertions.assertEquals("PKCS#8", keySpec.getFormat());
}

/**
Expand All @@ -80,7 +80,7 @@ public void testGenerateKeyWithSize() throws NoSuchProviderException,
KeyPair keyPair = keyGen.generateKey(4096);
PublicKey publicKey = keyPair.getPublic();
if (publicKey instanceof RSAPublicKey) {
Assert.assertEquals(4096,
Assertions.assertEquals(4096,
((RSAPublicKey)(publicKey)).getModulus().bitLength());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import org.apache.hadoop.hdds.client.OzoneQuota;

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

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

/**
* Test the json object printer.
Expand All @@ -46,7 +46,7 @@ public void printObjectAsJson() throws IOException {
}

private static void assertContains(String str, String part) {
assertTrue("Expected JSON to contain '" + part + "', but didn't: " + str,
str.contains(part));
assertTrue(str.contains(part),
"Expected JSON to contain '" + part + "', but didn't: " + str);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hdds.server.events;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;

Expand All @@ -40,13 +40,13 @@ public class TestEventQueue {

private AtomicLong eventTotal = new AtomicLong();

@Before
@BeforeEach
public void startEventQueue() {
DefaultMetricsSystem.initialize(getClass().getSimpleName());
queue = new EventQueue();
}

@After
@AfterEach
public void stopEventQueue() {
DefaultMetricsSystem.shutdown();
queue.close();
Expand All @@ -61,7 +61,7 @@ public void simpleEvent() {

queue.fireEvent(EVENT1, 11L);
queue.processAll(1000);
Assert.assertEquals(11, result[0]);
Assertions.assertEquals(11, result[0]);

}

Expand Down Expand Up @@ -94,19 +94,19 @@ public void simpleEventWithFixedThreadPoolExecutor() {

// As it is fixed threadpool executor with 10 threads, all should be
// scheduled.
Assert.assertEquals(11, eventExecutor.queuedEvents());
Assertions.assertEquals(11, eventExecutor.queuedEvents());

// As we don't see all 10 events scheduled.
Assert.assertTrue(eventExecutor.scheduledEvents() > 1 &&
Assertions.assertTrue(eventExecutor.scheduledEvents() > 1 &&
eventExecutor.scheduledEvents() <= 10);

queue.processAll(60000);

Assert.assertTrue(eventExecutor.scheduledEvents() == 11);
Assertions.assertEquals(11, eventExecutor.scheduledEvents());

Assert.assertEquals(166, eventTotal.intValue());
Assertions.assertEquals(166, eventTotal.intValue());

Assert.assertEquals(11, eventExecutor.successfulEvents());
Assertions.assertEquals(11, eventExecutor.successfulEvents());
eventTotal.set(0);

}
Expand Down Expand Up @@ -135,8 +135,8 @@ public void multipleSubscriber() {

queue.fireEvent(EVENT2, 23L);
queue.processAll(1000);
Assert.assertEquals(23, result[0]);
Assert.assertEquals(23, result[1]);
Assertions.assertEquals(23, result[0]);
Assertions.assertEquals(23, result[1]);

}
}
Loading