@@ -536,7 +536,7 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
536
536
@ Test
537
537
public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
538
538
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,false );
539
- Thread .sleep (10000 );
539
+ Thread .sleep (1000 );
540
540
DBConnection connection1 = new DBConnection ();
541
541
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
542
542
connection1 .run ("sleep(3000)" );
@@ -549,7 +549,7 @@ public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false
549
549
@ Test
550
550
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
551
551
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,true );
552
- Thread .sleep (10000 );
552
+ Thread .sleep (1000 );
553
553
DBConnection connection1 = new DBConnection ();
554
554
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
555
555
connection1 .run ("sleep(3000)" );
@@ -643,7 +643,7 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true()
643
643
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
644
644
DBConnection connection1 = new DBConnection ();
645
645
connection1 .connect (HOST , PORT , "admin" , "123456" ,true );
646
- connection1 .run ("sleep(1000 )" );
646
+ connection1 .run ("sleep(2000 )" );
647
647
BasicTable re = (BasicTable ) connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
648
648
for (int i = 0 ; i < re .rows (); i ++) {
649
649
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
@@ -659,34 +659,41 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true_1
659
659
DBConnection controller_conn = new DBConnection ();
660
660
controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
661
661
controller_conn .run ("try{stopDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
662
+ controller_conn .run ("sleep(1000)" );
662
663
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
663
664
controller_conn .run ("try{startDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
665
+ controller_conn .run ("sleep(1000)" );
664
666
DBConnection connection1 = new DBConnection ();
665
667
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
666
668
connection1 .run ("sleep(3000)" );
667
- BasicTable re = (BasicTable ) connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
669
+ BasicTable node1 = (BasicTable )connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port =" +ipports [1 ].split (":" )[1 ]);
670
+ System .out .println (node1 .getString ());
671
+ Assert .assertEquals (true , Integer .valueOf (node1 .getColumn (1 ).get (0 ).toString ())>=50 );
672
+
673
+ BasicTable node2 = (BasicTable )connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port =" +ipports [2 ].split (":" )[1 ]);
674
+ System .out .println (node2 .getString ());
675
+ Assert .assertEquals (true , Integer .valueOf (node2 .getColumn (1 ).get (0 ).toString ())>=25 );
676
+ pool1 .shutdown ();
677
+ }
678
+ @ Test
679
+ public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_true () throws SQLException , ClassNotFoundException , IOException {
680
+ DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,false ,null ,null , false , false , false );
681
+ DBConnection connection1 = new DBConnection ();
682
+ connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
683
+ connection1 .run ("sleep(3000)" );
684
+ BasicTable re = (BasicTable ) connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode in [0,4];" );
668
685
for (int i = 0 ; i < re .rows (); i ++) {
669
686
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
670
687
String port = re .getColumn (0 ).get (i ).toString ();
671
688
String connectionNum = re .getColumn (1 ).get (i ).toString ();
672
689
if (Integer .valueOf (port )!=PORT ) {
673
- assertEquals (true , Integer .valueOf (connectionNum ) > 25 );
690
+ assertEquals (true , Integer .valueOf (connectionNum ) > 20 );
674
691
assertEquals (true , Integer .valueOf (connectionNum ) < 50 );
675
692
}
676
693
}
677
694
pool1 .shutdown ();
678
695
}
679
696
@ Test
680
- public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_true () throws SQLException , ClassNotFoundException , IOException {
681
- String re = null ;
682
- try {
683
- DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,false ,null ,null , false , false , false );
684
- }catch (Exception ex ){
685
- re = ex .getMessage ();
686
- }
687
- Assert .assertEquals ("Cannot only enable loadbalance but not enable highAvailablity." ,re );
688
- }
689
- @ Test
690
697
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_site_not_null () throws SQLException , ClassNotFoundException , IOException {
691
698
DBConnection controller_conn = new DBConnection ();
692
699
controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
@@ -705,16 +712,16 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
705
712
controller_conn .run ("5000" );
706
713
List <DBTask > tasks = new ArrayList <>();
707
714
for (int i = 0 ; i < 100 ; i ++){
708
- BasicDBTask task = new BasicDBTask ("t = streamTable(10:0,`a`b,[INT,INT]); \n insert into t values(1,1 );" );
715
+ BasicDBTask task = new BasicDBTask ("getNodePort( );" );
709
716
tasks .add (task );
710
717
}
711
718
pool1 .execute (tasks );
719
+ pool1 .waitForThreadCompletion ();
712
720
BasicTable node2 = (BasicTable )controller_conn .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port =" +PORT );
713
721
System .out .println (node2 .getString ());
714
722
Assert .assertEquals (true , Integer .valueOf (node2 .getColumn (1 ).get (0 ).toString ())>=100 );
715
723
controller_conn .run ("try{startDataNode('" +HOST +":" +ipportArray [0 ].split (":" )[1 ]+"')}catch(ex){}" );
716
724
controller_conn .run ("2000" );
717
725
pool1 .shutdown ();
718
-
719
726
}
720
727
}
0 commit comments