1414import java .util .List ;
1515
1616public class TestMultiHost {
17- private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8000 ,localhost:8002,localhost:8003/default" ;
18- private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8000 ,localhost:8002,localhost:8003/default?load_balancing_policy=random" ;
19- private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8000 ,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin" ;
20- private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8000 /default?load_balancing_policy=round_robin&max_failover_retry=4" ;
21- private final String AUTO_DISCOVERY_JDBC_URL = "jdbc:databend://localhost:8000 /default?load_balancing_policy=round_robin&auto_discovery=true" ;
22- private final String UNSUPPORT_AUTO_DISCOVERY_JDBC_URL = "jdbc:databend://localhost:8000 /default?load_balancing_policy=round_robin&auto_discovery=true&enable_mock=true" ;
17+ private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8001 ,localhost:8002,localhost:8003/default" ;
18+ private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8001 ,localhost:8002,localhost:8003/default?load_balancing_policy=random" ;
19+ private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8001 ,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin" ;
20+ private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8001 /default?load_balancing_policy=round_robin&max_failover_retry=4" ;
21+ private final String AUTO_DISCOVERY_JDBC_URL = "jdbc:databend://localhost:8001 /default?load_balancing_policy=round_robin&auto_discovery=true" ;
22+ private final String UNSUPPORT_AUTO_DISCOVERY_JDBC_URL = "jdbc:databend://localhost:8001 /default?load_balancing_policy=round_robin&auto_discovery=true&enable_mock=true" ;
2323
2424
2525 private Connection createConnection (String url )
@@ -31,7 +31,7 @@ private Connection createConnection(String url)
3131 public void testDefaultLoadBalancing ()
3232 throws SQLException {
3333 // try to connect with three nodes 1000 times and count for each node
34- int node8000 = 0 ;
34+ int node8001 = 0 ;
3535 int node8002 = 0 ;
3636 int node8003 = 0 ;
3737 int unknown = 0 ;
@@ -41,8 +41,9 @@ public void testDefaultLoadBalancing()
4141 statement .execute ("select value from system.configs where name = 'http_handler_port';" );
4242 ResultSet r = statement .getResultSet ();
4343 r .next ();
44- if (r .getInt (1 ) == 8000 ) {
45- node8000 ++;
44+
45+ if (r .getInt (1 ) == 8001 ) {
46+ node8001 ++;
4647 } else if (r .getInt (1 ) == 8002 ) {
4748 node8002 ++;
4849 } else if (r .getInt (1 ) == 8003 ) {
@@ -52,7 +53,7 @@ public void testDefaultLoadBalancing()
5253 }
5354 }
5455 }
55- Assert .assertEquals (node8000 , 100 );
56+ Assert .assertEquals (node8001 , 100 );
5657 Assert .assertEquals (node8002 , 0 );
5758 Assert .assertEquals (node8003 , 0 );
5859 Assert .assertEquals (unknown , 0 );
@@ -62,7 +63,7 @@ public void testDefaultLoadBalancing()
6263 public void testRandomLoadBalancing ()
6364 throws SQLException {
6465 // try to connect with three nodes 1000 times and count for each node
65- int node8000 = 0 ;
66+ int node8001 = 0 ;
6667 int node8002 = 0 ;
6768 int node8003 = 0 ;
6869 int unknown = 0 ;
@@ -72,8 +73,8 @@ public void testRandomLoadBalancing()
7273 statement .execute ("select value from system.configs where name = 'http_handler_port';" );
7374 ResultSet r = statement .getResultSet ();
7475 r .next ();
75- if (r .getInt (1 ) == 8000 ) {
76- node8000 ++;
76+ if (r .getInt (1 ) == 8001 ) {
77+ node8001 ++;
7778 } else if (r .getInt (1 ) == 8002 ) {
7879 node8002 ++;
7980 } else if (r .getInt (1 ) == 8003 ) {
@@ -83,16 +84,16 @@ public void testRandomLoadBalancing()
8384 }
8485 }
8586 }
86- Assert .assertTrue (node8000 > 0 && node8002 > 0 && node8003 > 0 );
87+ Assert .assertTrue (node8001 > 0 && node8002 > 0 && node8003 > 0 );
8788 Assert .assertEquals (unknown , 0 );
88- Assert .assertEquals (node8000 + node8002 + node8003 , 100 );
89+ Assert .assertEquals (node8001 + node8002 + node8003 , 100 );
8990 }
9091
9192 @ Test (groups = {"IT" , "MULTI_HOST" })
9293 public void testRoundRobinLoadBalancing ()
9394 throws SQLException {
9495 // try to connect with three nodes 1000 times and count for each node
95- int node8000 = 0 ;
96+ int node8001 = 0 ;
9697 int node8002 = 0 ;
9798 int node8003 = 0 ;
9899 int unknown = 0 ;
@@ -104,8 +105,8 @@ public void testRoundRobinLoadBalancing()
104105 statement .execute ("select value from system.configs where name = 'http_handler_port';" );
105106 ResultSet r = statement .getResultSet ();
106107 r .next ();
107- if (r .getInt (1 ) == 8000 ) {
108- node8000 ++;
108+ if (r .getInt (1 ) == 8001 ) {
109+ node8001 ++;
109110 } else if (r .getInt (1 ) == 8002 ) {
110111 node8002 ++;
111112 } else if (r .getInt (1 ) == 8003 ) {
@@ -116,11 +117,11 @@ public void testRoundRobinLoadBalancing()
116117 }
117118 }
118119 }
119- Assert .assertEquals (node8000 , 30 );
120+ Assert .assertEquals (node8001 , 30 );
120121 Assert .assertEquals (node8002 , 30 );
121122 Assert .assertEquals (node8003 , 30 );
122123 Assert .assertEquals (unknown , 0 );
123- Assert .assertEquals (node8000 + node8002 + node8003 , 90 );
124+ Assert .assertEquals (node8001 + node8002 + node8003 , 90 );
124125 }
125126
126127 @ Test (groups = {"IT" , "MULTI_HOST" })
@@ -161,7 +162,7 @@ public void testRoundRobinTransaction()
161162 public void testFailOver ()
162163 throws SQLException {
163164 // try connect with three nodes 1000 times and count for each node
164- int node8000 = 0 ;
165+ int node8001 = 0 ;
165166 int node8002 = 0 ;
166167 int node8003 = 0 ;
167168 int unknown = 0 ;
@@ -173,8 +174,8 @@ public void testFailOver()
173174 statement .execute ("select value from system.configs where name = 'http_handler_port';" );
174175 ResultSet r = statement .getResultSet ();
175176 r .next ();
176- if (r .getInt (1 ) == 8000 ) {
177- node8000 ++;
177+ if (r .getInt (1 ) == 8001 ) {
178+ node8001 ++;
178179 } else if (r .getInt (1 ) == 8002 ) {
179180 node8002 ++;
180181 } else if (r .getInt (1 ) == 8003 ) {
@@ -186,16 +187,16 @@ public void testFailOver()
186187 }
187188 }
188189
189- Assert .assertEquals (node8000 , 90 );
190+ Assert .assertEquals (node8001 , 90 );
190191 Assert .assertEquals (unknown , 0 );
191- Assert .assertEquals (node8000 + node8002 + node8003 , 90 );
192+ Assert .assertEquals (node8001 + node8002 + node8003 , 90 );
192193 }
193194
194195 @ Test (groups = {"IT" , "MULTI_HOST" })
195196 public void testAutoDiscovery ()
196197 throws SQLException {
197198 // try connect with three nodes 1000 times and count for each node
198- int node8000 = 0 ;
199+ int node8001 = 0 ;
199200 int node8002 = 0 ;
200201 int node8003 = 0 ;
201202 int unknown = 0 ;
@@ -207,8 +208,8 @@ public void testAutoDiscovery()
207208 statement .execute ("select value from system.configs where name = 'http_handler_port';" );
208209 ResultSet r = statement .getResultSet ();
209210 r .next ();
210- if (r .getInt (1 ) == 8000 ) {
211- node8000 ++;
211+ if (r .getInt (1 ) == 8001 ) {
212+ node8001 ++;
212213 } else if (r .getInt (1 ) == 8002 ) {
213214 node8002 ++;
214215 } else if (r .getInt (1 ) == 8003 ) {
@@ -220,11 +221,11 @@ public void testAutoDiscovery()
220221 }
221222 }
222223
223- Assert .assertEquals (node8000 , 31 );
224+ Assert .assertEquals (node8001 , 31 );
224225 Assert .assertEquals (node8002 , 30 );
225226 Assert .assertEquals (node8003 , 29 );
226227 Assert .assertEquals (unknown , 0 );
227- Assert .assertEquals (node8000 + node8002 + node8003 , 90 );
228+ Assert .assertEquals (node8001 + node8002 + node8003 , 90 );
228229 }
229230
230231 @ Test (groups = {"IT" , "MULTI_HOST" })
@@ -247,13 +248,13 @@ public void testUnSupportedAutoDiscovery()
247248
248249 @ Test (groups = {"UNIT" })
249250 public void testAutoDiscoveryUriParsing () throws SQLException {
250- DatabendDriverUri uri = DatabendDriverUri .create ("jdbc:databend://localhost:8000 ?ssl=true" , null );
251- DatabendDriverUri uri2 = DatabendDriverUri .create ("jdbc:databend://127.0.0.1:8000 ,127.0.0.1:8002,127.0.0.1:8003?ssl=true" , null );
251+ DatabendDriverUri uri = DatabendDriverUri .create ("jdbc:databend://localhost:8001 ?ssl=true" , null );
252+ DatabendDriverUri uri2 = DatabendDriverUri .create ("jdbc:databend://127.0.0.1:8001 ,127.0.0.1:8002,127.0.0.1:8003?ssl=true" , null );
252253 List <URI > uris2 = uri2 .getNodes ().getUris ();
253254
254255 DatabendNodes nodes = uri .getNodes ();
255256 List <DiscoveryNode > discoveryNodes = new ArrayList <>();
256- discoveryNodes .add (DiscoveryNode .create ("127.0.0.1:8000 " ));
257+ discoveryNodes .add (DiscoveryNode .create ("127.0.0.1:8001 " ));
257258 discoveryNodes .add (DiscoveryNode .create ("127.0.0.1:8002" ));
258259 discoveryNodes .add (DiscoveryNode .create ("127.0.0.1:8003" ));
259260 List <URI > uris = nodes .parseURI (discoveryNodes );
0 commit comments