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 @@ -31,10 +31,10 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.mockito.Mockito;
import picocli.CommandLine;

Expand Down Expand Up @@ -62,7 +62,7 @@ public class TestInfoSubCommand {
private Logger logger;
private TestAppender appender;

@Before
@BeforeEach
public void setup() throws IOException {
scmClient = mock(ScmClient.class);
datanodes = createDatanodeDetails(3);
Expand All @@ -75,7 +75,7 @@ public void setup() throws IOException {
logger.addAppender(appender);
}

@After
@AfterEach
public void after() {
logger.removeAppender(appender);
}
Expand Down Expand Up @@ -105,20 +105,20 @@ private void testReplicaIncludedInOutput(boolean includeIndex)
List<LoggingEvent> replica = logs.stream()
.filter(m -> m.getRenderedMessage().matches("(?s)^Replicas:.*"))
.collect(Collectors.toList());
Assert.assertEquals(1, replica.size());
Assertions.assertEquals(1, replica.size());

// Ensure each DN UUID is mentioned in the message:
for (DatanodeDetails dn : datanodes) {
Pattern pattern = Pattern.compile(".*" + dn.getUuid().toString() + ".*",
Pattern.DOTALL);
Matcher matcher = pattern.matcher(replica.get(0).getRenderedMessage());
Assert.assertTrue(matcher.matches());
Assertions.assertTrue(matcher.matches());
}
// Ensure ReplicaIndex is not mentioned as it was not passed in the proto:
Pattern pattern = Pattern.compile(".*ReplicaIndex.*",
Pattern.DOTALL);
Matcher matcher = pattern.matcher(replica.get(0).getRenderedMessage());
Assert.assertEquals(includeIndex, matcher.matches());
Assertions.assertEquals(includeIndex, matcher.matches());
}

@Test
Expand All @@ -135,14 +135,14 @@ public void testReplicasNotOutputIfError() throws IOException {
List<LoggingEvent> replica = logs.stream()
.filter(m -> m.getRenderedMessage().matches("(?s)^Replicas:.*"))
.collect(Collectors.toList());
Assert.assertEquals(0, replica.size());
Assertions.assertEquals(0, replica.size());

// Ensure we have an error logged:
List<LoggingEvent> error = logs.stream()
.filter(m -> m.getLevel() == Level.ERROR)
.collect(Collectors.toList());
Assert.assertEquals(1, error.size());
Assert.assertTrue(error.get(0).getRenderedMessage()
Assertions.assertEquals(1, error.size());
Assertions.assertTrue(error.get(0).getRenderedMessage()
.matches("(?s)^Unable to retrieve the replica details.*"));
}

Expand All @@ -156,13 +156,13 @@ public void testReplicasNotOutputIfErrorWithJson() throws IOException {
cmd.execute(scmClient);

List<LoggingEvent> logs = appender.getLog();
Assert.assertEquals(2, logs.size());
Assertions.assertEquals(2, logs.size());
String error = logs.get(0).getRenderedMessage();
String json = logs.get(1).getRenderedMessage();

Assert.assertTrue(error
Assertions.assertTrue(error
.matches("(?s)^Unable to retrieve the replica details.*"));
Assert.assertFalse(json.matches("(?s).*replicas.*"));
Assertions.assertFalse(json.matches("(?s).*replicas.*"));
}

@Test
Expand All @@ -188,21 +188,21 @@ private void testJsonOutput() throws IOException {
cmd.execute(scmClient);

List<LoggingEvent> logs = appender.getLog();
Assert.assertEquals(1, logs.size());
Assertions.assertEquals(1, logs.size());

// Ensure each DN UUID is mentioned in the message after replicas:
String json = logs.get(0).getRenderedMessage();
Assert.assertTrue(json.matches("(?s).*replicas.*"));
Assertions.assertTrue(json.matches("(?s).*replicas.*"));
for (DatanodeDetails dn : datanodes) {
Pattern pattern = Pattern.compile(
".*replicas.*" + dn.getUuid().toString() + ".*", Pattern.DOTALL);
Matcher matcher = pattern.matcher(json);
Assert.assertTrue(matcher.matches());
Assertions.assertTrue(matcher.matches());
}
Pattern pattern = Pattern.compile(".*replicaIndex.*",
Pattern.DOTALL);
Matcher matcher = pattern.matcher(json);
Assert.assertTrue(matcher.matches());
Assertions.assertTrue(matcher.matches());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.apache.hadoop.hdds.scm.container.ContainerID;
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
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 org.mockito.Mockito;
import picocli.CommandLine;

Expand All @@ -38,7 +37,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;

/**
Expand All @@ -54,14 +54,14 @@ public class TestReportSubCommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
cmd = new ReportSubcommand();
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down Expand Up @@ -106,9 +106,9 @@ public void testValidJsonOutput() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(outContent.toString("UTF-8"));

Assert.assertTrue(json.get("reportTimeStamp") != null);
Assert.assertTrue(json.get("stats") != null);
Assert.assertTrue(json.get("samples") != null);
assertNotNull(json.get("reportTimeStamp"));
assertNotNull(json.get("stats"));
assertNotNull(json.get("samples"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.apache.hadoop.hdds.scm.cli.ContainerBalancerStartSubcommand;
import org.apache.hadoop.hdds.scm.cli.ContainerBalancerStatusSubcommand;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.After;
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 org.mockito.Mockito;

import java.io.ByteArrayOutputStream;
Expand All @@ -35,11 +35,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

/**
* Unit tests to validate the the ContainerBalancerSubCommand class includes the
* Unit tests to validate the ContainerBalancerSubCommand class includes the
* correct output when executed against a mock client.
*/
public class TestContainerBalancerSubCommand {
Expand All @@ -53,7 +53,7 @@ public class TestContainerBalancerSubCommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
stopCmd = new ContainerBalancerStopSubcommand();
startCmd = new ContainerBalancerStartSubcommand();
Expand All @@ -62,7 +62,7 @@ public void setup() throws UnsupportedEncodingException {
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.After;
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.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -35,13 +35,13 @@
import org.mockito.Mockito;
import picocli.CommandLine;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.mock;

/**
* Unit tests to validate the the DecommissionSubCommand class includes the
* Unit tests to validate the DecommissionSubCommand class includes the
* correct output when executed against a mock client.
*/
public class TestDecommissionSubCommand {
Expand All @@ -53,14 +53,14 @@ public class TestDecommissionSubCommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
cmd = new DecommissionSubCommand();
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.After;
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.ByteArrayOutputStream;
import java.io.PrintStream;
Expand All @@ -34,12 +34,12 @@
import java.util.regex.Pattern;
import org.mockito.Mockito;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.any;

/**
* Unit tests to validate the the TestListInfoSubCommand class includes the
* Unit tests to validate the TestListInfoSubCommand class includes the
* correct output when executed against a mock client.
*/
public class TestListInfoSubcommand {
Expand All @@ -51,14 +51,14 @@ public class TestListInfoSubcommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
cmd = new ListInfoSubcommand();
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.After;
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.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -35,14 +35,14 @@
import org.mockito.Mockito;
import picocli.CommandLine;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.mock;

/**
* Unit tests to validate the the DecommissionSubCommand class includes the
* Unit tests to validate the DecommissionSubCommand class includes the
* correct output when executed against a mock client.
*/
public class TestMaintenanceSubCommand {
Expand All @@ -54,14 +54,14 @@ public class TestMaintenanceSubCommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
cmd = new MaintenanceSubCommand();
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import org.apache.hadoop.hdds.scm.DatanodeAdminError;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.After;
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.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -35,8 +35,8 @@
import org.mockito.Mockito;
import picocli.CommandLine;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Mockito.mock;

Expand All @@ -53,14 +53,14 @@ public class TestRecommissionSubCommand {
private final PrintStream originalErr = System.err;
private static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();

@Before
@BeforeEach
public void setup() throws UnsupportedEncodingException {
cmd = new RecommissionSubCommand();
System.setOut(new PrintStream(outContent, false, DEFAULT_ENCODING));
System.setErr(new PrintStream(errContent, false, DEFAULT_ENCODING));
}

@After
@AfterEach
public void tearDown() {
System.setOut(originalOut);
System.setErr(originalErr);
Expand Down
Loading