hemantk-12 commented on code in PR #5910:
URL: https://github.com/apache/ozone/pull/5910#discussion_r1442353424
##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/scm/net/TestNetworkTopologyImpl.java:
##########
@@ -311,57 +311,49 @@ public void testAddRemove(NodeSchema[] schemas, Node[]
nodeArray) {
cluster.add(dataNodes[i]);
}
// Inner nodes are created automatically
- assertTrue(cluster.getNumOfNodes(2) > 0);
+ assertThat(cluster.getNumOfNodes(2)).isPositive();
- try {
- cluster.add(cluster.chooseRandom(null).getParent());
- fail("Inner node can not be added manually");
- } catch (Exception e) {
- assertTrue(e.getMessage().startsWith(
- "Not allowed to add an inner node"));
- }
+ Exception e = assertThrows(Exception.class,
+ () -> cluster.add(cluster.chooseRandom(null).getParent()));
+ assertThat(e).hasMessageStartingWith("Not allowed to add an inner node");
- try {
- cluster.remove(cluster.chooseRandom(null).getParent());
- fail("Inner node can not be removed manually");
- } catch (Exception e) {
- assertTrue(e.getMessage().startsWith(
- "Not allowed to remove an inner node"));
- }
+ Exception e2 = assertThrows(Exception.class,
+ () -> cluster.remove(cluster.chooseRandom(null).getParent()));
+ assertThat(e2).hasMessageStartingWith("Not allowed to remove an inner
node");
}
@ParameterizedTest
@MethodSource("topologies")
- public void testGetNumOfNodesWithLevel(NodeSchema[] schemas,
+ void testGetNumOfNodesWithLevel(NodeSchema[] schemas,
Node[] nodeArray) {
initNetworkTopology(schemas, nodeArray);
int maxLevel = cluster.getMaxLevel();
try {
Review Comment:
nit: we can use assertThrow() here and other palces.
```suggestion
IllegalArgumentException ex =
assertThrows(IllegalArgumentException.class, () -> cluster.getNumOfNodes(0));
Assertions.assertThat(ex).hasMessageStartingWith("Invalid level");
```
##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/scm/net/TestNetworkTopologyImpl.java:
##########
@@ -311,57 +311,49 @@ public void testAddRemove(NodeSchema[] schemas, Node[]
nodeArray) {
cluster.add(dataNodes[i]);
}
// Inner nodes are created automatically
- assertTrue(cluster.getNumOfNodes(2) > 0);
+ assertThat(cluster.getNumOfNodes(2)).isPositive();
- try {
- cluster.add(cluster.chooseRandom(null).getParent());
- fail("Inner node can not be added manually");
- } catch (Exception e) {
- assertTrue(e.getMessage().startsWith(
- "Not allowed to add an inner node"));
- }
+ Exception e = assertThrows(Exception.class,
+ () -> cluster.add(cluster.chooseRandom(null).getParent()));
+ assertThat(e).hasMessageStartingWith("Not allowed to add an inner node");
- try {
- cluster.remove(cluster.chooseRandom(null).getParent());
- fail("Inner node can not be removed manually");
- } catch (Exception e) {
- assertTrue(e.getMessage().startsWith(
- "Not allowed to remove an inner node"));
- }
+ Exception e2 = assertThrows(Exception.class,
+ () -> cluster.remove(cluster.chooseRandom(null).getParent()));
+ assertThat(e2).hasMessageStartingWith("Not allowed to remove an inner
node");
}
@ParameterizedTest
@MethodSource("topologies")
- public void testGetNumOfNodesWithLevel(NodeSchema[] schemas,
+ void testGetNumOfNodesWithLevel(NodeSchema[] schemas,
Node[] nodeArray) {
initNetworkTopology(schemas, nodeArray);
int maxLevel = cluster.getMaxLevel();
try {
assertEquals(1, cluster.getNumOfNodes(0));
fail("level 0 is not supported");
} catch (IllegalArgumentException e) {
- assertTrue(e.getMessage().startsWith("Invalid level"));
+ assertThat(e).hasMessageStartingWith("Invalid level");
}
try {
Review Comment:
Why do we have two same assertions? Lines 331-336 are same as lines 338-343.
Similarly, lines 345-350 are same as 352-357.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]