This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 4095ef1f48 HDDS-10278. Simplify tests using assertDoesNotThrow (#6291)
4095ef1f48 is described below
commit 4095ef1f481f716d5b3ecc57424fe332ffda4420
Author: Zhaohui Wang <[email protected]>
AuthorDate: Wed Feb 28 22:39:08 2024 +0800
HDDS-10278. Simplify tests using assertDoesNotThrow (#6291)
---
.../replication/TestReplicationSupervisor.java | 16 ++++---------
.../hadoop/hdds/utils/db/TestRDBTableStore.java | 8 ++-----
.../hdds/utils/db/TestTypedRDBTableStore.java | 8 ++-----
.../ozone/TestDirectoryDeletingServiceWithFSO.java | 25 +++++++++----------
.../hadoop/fs/ozone/TestRootedDDSWithFSO.java | 25 ++++++++-----------
.../hadoop/ozone/TestSecureOzoneCluster.java | 22 ++++-------------
.../apache/hadoop/ozone/om/TestScmSafeMode.java | 7 +-----
.../ozone/om/TestSnapshotDeletingService.java | 18 +++++++-------
.../om/TestSnapshotDirectoryCleaningService.java | 25 ++++++++-----------
.../TestReconInsightsForDeletedDirectories.java | 28 ++++++++++------------
.../hadoop/ozone/om/TestAuthorizerLockImpl.java | 9 +++----
...TestOzoneManagerDoubleBufferWithOMResponse.java | 11 ++++-----
.../volume/TestOMVolumeDeleteResponse.java | 15 +++---------
.../ozone/om/service/TestKeyDeletingService.java | 17 +++++++------
.../hadoop/ozone/recon/api/TestEndpoints.java | 7 +++---
.../ozone/recon/api/TestOpenContainerCount.java | 26 +++++++++-----------
16 files changed, 99 insertions(+), 168 deletions(-)
diff --git
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestReplicationSupervisor.java
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestReplicationSupervisor.java
index 26c6853b64..f42d6afd68 100644
---
a/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestReplicationSupervisor.java
+++
b/hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/replication/TestReplicationSupervisor.java
@@ -79,8 +79,8 @@ import static
org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalSt
import static
org.apache.hadoop.ozone.container.replication.AbstractReplicationTask.Status.DONE;
import static
org.apache.hadoop.ozone.protocol.commands.ReplicateContainerCommand.fromSources;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
import static
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ReplicationCommandPriority.LOW;
import static
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ReplicationCommandPriority.NORMAL;
import static org.mockito.Mockito.any;
@@ -478,11 +478,8 @@ public class TestReplicationSupervisor {
@Override
public void runTask() {
runningLatch.countDown();
- try {
- waitForCompleteLatch.await();
- } catch (InterruptedException e) {
- fail("Interrupted waiting for the completion latch to be released");
- }
+ assertDoesNotThrow(() -> waitForCompleteLatch.await(),
+ "Interrupted waiting for the completion latch to be released");
setStatus(DONE);
}
}
@@ -607,13 +604,10 @@ public class TestReplicationSupervisor {
UUID.randomUUID().toString(), UUID.randomUUID().toString());
KeyValueContainer kvc =
new KeyValueContainer(kvcd, conf);
-
- try {
+ assertDoesNotThrow(() -> {
set.addContainer(kvc);
task.setStatus(DONE);
- } catch (Exception e) {
- fail("Unexpected error: " + e.getMessage());
- }
+ });
}
}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
index 504c3dd47f..8095c1cbb1 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBTableStore.java
@@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -55,7 +56,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests for RocksDBTable Store.
@@ -96,11 +96,7 @@ public class TestRDBTableStore {
private static boolean consume(Table.KeyValue keyValue) {
count++;
- try {
- assertNotNull(keyValue.getKey());
- } catch (IOException ex) {
- fail("Unexpected Exception " + ex);
- }
+ assertNotNull(assertDoesNotThrow(keyValue::getKey));
return true;
}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestTypedRDBTableStore.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestTypedRDBTableStore.java
index 9e16ebb99e..f437d6518c 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestTypedRDBTableStore.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestTypedRDBTableStore.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.hdds.utils.db;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -29,7 +30,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
@@ -217,11 +217,7 @@ public class TestTypedRDBTableStore {
private static boolean consume(Table.KeyValue keyValue) {
count++;
- try {
- assertNotNull(keyValue.getKey());
- } catch (IOException ex) {
- fail(ex.toString());
- }
+ assertNotNull(assertDoesNotThrow(keyValue::getKey));
return true;
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDirectoryDeletingServiceWithFSO.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDirectoryDeletingServiceWithFSO.java
index 87f114bd71..382f4b7203 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDirectoryDeletingServiceWithFSO.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestDirectoryDeletingServiceWithFSO.java
@@ -55,13 +55,14 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.function.LongSupplier;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
@@ -126,15 +127,13 @@ public class TestDirectoryDeletingServiceWithFSO {
@AfterEach
public void cleanup() {
- try {
+ assertDoesNotThrow(() -> {
Path root = new Path("/");
FileStatus[] fileStatuses = fs.listStatus(root);
for (FileStatus fileStatus : fileStatuses) {
fs.delete(fileStatus.getPath(), true);
}
- } catch (IOException ex) {
- fail("Failed to cleanup files.");
- }
+ });
}
@Test
@@ -534,16 +533,14 @@ public class TestDirectoryDeletingServiceWithFSO {
private boolean assertTableRowCount(int expectedCount,
Table<String, ?> table) {
- long count = 0L;
- try {
- count = cluster.getOzoneManager().getMetadataManager()
- .countRowsInTable(table);
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
+
count.set(cluster.getOzoneManager().getMetadataManager().countRowsInTable(table));
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+
+ return count.get() == expectedCount;
}
private void checkPath(Path path) {
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedDDSWithFSO.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedDDSWithFSO.java
index 074a8e7df4..de3358685e 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedDDSWithFSO.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedDDSWithFSO.java
@@ -47,9 +47,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
-import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import static
org.apache.hadoop.fs.ozone.TestDirectoryDeletingServiceWithFSO.assertSubPathsCount;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
@@ -58,10 +58,10 @@ import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZ
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Directory deletion service test cases using rooted ozone filesystem
@@ -128,15 +128,13 @@ public class TestRootedDDSWithFSO {
@AfterEach
public void cleanup() {
- try {
+ assertDoesNotThrow(() -> {
Path root = new Path("/");
FileStatus[] fileStatuses = fs.listStatus(root);
for (FileStatus fileStatus : fileStatuses) {
fs.delete(fileStatus.getPath(), false);
}
- } catch (IOException ex) {
- fail("Failed to cleanup files.");
- }
+ });
}
@Test
@@ -227,16 +225,13 @@ public class TestRootedDDSWithFSO {
private boolean assertTableRowCount(int expectedCount,
Table<String, ?> table) {
- long count = 0L;
- try {
- count = cluster.getOzoneManager().getMetadataManager()
- .countRowsInTable(table);
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
+
count.set(cluster.getOzoneManager().getMetadataManager().countRowsInTable(table));
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+ return count.get() == expectedCount;
}
private static BucketLayout getFSOBucketLayout() {
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestSecureOzoneCluster.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestSecureOzoneCluster.java
index 1be5b64ac8..bc49d176da 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestSecureOzoneCluster.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestSecureOzoneCluster.java
@@ -179,7 +179,6 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
@@ -1346,27 +1345,16 @@ final class TestSecureOzoneCluster {
}
// get new client, it should succeed.
- try {
- OzoneClient client1 = OzoneClientFactory.getRpcClient(conf);
- client1.close();
- } catch (Exception e) {
- System.out.println("OzoneClientFactory.getRpcClient failed for " +
- e.getMessage());
- fail("Create client should succeed for certificate is renewed");
- }
+ OzoneClient client1 = OzoneClientFactory.getRpcClient(conf);
+ client1.close();
+
// Wait for old OM certificate to expire
GenericTestUtils.waitFor(() -> omCert.getNotAfter().before(new Date()),
500, certLifetime * 1000);
// get new client, it should succeed too.
- try {
- OzoneClient client1 = OzoneClientFactory.getRpcClient(conf);
- client1.close();
- } catch (Exception e) {
- System.out.println("OzoneClientFactory.getRpcClient failed for " +
- e.getMessage());
- fail("Create client should succeed for certificate is renewed");
- }
+ OzoneClient client2 = OzoneClientFactory.getRpcClient(conf);
+ client2.close();
} finally {
OzoneManager.setUgi(null);
GrpcOmTransport.setCaCerts(null);
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestScmSafeMode.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestScmSafeMode.java
index d5c2c64c20..427d3bf8a4 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestScmSafeMode.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestScmSafeMode.java
@@ -349,12 +349,7 @@ public class TestScmSafeMode {
public void testCreateRetryWhileSCMSafeMode() throws Exception {
// Test1: Test safe mode when there are no containers in system.
cluster.stop();
-
- try {
- cluster = builder.build();
- } catch (IOException e) {
- fail("Cluster startup failed.");
- }
+ cluster = builder.build();
final String rootPath = String.format("%s://%s/",
OZONE_OFS_URI_SCHEME, conf.get(OZONE_OM_ADDRESS_KEY));
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDeletingService.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDeletingService.java
index 9f697d4148..d4bf911676 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDeletingService.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDeletingService.java
@@ -53,14 +53,15 @@ import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import static
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CHUNK_SIZE_KEY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_TIMEOUT;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Test Snapshot Deleting Service.
@@ -553,15 +554,12 @@ public class TestSnapshotDeletingService {
private boolean assertTableRowCount(int expectedCount,
Table<String, ?> table) {
- long count = 0L;
- try {
- count = cluster.getOzoneManager().getMetadataManager()
- .countRowsInTable(table);
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
+
count.set(cluster.getOzoneManager().getMetadataManager().countRowsInTable(table));
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+ return count.get() == expectedCount;
}
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDirectoryCleaningService.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDirectoryCleaningService.java
index 6b39b76c54..893e248d88 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDirectoryCleaningService.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestSnapshotDirectoryCleaningService.java
@@ -46,17 +46,17 @@ import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZE;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Test Snapshot Directory Service.
@@ -114,15 +114,13 @@ public class TestSnapshotDirectoryCleaningService {
@AfterEach
public void cleanup() {
- try {
+ assertDoesNotThrow(() -> {
Path root = new Path("/");
FileStatus[] fileStatuses = fs.listStatus(root);
for (FileStatus fileStatus : fileStatuses) {
fs.delete(fileStatus.getPath(), true);
}
- } catch (IOException ex) {
- fail("Failed to cleanup files.");
- }
+ });
}
@SuppressWarnings("checkstyle:LineLength")
@@ -258,15 +256,12 @@ public class TestSnapshotDirectoryCleaningService {
private boolean assertTableRowCount(int expectedCount,
Table<String, ?> table) {
- long count = 0L;
- try {
- count = cluster.getOzoneManager().getMetadataManager()
- .countRowsInTable(table);
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
+
count.set(cluster.getOzoneManager().getMetadataManager().countRowsInTable(table));
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+ return count.get() == expectedCount;
}
}
diff --git
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconInsightsForDeletedDirectories.java
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconInsightsForDeletedDirectories.java
index 4c059be1b5..ca8fcae664 100644
---
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconInsightsForDeletedDirectories.java
+++
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/recon/TestReconInsightsForDeletedDirectories.java
@@ -54,6 +54,7 @@ import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicLong;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
@@ -61,6 +62,7 @@ import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_ITERATE_BATCH_SIZ
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_DIR_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_PATH_DELETING_LIMIT_PER_TASK;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_RATIS_ENABLE_KEY;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
@@ -127,15 +129,13 @@ public class TestReconInsightsForDeletedDirectories {
@AfterEach
public void cleanup() {
- try {
+ assertDoesNotThrow(() -> {
Path root = new Path("/");
FileStatus[] fileStatuses = fs.listStatus(root);
for (FileStatus fileStatus : fileStatuses) {
fs.delete(fileStatus.getPath(), true);
}
- } catch (IOException ex) {
- fail("Failed to cleanup files.");
- }
+ });
}
/**
@@ -461,21 +461,19 @@ public class TestReconInsightsForDeletedDirectories {
private boolean assertTableRowCount(int expectedCount,
Table<String, ?> table, boolean isRecon)
{
- long count = 0L;
- try {
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
if (isRecon) {
- count = cluster.getReconServer().getOzoneManagerServiceProvider()
- .getOMMetadataManagerInstance().countRowsInTable(table);
+ count.set(cluster.getReconServer().getOzoneManagerServiceProvider()
+ .getOMMetadataManagerInstance().countRowsInTable(table));
} else {
- count = cluster.getOzoneManager().getMetadataManager()
- .countRowsInTable(table);
+ count.set(cluster.getOzoneManager().getMetadataManager()
+ .countRowsInTable(table));
}
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("Test failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+ return count.get() == expectedCount;
}
private void syncDataFromOM() {
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java
index b78864e301..f600158007 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestAuthorizerLockImpl.java
@@ -18,11 +18,11 @@
package org.apache.hadoop.ozone.om;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
import org.apache.hadoop.ozone.om.multitenant.AuthorizerLock;
import org.apache.hadoop.ozone.om.multitenant.AuthorizerLockImpl;
import org.apache.ozone.test.GenericTestUtils;
@@ -103,17 +103,14 @@ public class TestAuthorizerLockImpl {
public void testLockInOneThreadUnlockInAnother() {
final AuthorizerLock authorizerLock = new AuthorizerLockImpl();
-
- try {
+ assertDoesNotThrow(() -> {
authorizerLock.tryWriteLockInOMRequest();
// Spawn another thread to release the lock.
// Works as long as they share the same AuthorizerLockImpl instance.
final Thread thread1 = new
Thread(authorizerLock::unlockWriteInOMRequest);
thread1.start();
- } catch (IOException e) {
- fail("Should not have thrown: " + e.getMessage());
- }
+ });
}
@Test
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
index a97b24289c..d0e814a782 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerDoubleBufferWithOMResponse.java
@@ -64,6 +64,7 @@ import org.apache.hadoop.util.Daemon;
import static org.apache.hadoop.ozone.OzoneConsts.TRANSACTION_INFO_KEY;
import static
org.apache.hadoop.ozone.om.request.OMRequestTestUtils.newBucketInfoBuilder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -416,13 +417,9 @@ public class TestOzoneManagerDoubleBufferWithOMResponse {
}
private boolean assertRowCount(int expected, Table<String, ?> table) {
- long count = 0L;
- try {
- count = omMetadataManager.countRowsInTable(table);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expected;
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() ->
count.set(omMetadataManager.countRowsInTable(table)));
+ return count.get() == expected;
}
/**
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/volume/TestOMVolumeDeleteResponse.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/volume/TestOMVolumeDeleteResponse.java
index 9ae0a395e9..70dd23a7b0 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/volume/TestOMVolumeDeleteResponse.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/response/volume/TestOMVolumeDeleteResponse.java
@@ -36,12 +36,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
-import java.io.IOException;
import java.util.UUID;
import java.nio.file.Path;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* This class tests OMVolumeCreateResponse.
@@ -115,7 +114,7 @@ public class TestOMVolumeDeleteResponse {
}
@Test
- public void testAddToDBBatchNoOp() throws Exception {
+ public void testAddToDBBatchNoOp() {
OMResponse omResponse = OMResponse.newBuilder()
.setCmdType(OzoneManagerProtocolProtos.Type.DeleteVolume)
@@ -126,15 +125,7 @@ public class TestOMVolumeDeleteResponse {
OMVolumeDeleteResponse omVolumeDeleteResponse = new OMVolumeDeleteResponse(
omResponse);
-
- try {
- omVolumeDeleteResponse.checkAndUpdateDB(omMetadataManager,
- batchOperation);
- } catch (IOException ex) {
- fail("testAddToDBBatchFailure failed");
- }
-
+ assertDoesNotThrow(() ->
omVolumeDeleteResponse.checkAndUpdateDB(omMetadataManager, batchOperation));
}
-
}
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java
index d745a01e62..c5099fc759 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java
@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import com.google.common.collect.ImmutableMap;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
@@ -81,10 +82,10 @@ import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVI
import static
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
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.fail;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
@@ -626,15 +627,13 @@ class TestKeyDeletingService extends OzoneTestBase {
private static boolean assertTableRowCount(long expectedCount,
Table<String, ?> table,
OMMetadataManager metadataManager) {
- long count = 0L;
- try {
- count = metadataManager.countRowsInTable(table);
+ AtomicLong count = new AtomicLong(0L);
+ assertDoesNotThrow(() -> {
+ count.set(metadataManager.countRowsInTable(table));
LOG.info("{} actual row count={}, expectedCount={}", table.getName(),
- count, expectedCount);
- } catch (IOException ex) {
- fail("testDoubleBuffer failed with: " + ex);
- }
- return count == expectedCount;
+ count.get(), expectedCount);
+ });
+ return count.get() == expectedCount;
}
private void createVolumeAndBucket(String volumeName,
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java
index f7deaddd4f..9c92ad4d7e 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java
@@ -113,6 +113,7 @@ import static
org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.writeDele
import static
org.apache.hadoop.ozone.recon.spi.impl.PrometheusServiceProviderImpl.PROMETHEUS_INSTANT_QUERY_API;
import static
org.hadoop.ozone.recon.schema.tables.GlobalStatsTable.GLOBAL_STATS;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -406,7 +407,7 @@ public class TestEndpoints extends AbstractReconSqlDBTest {
.addStorageReport(storageReportProto4).build();
LayoutVersionProto layoutInfo = defaultLayoutVersionProto();
- try {
+ assertDoesNotThrow(() -> {
reconScm.getDatanodeProtocolServer()
.register(extendedDatanodeDetailsProto, nodeReportProto,
containerReportsProto, pipelineReportsProto, layoutInfo);
@@ -417,9 +418,7 @@ public class TestEndpoints extends AbstractReconSqlDBTest {
defaultLayoutVersionProto());
// Process all events in the event queue
reconScm.getEventQueue().processAll(1000);
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
+ });
// Write Data to OM
// A sample volume (sampleVol) and a bucket (bucketOne) is already created
// in AbstractOMMetadataManagerTest.
diff --git
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOpenContainerCount.java
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOpenContainerCount.java
index 8a9452a862..f64d93707a 100644
---
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOpenContainerCount.java
+++
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOpenContainerCount.java
@@ -67,8 +67,8 @@ import static
org.apache.hadoop.ozone.container.upgrade.UpgradeUtils.defaultLayo
import static
org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getRandomPipeline;
import static
org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getTestReconOmMetadataManager;
import static
org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.initializeNewOmMetadataManager;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyBoolean;
import static org.mockito.Mockito.anyString;
@@ -329,16 +329,14 @@ public class TestOpenContainerCount {
.addStorageReport(storageReportProto1)
.addStorageReport(storageReportProto2).build();
- try {
+ assertDoesNotThrow(() -> {
reconScm.getDatanodeProtocolServer()
- .register(extendedDatanodeDetailsProto, nodeReportProto,
- containerReportsProto, pipelineReportsProto,
- defaultLayoutVersionProto());
+ .register(extendedDatanodeDetailsProto, nodeReportProto,
+ containerReportsProto, pipelineReportsProto,
+ defaultLayoutVersionProto());
// Process all events in the event queue
reconScm.getEventQueue().processAll(1000);
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
+ });
}
@Test
@@ -421,16 +419,14 @@ public class TestOpenContainerCount {
.setOriginNodeId(datanodeId)
.build())
.build();
- try {
+ assertDoesNotThrow(() -> {
reconScm.getDatanodeProtocolServer()
- .register(extendedDatanodeDetailsProto, nodeReportProto,
- containerReportsProto, pipelineReportsProto,
- defaultLayoutVersionProto());
+ .register(extendedDatanodeDetailsProto, nodeReportProto,
+ containerReportsProto, pipelineReportsProto,
+ defaultLayoutVersionProto());
// Process all events in the event queue
reconScm.getEventQueue().processAll(1000);
- } catch (Exception ex) {
- fail(ex.getMessage());
- }
+ });
}
private void waitAndCheckConditionAfterHeartbeat(Callable<Boolean> check)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]