Skip to content

Commit

Permalink
HADOOP-16512. [hadoop-tools] Fix order of actual and expected express…
Browse files Browse the repository at this point in the history
…ion in assert statements

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
  • Loading branch information
pingsutw authored and aajisaka committed Oct 7, 2019
1 parent 022fe5f commit 14cd969
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 29 deletions.
5 changes: 5 additions & 0 deletions hadoop-tools/hadoop-archives/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.junit.Assert;
import static org.junit.Assert.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -400,7 +401,7 @@ public void testReadFileContent() throws Exception {
readFileCount++;
}
}
assertEquals(fileList.size(), readFileCount);
assertThat(fileList.size()).isEqualTo(readFileCount);
} finally {
harFileSystem.close();
}
Expand Down
5 changes: 5 additions & 0 deletions hadoop-tools/hadoop-distcp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -205,8 +206,8 @@ public void testBuildListing() {
Assert.fail("Duplicates not detected");
} catch (DuplicateFileException ignore) {
}
Assert.assertEquals(listing.getBytesToCopy(), 10);
Assert.assertEquals(listing.getNumberOfPaths(), 3);
assertThat(listing.getBytesToCopy()).isEqualTo(10);
assertThat(listing.getNumberOfPaths()).isEqualTo(3);
TestDistCpUtils.delete(fs, "/tmp");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
package org.apache.hadoop.tools;

import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
import static org.assertj.core.api.Assertions.within;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -106,14 +108,14 @@ public void testParsebandwidth() {
DistCpOptions options = OptionsParser.parse(new String[] {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getMapBandwidth(), 0, DELTA);
assertThat(options.getMapBandwidth()).isCloseTo(0f, within(DELTA));

options = OptionsParser.parse(new String[] {
"-bandwidth",
"11.2",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getMapBandwidth(), 11.2, DELTA);
assertThat(options.getMapBandwidth()).isCloseTo(11.2f, within(DELTA));
}

@Test(expected=IllegalArgumentException.class)
Expand Down Expand Up @@ -256,21 +258,21 @@ public void testParseMaps() {
DistCpOptions options = OptionsParser.parse(new String[] {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getMaxMaps(), DistCpConstants.DEFAULT_MAPS);
assertThat(options.getMaxMaps()).isEqualTo(DistCpConstants.DEFAULT_MAPS);

options = OptionsParser.parse(new String[] {
"-m",
"1",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getMaxMaps(), 1);
assertThat(options.getMaxMaps()).isEqualTo(1);

options = OptionsParser.parse(new String[] {
"-m",
"0",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getMaxMaps(), 1);
assertThat(options.getMaxMaps()).isEqualTo(1);

try {
OptionsParser.parse(new String[] {
Expand Down Expand Up @@ -389,13 +391,13 @@ public void testCopyStrategy() {
"-f",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getCopyStrategy(), "dynamic");
assertThat(options.getCopyStrategy()).isEqualTo("dynamic");

options = OptionsParser.parse(new String[] {
"-f",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getCopyStrategy(), DistCpConstants.UNIFORMSIZE);
assertThat(options.getCopyStrategy()).isEqualTo(DistCpConstants.UNIFORMSIZE);
}

@Test
Expand Down Expand Up @@ -563,7 +565,7 @@ public void testOptionsAppendToConf() {
conf = new Configuration();
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
Assert.assertFalse(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), null);
assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isNull();
options = OptionsParser.parse(new String[] {
"-update",
"-delete",
Expand All @@ -575,8 +577,9 @@ public void testOptionsAppendToConf() {
options.appendToConf(conf);
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.SYNC_FOLDERS.getConfigLabel(), false));
Assert.assertTrue(conf.getBoolean(DistCpOptionSwitch.DELETE_MISSING.getConfigLabel(), false));
Assert.assertEquals(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel()), "U");
Assert.assertEquals(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), 11.2, DELTA);
assertThat(conf.get(DistCpOptionSwitch.PRESERVE_STATUS.getConfigLabel())).isEqualTo("U");
assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
.isCloseTo(11.2f, within(DELTA));
}

@Test
Expand All @@ -588,9 +591,8 @@ public void testOptionsAppendToConfDoesntOverwriteBandwidth() {
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
options.appendToConf(conf);
Assert.assertEquals(
conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1), -1.0,
DELTA);
assertThat(conf.getFloat(DistCpOptionSwitch.BANDWIDTH.getConfigLabel(), -1))
.isCloseTo(-1.0f,within(DELTA));

conf = new Configuration();
Assert.assertEquals(
Expand Down Expand Up @@ -800,6 +802,6 @@ public void testExclusionsOption() {
"/tmp/filters.txt",
"hdfs://localhost:8020/source/first",
"hdfs://localhost:8020/target/"});
Assert.assertEquals(options.getFiltersFile(), "/tmp/filters.txt");
assertThat(options.getFiltersFile()).isEqualTo("/tmp/filters.txt");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.assertj.core.api.Assertions.assertThat;

public class TestCopyMapper {
private static final Logger LOG = LoggerFactory.getLogger(TestCopyMapper.class);
Expand Down Expand Up @@ -769,7 +770,7 @@ public Integer run() {
new CopyListingFileStatus(tmpFS.getFileStatus(
new Path(SOURCE_PATH + "/src/file"))),
context);
Assert.assertEquals(stubContext.getWriter().values().size(), 1);
assertThat(stubContext.getWriter().values().size()).isEqualTo(1);
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().startsWith("SKIP"));
Assert.assertTrue(stubContext.getWriter().values().get(0).toString().
contains(SOURCE_PATH + "/src/file"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

public class TestDistCpUtils {
private static final Logger LOG = LoggerFactory.getLogger(TestDistCpUtils.class);
Expand Down Expand Up @@ -98,39 +99,39 @@ public static void destroy() {
public void testGetRelativePathRoot() {
Path root = new Path("/");
Path child = new Path("/a");
Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/a");
assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/a");
}

@Test
public void testGetRelativePath() {
Path root = new Path("/tmp/abc");
Path child = new Path("/tmp/abc/xyz/file");
Assert.assertEquals(DistCpUtils.getRelativePath(root, child), "/xyz/file");
assertThat(DistCpUtils.getRelativePath(root, child)).isEqualTo("/xyz/file");
}

@Test
public void testPackAttributes() {
EnumSet<FileAttribute> attributes = EnumSet.noneOf(FileAttribute.class);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("");

attributes.add(FileAttribute.REPLICATION);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "R");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("R");

attributes.add(FileAttribute.BLOCKSIZE);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RB");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RB");

attributes.add(FileAttribute.USER);
attributes.add(FileAttribute.CHECKSUMTYPE);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUC");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUC");

attributes.add(FileAttribute.GROUP);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGC");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGC");

attributes.add(FileAttribute.PERMISSION);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPC");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPC");

attributes.add(FileAttribute.TIMES);
Assert.assertEquals(DistCpUtils.packAttributes(attributes), "RBUGPCT");
assertThat(DistCpUtils.packAttributes(attributes)).isEqualTo("RBUGPCT");
}

@Test
Expand Down
5 changes: 5 additions & 0 deletions hadoop-tools/hadoop-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
import java.util.StringJoiner;
import java.util.concurrent.Future;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.assertj.core.api.Assertions.assertThat;

/**
* This tests that the KafkaSink properly formats the Kafka message.
Expand Down Expand Up @@ -147,7 +147,7 @@ public void visit(MetricsVisitor visitor) {
if (LOG.isDebugEnabled()) {
LOG.debug("kafka result: " + jsonResult);
}
assertEquals(jsonLines.toString(), jsonResult);
assertThat(jsonLines.toString()).isEqualTo(jsonResult);
}

StringBuilder recordToJson(MetricsRecord record) {
Expand Down

0 comments on commit 14cd969

Please sign in to comment.