Skip to content
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

HDDS-9503. Migrate simple misc. integration tests to JUnit5 #5854

Merged
merged 8 commits into from
Dec 22, 2023
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 @@ -30,9 +30,9 @@
import org.apache.hadoop.ozone.freon.FreonReplicationOptions;
import org.apache.hadoop.ozone.loadgenerators.LoadGenerator;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
Expand Down Expand Up @@ -117,7 +117,7 @@ enum AllowedBucketLayouts { FILE_SYSTEM_OPTIMIZED, OBJECT_STORE }
private static final String OM_SERVICE_ID = "ozoneChaosTest";
private static final String SCM_SERVICE_ID = "scmChaosTest";

@BeforeClass
@BeforeAll
public static void init() throws Exception {
OzoneConfiguration configuration = new OzoneConfiguration();

Expand Down Expand Up @@ -191,7 +191,7 @@ static void setNumManagers(int nOms, int numScms, boolean enableHA) {
/**
* Shutdown MiniDFSCluster.
*/
@AfterClass
@AfterAll
public static void shutdown() {
if (loadGenerator != null) {
loadGenerator.shutdownLoadGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,26 @@

import static java.util.Collections.singletonList;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.ratis.protocol.exceptions.AlreadyClosedException;
import org.apache.ratis.protocol.exceptions.NotReplicatedException;
import org.apache.ratis.protocol.exceptions.RaftRetryFailureException;
import org.apache.ratis.protocol.exceptions.TimeoutIOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.apache.ozone.test.JUnit5AwareTimeout;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

/**
* Class to test CommitWatcher functionality.
*/
@Timeout(value = 300, unit = TimeUnit.SECONDS)
public class TestCommitWatcher {

/**
* Set a timeout for each test.
*/
@Rule
public TestRule timeout = new JUnit5AwareTimeout(Timeout.seconds(300));
private MiniOzoneCluster cluster;
private OzoneConfiguration conf = new OzoneConfiguration();
private OzoneClient client;
Expand All @@ -104,7 +97,7 @@ public class TestCommitWatcher {
*
* @throws IOException
*/
@Before
@BeforeEach
public void init() throws Exception {
chunkSize = (int)(1 * OzoneConsts.MB);
flushSize = (long) 2 * chunkSize;
Expand Down Expand Up @@ -165,7 +158,7 @@ public void init() throws Exception {
/**
* Shutdown MiniDFSCluster.
*/
@After
@AfterEach
public void shutdown() {
IOUtils.closeQuietly(client);
if (cluster != null) {
Expand Down Expand Up @@ -324,11 +317,12 @@ public void testReleaseBuffersOnException() throws Exception {
// can itself get AlreadyClosedException from the Ratis Server
// and the write may fail with RaftRetryFailureException
Throwable t = HddsClientUtils.checkForException(ioe);
assertTrue("Unexpected exception: " + t.getClass(),
assertTrue(
t instanceof RaftRetryFailureException ||
t instanceof TimeoutIOException ||
t instanceof AlreadyClosedException ||
t instanceof NotReplicatedException);
t instanceof NotReplicatedException,
"Unexpected exception: " + t.getClass());
}
if (ratisClient.getReplicatedMinCommitIndex() < replies.get(1)
.getLogIndex()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@
import org.apache.hadoop.security.token.Token;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.util.ExitUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.apache.ozone.test.JUnit5AwareTimeout;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -64,6 +61,7 @@
import java.util.Objects;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;

Expand Down Expand Up @@ -92,14 +90,15 @@
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
import static org.apache.ozone.test.GenericTestUtils.waitFor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Integration test to verify block tokens in a secure cluster.
*/
@InterfaceAudience.Private
@Timeout(value = 180, unit = TimeUnit.SECONDS)
public final class TestBlockTokens {
private static final Logger LOG = LoggerFactory.getLogger(TestBlockTokens.class);
private static final String TEST_VOLUME = "testvolume";
Expand All @@ -109,9 +108,6 @@ public final class TestBlockTokens {
private static final int EXPIRY_DURATION_IN_MS = 10000;
private static final int ROTATION_CHECK_DURATION_IN_MS = 100;

@Rule
public TestRule timeout = new JUnit5AwareTimeout(Timeout.seconds(180));

private static MiniKdc miniKdc;
private static OzoneConfiguration conf;
private static File workDir;
Expand All @@ -127,7 +123,7 @@ public final class TestBlockTokens {
private static BlockInputStreamFactory blockInputStreamFactory =
new BlockInputStreamFactoryImpl();

@BeforeClass
@BeforeAll
public static void init() throws Exception {
conf = new OzoneConfiguration();
conf.set(OZONE_SCM_CLIENT_ADDRESS_KEY, "localhost");
Expand Down Expand Up @@ -159,7 +155,7 @@ private static void createTestData() throws IOException {
}
}

@AfterClass
@AfterAll
public static void stop() {
miniKdc.stop();
IOUtils.close(LOG, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ratis.util.ExitUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.apache.ozone.test.JUnit5AwareTimeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -56,6 +48,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static java.time.Duration.between;
Expand All @@ -78,19 +71,20 @@
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_KERBEROS_PRINCIPAL_KEY;
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Assertions;
/**
* Integration test class to verify block token CLI commands functionality in a
* secure cluster.
*/
@InterfaceAudience.Private
@Timeout(value = 180, unit = TimeUnit.SECONDS)
public final class TestBlockTokensCLI {
private static final Logger LOG = LoggerFactory
.getLogger(TestBlockTokensCLI.class);

@Rule
public TestRule timeout = new JUnit5AwareTimeout(Timeout.seconds(180));

private static MiniKdc miniKdc;
private static OzoneAdmin ozoneAdmin;
private static OzoneConfiguration conf;
Expand All @@ -105,7 +99,7 @@ public final class TestBlockTokensCLI {
private static MiniOzoneHAClusterImpl cluster;
private static OzoneClient client;

@BeforeClass
@BeforeAll
public static void init() throws Exception {
conf = new OzoneConfiguration();
conf.set(OZONE_SCM_CLIENT_ADDRESS_KEY, "localhost");
Expand All @@ -128,7 +122,7 @@ public static void init() throws Exception {
ozoneAdmin = new OzoneAdmin(conf);
}

@AfterClass
@AfterAll
public static void stop() {
miniKdc.stop();
IOUtils.close(LOG, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,30 @@

import org.apache.ozone.test.UnhealthyTest;
import org.apache.ozone.test.tag.Unhealthy;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.apache.ozone.test.JUnit5AwareTimeout;
import org.junit.jupiter.api.Timeout;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

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

/**
* This class tests container balancer operations
* from cblock clients.
*/
@Timeout(value = 300, unit = TimeUnit.MILLISECONDS)
public class TestContainerBalancerOperations {

/**
* Set a timeout for each test.
*/
@Rule
public TestRule timeout = new JUnit5AwareTimeout(Timeout.seconds(300));

private static ScmClient containerBalancerClient;
private static MiniOzoneCluster cluster;
private static OzoneConfiguration ozoneConf;

@BeforeClass
@BeforeAll
public static void setup() throws Exception {
ozoneConf = new OzoneConfiguration();
ozoneConf.setClass(ScmConfigKeys.OZONE_SCM_CONTAINER_PLACEMENT_IMPL_KEY,
Expand All @@ -66,7 +59,7 @@ public static void setup() throws Exception {
cluster.waitForClusterToBeReady();
}

@AfterClass
@AfterAll
public static void cleanup() throws Exception {
if (cluster != null) {
cluster.shutdown();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down Expand Up @@ -29,39 +29,32 @@
import org.apache.hadoop.hdds.scm.ha.SCMHAUtils;
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.pipeline.PipelineNotFoundException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.apache.ozone.test.JUnit5AwareTimeout;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.apache.hadoop.hdds.protocol.DatanodeDetails.Port.Name.REPLICATION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* This class tests container operations (TODO currently only supports create)
* from cblock clients.
*/
@Timeout(value = 300, unit = TimeUnit.SECONDS)
public class TestContainerOperations {

/**
* Set a timeout for each test.
*/
@Rule
public TestRule timeout = new JUnit5AwareTimeout(Timeout.seconds(300));

private static ScmClient storageClient;
private static MiniOzoneCluster cluster;
private static OzoneConfiguration ozoneConf;

@BeforeClass
@BeforeAll
public static void setup() throws Exception {
ozoneConf = new OzoneConfiguration();
ozoneConf.setClass(ScmConfigKeys.OZONE_SCM_CONTAINER_PLACEMENT_IMPL_KEY,
Expand All @@ -71,7 +64,7 @@ public static void setup() throws Exception {
cluster.waitForClusterToBeReady();
}

@AfterClass
@AfterAll
public static void cleanup() throws Exception {
if (cluster != null) {
cluster.shutdown();
Expand Down Expand Up @@ -100,13 +93,13 @@ public void testCreate() throws Exception {
public void testGetPipeline() throws Exception {
try {
storageClient.getPipeline(PipelineID.randomId().getProtobuf());
Assert.fail("Get Pipeline should fail");
Assertions.fail("Get Pipeline should fail");
} catch (Exception e) {
assertTrue(
SCMHAUtils.unwrapException(e) instanceof PipelineNotFoundException);
}

Assert.assertFalse(storageClient.listPipelines().isEmpty());
Assertions.assertFalse(storageClient.listPipelines().isEmpty());
}

@Test
Expand Down
Loading