1414class APICallTest {
1515
1616 private ApiCall apiCall ;
17+ private Node nearestNode ;
1718
18- @ BeforeEach
19- void setUp () throws Exception {
19+ void setUpNoNearestNode () throws Exception {
2020 List <Node > nodes = new ArrayList <>();
2121 nodes .add (new Node ("http" ,"localhost" ,"8108" ));
2222 nodes .add (new Node ("http" ,"localhost" ,"7108" ));
23- nodes .add (new Node ("http" ,"localhost" ,"6108 " ));
23+ nodes .add (new Node ("http" ,"localhost" ,"2108 " ));
2424 apiCall = new ApiCall (new Configuration (nodes , Duration .ofSeconds (3 ),"xyz" ));
2525 }
2626
27+ void setUpNearestNode () throws Exception {
28+ List <Node > nodes = new ArrayList <>();
29+ nodes .add (new Node ("http" ,"localhost" ,"8108" ));
30+ nodes .add (new Node ("http" ,"localhost" ,"7108" ));
31+ nodes .add (new Node ("http" ,"localhost" ,"6108" ));
32+ nearestNode = new Node ("http" ,"localhost" ,"0000" );
33+ apiCall = new ApiCall (new Configuration (nearestNode , nodes , Duration .ofSeconds (3 ),"xyz" ));
34+ }
35+
2736 @ AfterEach
2837 void tearDown () throws Exception {
2938
3039 }
3140
3241 @ Test
3342 void testRoundRobin () throws Exception {
43+ setUpNoNearestNode ();
3444 assertEquals ("7108" , apiCall .getNode ().port );
3545 assertEquals ("6108" , apiCall .getNode ().port );
3646 assertEquals ("8108" , apiCall .getNode ().port );
@@ -39,4 +49,28 @@ void testRoundRobin() throws Exception {
3949 assertEquals ("6108" , apiCall .getNode ().port );
4050 assertEquals ("8108" , apiCall .getNode ().port );
4151 }
52+
53+
54+ @ Test
55+ void testUnhealthyNearestNode () throws Exception {
56+ setUpNearestNode ();
57+ nearestNode .isHealthy = false ;
58+ assertEquals ("7108" , apiCall .getNode ().port );
59+ }
60+
61+ @ Test
62+ void testHealthyNearestNode () throws Exception {
63+ setUpNearestNode ();
64+ assertEquals ("0000" , apiCall .getNode ().port );
65+ }
66+
67+ @ Test
68+ void testUnhealthyNearestNodeDueForHealthCheck () throws Exception {
69+ setUpNearestNode ();
70+ nearestNode .isHealthy = false ;
71+ nearestNode .lastAccessTimestamp = nearestNode .lastAccessTimestamp .minusSeconds (63 );
72+ assertEquals ("0000" , apiCall .getNode ().port );
73+ }
74+
75+
4276}
0 commit comments