@@ -415,6 +415,9 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
415
415
DBConnection connection = new DBConnection ();
416
416
connection .connect (HOST , PORT , "admin" , "123456" ,null ,true ,null ,false ,false );
417
417
list .add (connection );
418
+ // BasicInt re = (BasicInt)connection.run("getNodePort()");
419
+ // System.out.println("current node is:"+re);
420
+ // System.out.println("stop current node");
418
421
}
419
422
DBConnection connection1 = new DBConnection ();
420
423
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
@@ -533,7 +536,7 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
533
536
@ Test
534
537
public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
535
538
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,false );
536
- Thread .sleep (10000 );
539
+ Thread .sleep (1000 );
537
540
DBConnection connection1 = new DBConnection ();
538
541
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
539
542
connection1 .run ("sleep(3000)" );
@@ -546,7 +549,7 @@ public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false
546
549
@ Test
547
550
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
548
551
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,true );
549
- Thread .sleep (10000 );
552
+ Thread .sleep (1000 );
550
553
DBConnection connection1 = new DBConnection ();
551
554
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
552
555
connection1 .run ("sleep(3000)" );
@@ -579,6 +582,45 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
579
582
}
580
583
}
581
584
}
585
+ //@Test//The current node is unavailable
586
+ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_2 () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
587
+ DBConnection controller_conn = new DBConnection ();
588
+ controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
589
+ class MyThread extends Thread {
590
+ @ Override
591
+ public void run () {
592
+ try {
593
+ DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,true ,null ,null , false , false , false );
594
+ Thread .sleep (1000 );
595
+ } catch (IOException e ) {
596
+ throw new RuntimeException (e );
597
+ } catch (InterruptedException e ) {
598
+ throw new RuntimeException (e );
599
+ }
600
+ }
601
+ }
602
+ class MyThread1 extends Thread {
603
+ @ Override
604
+ public void run () {
605
+ try {
606
+ controller_conn .run ("try{stopDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
607
+ Thread .sleep (1000 );
608
+ } catch (Exception e ) {
609
+ // 捕获异常并打印错误信息
610
+ System .err .println ("Error executing task: " + e .getMessage ());
611
+ }
612
+ }
613
+ }
614
+ MyThread thread = new MyThread ();
615
+ MyThread1 thread1 = new MyThread1 ();
616
+ thread .start ();
617
+ Thread .sleep (15 );
618
+ System .err .println ("thread1开始运行 " );
619
+ thread1 .start ();
620
+ thread .join ();
621
+ thread1 .join ();
622
+ controller_conn .run ("try{stopDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
623
+ }
582
624
@ Test
583
625
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true_highAvailabilitySites_null () throws SQLException , ClassNotFoundException , IOException {
584
626
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,null ,null , false , false , false );
@@ -601,7 +643,7 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true()
601
643
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
602
644
DBConnection connection1 = new DBConnection ();
603
645
connection1 .connect (HOST , PORT , "admin" , "123456" ,true );
604
- connection1 .run ("sleep(1000 )" );
646
+ connection1 .run ("sleep(2000 )" );
605
647
BasicTable re = (BasicTable ) connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
606
648
for (int i = 0 ; i < re .rows (); i ++) {
607
649
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
@@ -617,34 +659,41 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true_1
617
659
DBConnection controller_conn = new DBConnection ();
618
660
controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
619
661
controller_conn .run ("try{stopDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
662
+ controller_conn .run ("sleep(1000)" );
620
663
DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
621
664
controller_conn .run ("try{startDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
665
+ controller_conn .run ("sleep(1000)" );
622
666
DBConnection connection1 = new DBConnection ();
623
667
connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
624
668
connection1 .run ("sleep(3000)" );
625
- 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];" );
626
685
for (int i = 0 ; i < re .rows (); i ++) {
627
686
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
628
687
String port = re .getColumn (0 ).get (i ).toString ();
629
688
String connectionNum = re .getColumn (1 ).get (i ).toString ();
630
689
if (Integer .valueOf (port )!=PORT ) {
631
- assertEquals (true , Integer .valueOf (connectionNum ) > 25 );
690
+ assertEquals (true , Integer .valueOf (connectionNum ) > 20 );
632
691
assertEquals (true , Integer .valueOf (connectionNum ) < 50 );
633
692
}
634
693
}
635
694
pool1 .shutdown ();
636
695
}
637
696
@ Test
638
- public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_true () throws SQLException , ClassNotFoundException , IOException {
639
- String re = null ;
640
- try {
641
- DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,false ,null ,null , false , false , false );
642
- }catch (Exception ex ){
643
- re = ex .getMessage ();
644
- }
645
- Assert .assertEquals ("Cannot only enable loadbalance but not enable highAvailablity." ,re );
646
- }
647
- @ Test
648
697
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_site_not_null () throws SQLException , ClassNotFoundException , IOException {
649
698
DBConnection controller_conn = new DBConnection ();
650
699
controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
@@ -663,16 +712,16 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
663
712
controller_conn .run ("5000" );
664
713
List <DBTask > tasks = new ArrayList <>();
665
714
for (int i = 0 ; i < 100 ; i ++){
666
- 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( );" );
667
716
tasks .add (task );
668
717
}
669
718
pool1 .execute (tasks );
719
+ pool1 .waitForThreadCompletion ();
670
720
BasicTable node2 = (BasicTable )controller_conn .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port =" +PORT );
671
721
System .out .println (node2 .getString ());
672
722
Assert .assertEquals (true , Integer .valueOf (node2 .getColumn (1 ).get (0 ).toString ())>=100 );
673
723
controller_conn .run ("try{startDataNode('" +HOST +":" +ipportArray [0 ].split (":" )[1 ]+"')}catch(ex){}" );
674
724
controller_conn .run ("2000" );
675
725
pool1 .shutdown ();
676
-
677
726
}
678
727
}
0 commit comments