26
26
import org .apache .commons .lang3 .tuple .Pair ;
27
27
import org .apache .commons .math3 .stat .inference .ChiSquareTest ;
28
28
import org .apache .hadoop .conf .Configuration ;
29
- import org .junit .Assert ;
30
- import org .junit .Test ;
29
+ import org .junit .jupiter . api . Assertions ;
30
+ import org .junit .jupiter . api . Test ;
31
31
32
- public class TestClusterTopology extends Assert {
32
+ public class TestClusterTopology extends Assertions {
33
33
34
34
public static class NodeElement implements Node {
35
35
private String location ;
@@ -96,34 +96,33 @@ public void testCountNumNodes() throws Exception {
96
96
// create exclude list
97
97
List <Node > excludedNodes = new ArrayList <Node >();
98
98
99
- assertEquals ("4 nodes should be available" , 4 ,
100
- cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) );
99
+ assertEquals (4 , cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) ,
100
+ "4 nodes should be available" );
101
101
NodeElement deadNode = getNewNode ("node5" , "/d1/r2" );
102
102
excludedNodes .add (deadNode );
103
- assertEquals ("4 nodes should be available with extra excluded Node" , 4 ,
104
- cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) );
103
+ assertEquals (4 , cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) ,
104
+ "4 nodes should be available with extra excluded Node" );
105
105
// add one existing node to exclude list
106
106
excludedNodes .add (node4 );
107
- assertEquals ("excluded nodes with ROOT scope should be considered" , 3 ,
108
- cluster .countNumOfAvailableNodes (NodeBase .ROOT , excludedNodes ));
109
- assertEquals ("excluded nodes without ~ scope should be considered" , 2 ,
110
- cluster .countNumOfAvailableNodes ("~" + deadNode .getNetworkLocation (),
111
- excludedNodes ));
112
- assertEquals ("excluded nodes with rack scope should be considered" , 1 ,
113
- cluster .countNumOfAvailableNodes (deadNode .getNetworkLocation (),
114
- excludedNodes ));
107
+ assertEquals (3 , cluster .countNumOfAvailableNodes (NodeBase .ROOT , excludedNodes ),
108
+ "excluded nodes with ROOT scope should be considered" );
109
+ assertEquals (2 ,
110
+ cluster .countNumOfAvailableNodes ("~" + deadNode .getNetworkLocation (), excludedNodes ),
111
+ "excluded nodes without ~ scope should be considered" );
112
+ assertEquals (1 , cluster .countNumOfAvailableNodes (deadNode .getNetworkLocation (),
113
+ excludedNodes ), "excluded nodes with rack scope should be considered" );
115
114
// adding the node in excluded scope to excluded list
116
115
excludedNodes .add (node2 );
117
- assertEquals ("excluded nodes with ~ scope should be considered" , 2 ,
118
- cluster .countNumOfAvailableNodes ("~" + deadNode .getNetworkLocation (),
119
- excludedNodes ) );
116
+ assertEquals (2 ,
117
+ cluster .countNumOfAvailableNodes ("~" + deadNode .getNetworkLocation (), excludedNodes ),
118
+ "excluded nodes with ~ scope should be considered" );
120
119
// getting count with non-exist scope.
121
- assertEquals ("No nodes should be considered for non-exist scope " , 0 ,
122
- cluster . countNumOfAvailableNodes ( "/ non-exist" , excludedNodes ) );
120
+ assertEquals (0 , cluster . countNumOfAvailableNodes ( "/ non-exist" , excludedNodes ) ,
121
+ "No nodes should be considered for non-exist scope" );
123
122
// remove a node from the cluster
124
123
cluster .remove (node1 );
125
- assertEquals ("1 node should be available" , 1 ,
126
- cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) );
124
+ assertEquals (1 , cluster . countNumOfAvailableNodes ( NodeBase . ROOT , excludedNodes ) ,
125
+ "1 node should be available" );
127
126
}
128
127
129
128
/**
@@ -160,7 +159,7 @@ public void testChooseRandom() {
160
159
}
161
160
histogram .put (randomNode , histogram .get (randomNode ) + 1 );
162
161
}
163
- assertEquals ("Random is not selecting all nodes" , 4 , histogram . size () );
162
+ assertEquals (4 , histogram . size (), "Random is not selecting all nodes" );
164
163
165
164
// Check with 99% confidence alpha=0.01 as confidence = 100 * (1 - alpha)
166
165
ChiSquareTest chiSquareTest = new ChiSquareTest ();
@@ -181,8 +180,8 @@ public void testChooseRandom() {
181
180
}
182
181
183
182
// Check that they have the proper distribution
184
- assertFalse ("Random not choosing nodes with proper distribution" ,
185
- chiSquareTestRejectedCounter == 3 );
183
+ assertFalse (chiSquareTestRejectedCounter == 3 ,
184
+ "Random not choosing nodes with proper distribution" );
186
185
187
186
// Pick random nodes excluding the 2 nodes in /d1/r3
188
187
HashMap <String , Integer > histogram = new HashMap <String , Integer >();
@@ -193,8 +192,8 @@ public void testChooseRandom() {
193
192
}
194
193
histogram .put (randomNode , histogram .get (randomNode ) + 1 );
195
194
}
196
- assertEquals ("Random is not selecting the nodes it should" ,
197
- 2 , histogram . size () );
195
+ assertEquals (2 , histogram . size () ,
196
+ "Random is not selecting the nodes it should" );
198
197
199
198
Node val = cluster .chooseRandom ("/d1" , "/d" , Collections .emptyList ());
200
199
assertNotNull (val );
@@ -268,9 +267,10 @@ public void testWeights() {
268
267
for (Pair <Integer , NodeElement > test : new Pair []{Pair .of (0 , node1 ),
269
268
Pair .of (2 , node2 ), Pair .of (4 , node3 )}) {
270
269
int expect = test .getLeft ();
271
- assertEquals (test .toString (), expect , cluster .getWeight (node1 , test .getRight ()));
272
- assertEquals (test .toString (), expect ,
273
- cluster .getWeightUsingNetworkLocation (node1 , test .getRight ()));
270
+ assertEquals (expect , cluster .getWeight (node1 , test .getRight ()),
271
+ test .toString ());
272
+ assertEquals (expect , cluster .getWeightUsingNetworkLocation (node1 , test .getRight ()),
273
+ test .toString ());
274
274
}
275
275
// Reset so that we can have 2 levels
276
276
cluster = NetworkTopology .getInstance (new Configuration ());
@@ -281,9 +281,9 @@ public void testWeights() {
281
281
for (Pair <Integer , NodeElement > test : new Pair []{Pair .of (0 , node5 ),
282
282
Pair .of (2 , node6 ), Pair .of (4 , node7 ), Pair .of (6 , node8 )}) {
283
283
int expect = test .getLeft ();
284
- assertEquals (test . toString (), expect , cluster .getWeight (node5 , test .getRight ()));
285
- assertEquals (test . toString (), expect ,
286
- cluster . getWeightUsingNetworkLocation ( node5 , test .getRight () ));
284
+ assertEquals (expect , cluster .getWeight (node5 , test .getRight ()), test . toString ( ));
285
+ assertEquals (expect , cluster . getWeightUsingNetworkLocation ( node5 , test . getRight ()) ,
286
+ test .toString ( ));
287
287
}
288
288
}
289
289
}
0 commit comments