1717
1818import java .io .PrintWriter ;
1919import java .io .StringWriter ;
20+ import java .util .Collection ;
2021
2122import org .testng .annotations .AfterClass ;
2223import org .testng .annotations .BeforeClass ;
@@ -41,7 +42,8 @@ private void setup() {
4142
4243 @ Test (groups = "short" )
4344 public void notificationsTest () throws Exception {
44- assertEquals (policy .adds , 2 , "adds\n " + policy .history );
45+ assertEquals (policy .inits , 2 , "inits\n " + policy .history );
46+ assertEquals (policy .adds , 0 , "adds\n " + policy .history );
4547 assertEquals (policy .suspecteds , 0 , "suspecteds\n " + policy .history );
4648 assertEquals (policy .removes , 0 , "removes\n " + policy .history );
4749 assertEquals (policy .ups , 0 , "ups\n " + policy .history );
@@ -55,6 +57,7 @@ private void tearDown() {
5557
5658 static class CountingPolicy extends DelegatingLoadBalancingPolicy {
5759
60+ int inits ;
5861 int adds ;
5962 int suspecteds ;
6063 int removes ;
@@ -68,6 +71,12 @@ public CountingPolicy(LoadBalancingPolicy delegate) {
6871 super (delegate );
6972 }
7073
74+ @ Override
75+ public void init (Cluster cluster , Collection <Host > hosts ) {
76+ super .init (cluster , hosts );
77+ inits += hosts .size ();
78+ }
79+
7180 public void onAdd (Host host ) {
7281 out .printf ("add %s%n" , host );
7382 adds ++;
0 commit comments