Skip to content

Commit 40edced

Browse files
committed
HBASE-30002 Addendum remove Assert usage
1 parent 9fe9593 commit 40edced

File tree

6 files changed

+44
-52
lines changed

6 files changed

+44
-52
lines changed

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/ExportFileSystemStateWithMergeOrSplitRegionTestBase.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20-
import static org.junit.Assert.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
import java.util.List;
2323
import java.util.stream.Collectors;
@@ -72,8 +72,6 @@ public void testExportFileSystemStateWithMergeRegion() throws Exception {
7272
admin.snapshot(snapshotName0, tableName0);
7373
// export snapshot and verify
7474
testExportFileSystemState(tableName0, snapshotName0, snapshotName0, tableNumFiles);
75-
// delete table
76-
TEST_UTIL.deleteTable(tableName0);
7775
}
7876

7977
@TestTemplate
@@ -119,7 +117,5 @@ public void testExportFileSystemStateWithSplitRegion() throws Exception {
119117
testExportFileSystemState(tmpConf, splitTableName, splitTableSnap, splitTableSnap,
120118
tableNumFiles, TEST_UTIL.getDefaultRootDirPath(), getHdfsDestinationDir(), false, false,
121119
getBypassRegionPredicate(), true, false);
122-
// delete table
123-
TEST_UTIL.deleteTable(splitTableName);
124120
}
125121
}

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/ExportSnapshotMiscTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.util.HashMap;
2424
import java.util.Map;

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/ExportSnapshotTestBase.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
package org.apache.hadoop.hbase.snapshot;
1919

2020
import static org.apache.hadoop.util.ToolRunner.run;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

2525
import java.io.IOException;
2626
import java.lang.reflect.Method;
@@ -185,11 +185,11 @@ protected static void testExportFileSystemState(final Configuration conf,
185185
// Export Snapshot
186186
int res = runExportSnapshot(conf, snapshotName, targetName, srcDir, rawTgtDir, overwrite,
187187
resetTtl, checksumVerify, true, true);
188-
assertEquals("success " + success + ", res=" + res, success ? 0 : 1, res);
188+
assertEquals(success ? 0 : 1, res, "success " + success + ", res=" + res);
189189
if (!success) {
190190
final Path targetDir = new Path(HConstants.SNAPSHOT_DIR_NAME, targetName);
191-
assertFalse(tgtDir.toString() + " " + targetDir.toString(),
192-
tgtFs.exists(new Path(tgtDir, targetDir)));
191+
assertFalse(tgtFs.exists(new Path(tgtDir, targetDir)),
192+
tgtDir.toString() + " " + targetDir.toString());
193193
return;
194194
}
195195
LOG.info("Exported snapshot");
@@ -199,9 +199,9 @@ protected static void testExportFileSystemState(final Configuration conf,
199199
assertEquals(filesExpected > 0 ? 2 : 1, rootFiles.length);
200200
for (FileStatus fileStatus : rootFiles) {
201201
String name = fileStatus.getPath().getName();
202-
assertTrue(fileStatus.toString(), fileStatus.isDirectory());
203-
assertTrue(name.toString(), name.equals(HConstants.SNAPSHOT_DIR_NAME)
204-
|| name.equals(HConstants.HFILE_ARCHIVE_DIRECTORY));
202+
assertTrue(fileStatus.isDirectory(), fileStatus.toString());
203+
assertTrue(name.equals(HConstants.SNAPSHOT_DIR_NAME)
204+
|| name.equals(HConstants.HFILE_ARCHIVE_DIRECTORY), name.toString());
205205
}
206206
LOG.info("Verified filesystem state");
207207

@@ -260,8 +260,8 @@ public void storeFile(final RegionInfo regionInfo, final String family,
260260
}
261261

262262
private void verifyNonEmptyFile(final Path path) throws IOException {
263-
assertTrue(path + " should exists", fs.exists(path));
264-
assertTrue(path + " should not be empty", fs.getFileStatus(path).getLen() > 0);
263+
assertTrue(fs.exists(path), path + " should exists");
264+
assertTrue(fs.getFileStatus(path).getLen() > 0, path + " should not be empty");
265265
}
266266
});
267267

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshotHelpers.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.util.ArrayList;
2424
import java.util.Collection;
@@ -107,7 +107,7 @@ public void testGroupFilesForSplitsWithoutCustomFileGrouper() {
107107
Collection<List<Pair<SnapshotFileInfo, Long>>> groups =
108108
inputFormat.groupFilesForSplits(conf, files);
109109

110-
assertEquals("Should create 3 groups", 3, groups.size());
110+
assertEquals(3, groups.size(), "Should create 3 groups");
111111

112112
long totalSize = 0;
113113
int totalFiles = 0;
@@ -118,8 +118,8 @@ public void testGroupFilesForSplitsWithoutCustomFileGrouper() {
118118
}
119119
}
120120

121-
assertEquals("All files should be included", 10, totalFiles);
122-
assertEquals("Total size should be preserved", 450, totalSize);
121+
assertEquals(10, totalFiles, "All files should be included");
122+
assertEquals(450, totalSize, "Total size should be preserved");
123123
}
124124

125125
@Test
@@ -141,7 +141,7 @@ public void testGroupFilesForSplitsWithCustomFileGrouper() {
141141
Collection<List<Pair<SnapshotFileInfo, Long>>> groups =
142142
inputFormat.groupFilesForSplits(conf, files);
143143

144-
assertEquals("Should create splits based on custom grouper output", 4, groups.size());
144+
assertEquals(4, groups.size(), "Should create splits based on custom grouper output");
145145

146146
long totalSize = 0;
147147
int totalFiles = 0;
@@ -152,8 +152,8 @@ public void testGroupFilesForSplitsWithCustomFileGrouper() {
152152
}
153153
}
154154

155-
assertEquals("All files should be included", 8, totalFiles);
156-
assertEquals("Total size should be preserved", 140, totalSize);
155+
assertEquals(8, totalFiles, "All files should be included");
156+
assertEquals(140, totalSize, "Total size should be preserved");
157157
}
158158

159159
@Test
@@ -169,7 +169,7 @@ public void testFileLocationResolverWithNoopResolver() {
169169
new ExportSnapshot.NoopFileLocationResolver();
170170
Set<String> locations = resolver.getLocationsForInputFiles(files);
171171

172-
assertTrue("NoopFileLocationResolver should return empty locations", locations.isEmpty());
172+
assertTrue(locations.isEmpty(), "NoopFileLocationResolver should return empty locations");
173173
}
174174

175175
@Test
@@ -184,13 +184,13 @@ public void testFileLocationResolverWithCustomResolver() {
184184
TestFileLocationResolver resolver = new TestFileLocationResolver();
185185
Set<String> locations = resolver.getLocationsForInputFiles(files);
186186

187-
assertEquals("Should return expected locations", 2, locations.size());
188-
assertTrue("Should contain rack1", locations.contains("rack1"));
189-
assertTrue("Should contain rack2", locations.contains("rack2"));
187+
assertEquals(2, locations.size(), "Should return expected locations");
188+
assertTrue(locations.contains("rack1"), "Should contain rack1");
189+
assertTrue(locations.contains("rack2"), "Should contain rack2");
190190
}
191191

192192
@Test
193-
public void testInputSplitWithFileLocationResolver() {
193+
public void testInputSplitWithFileLocationResolver() throws Exception {
194194
List<Pair<SnapshotFileInfo, Long>> files = new ArrayList<>();
195195
for (long i = 0; i < 3; i++) {
196196
SnapshotFileInfo fileInfo = SnapshotFileInfo.newBuilder().setType(SnapshotFileInfo.Type.HFILE)
@@ -202,26 +202,22 @@ public void testInputSplitWithFileLocationResolver() {
202202
ExportSnapshot.ExportSnapshotInputFormat.ExportSnapshotInputSplit split =
203203
new ExportSnapshot.ExportSnapshotInputFormat.ExportSnapshotInputSplit(files, resolver);
204204

205-
try {
206-
String[] locations = split.getLocations();
207-
assertEquals("Should return 2 locations", 2, locations.length);
205+
String[] locations = split.getLocations();
206+
assertEquals(2, locations.length, "Should return 2 locations");
208207

209-
boolean hasRack1 = false;
210-
boolean hasRack2 = false;
211-
for (String location : locations) {
212-
if ("rack1".equals(location)) {
213-
hasRack1 = true;
214-
}
215-
if ("rack2".equals(location)) {
216-
hasRack2 = true;
217-
}
208+
boolean hasRack1 = false;
209+
boolean hasRack2 = false;
210+
for (String location : locations) {
211+
if ("rack1".equals(location)) {
212+
hasRack1 = true;
213+
}
214+
if ("rack2".equals(location)) {
215+
hasRack2 = true;
218216
}
219-
220-
assertTrue("Should contain rack1", hasRack1);
221-
assertTrue("Should contain rack2", hasRack2);
222-
} catch (Exception e) {
223-
throw new RuntimeException("Failed to get locations", e);
224217
}
218+
219+
assertTrue(hasRack1, "Should contain rack1");
220+
assertTrue(hasRack2, "Should contain rack2");
225221
}
226222

227223
public static class TestCustomFileGrouper implements ExportSnapshot.CustomFileGrouper {

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshotV1NoCluster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import java.io.IOException;
2323
import java.util.HashSet;
@@ -63,7 +63,7 @@ public void setUpBefore() throws Exception {
6363
this.testDir = setup(fs, this.testUtil);
6464
LOG.info("fs={}, fsuri={}, fswd={}, testDir={}", this.fs, this.fs.getUri(),
6565
this.fs.getWorkingDirectory(), this.testDir);
66-
assertTrue("FileSystem '" + fs + "' is not local", fs instanceof LocalFileSystem);
66+
assertTrue(fs instanceof LocalFileSystem, "FileSystem '" + fs + "' is not local");
6767
}
6868

6969
/**

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/snapshot/TestExportSnapshotV2NoCluster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.snapshot;
1919

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import org.apache.hadoop.fs.FileSystem;
2323
import org.apache.hadoop.fs.LocalFileSystem;
@@ -51,7 +51,7 @@ public void before() throws Exception {
5151
this.fs = FileSystem.getLocal(this.testUtil.getConfiguration());
5252
this.testDir = TestExportSnapshotV1NoCluster.setup(this.fs, this.testUtil);
5353
LOG.info("fs={}, testDir={}", this.fs, this.testDir);
54-
assertTrue("FileSystem '" + fs + "' is not local", fs instanceof LocalFileSystem);
54+
assertTrue(fs instanceof LocalFileSystem, "FileSystem '" + fs + "' is not local");
5555
}
5656

5757
@Test

0 commit comments

Comments
 (0)