@@ -415,6 +415,9 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
415415 DBConnection connection = new DBConnection ();
416416 connection .connect (HOST , PORT , "admin" , "123456" ,null ,true ,null ,false ,false );
417417 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");
418421 }
419422 DBConnection connection1 = new DBConnection ();
420423 connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
@@ -533,7 +536,7 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
533536 @ Test
534537 public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
535538 DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,false );
536- Thread .sleep (10000 );
539+ Thread .sleep (1000 );
537540 DBConnection connection1 = new DBConnection ();
538541 connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
539542 connection1 .run ("sleep(3000)" );
@@ -546,7 +549,7 @@ public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false
546549 @ Test
547550 public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false () throws SQLException , ClassNotFoundException , IOException , InterruptedException {
548551 DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,false ,true );
549- Thread .sleep (10000 );
552+ Thread .sleep (1000 );
550553 DBConnection connection1 = new DBConnection ();
551554 connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
552555 connection1 .run ("sleep(3000)" );
@@ -579,6 +582,45 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
579582 }
580583 }
581584 }
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+ }
582624 @ Test
583625 public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true_highAvailabilitySites_null () throws SQLException , ClassNotFoundException , IOException {
584626 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()
601643 DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
602644 DBConnection connection1 = new DBConnection ();
603645 connection1 .connect (HOST , PORT , "admin" , "123456" ,true );
604- connection1 .run ("sleep(1000 )" );
646+ connection1 .run ("sleep(2000 )" );
605647 BasicTable re = (BasicTable ) connection1 .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
606648 for (int i = 0 ; i < re .rows (); i ++) {
607649 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
617659 DBConnection controller_conn = new DBConnection ();
618660 controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
619661 controller_conn .run ("try{stopDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
662+ controller_conn .run ("sleep(1000)" );
620663 DBConnectionPool pool1 = new ExclusiveDBConnectionPool (HOST ,PORT ,"admin" ,"123456" ,100 ,true ,true ,ipports ,null , false , false , false );
621664 controller_conn .run ("try{startDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
665+ controller_conn .run ("sleep(1000)" );
622666 DBConnection connection1 = new DBConnection ();
623667 connection1 .connect (HOST , PORT , "admin" , "123456" ,false );
624668 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];" );
626685 for (int i = 0 ; i < re .rows (); i ++) {
627686 System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
628687 String port = re .getColumn (0 ).get (i ).toString ();
629688 String connectionNum = re .getColumn (1 ).get (i ).toString ();
630689 if (Integer .valueOf (port )!=PORT ) {
631- assertEquals (true , Integer .valueOf (connectionNum ) > 25 );
690+ assertEquals (true , Integer .valueOf (connectionNum ) > 20 );
632691 assertEquals (true , Integer .valueOf (connectionNum ) < 50 );
633692 }
634693 }
635694 pool1 .shutdown ();
636695 }
637696 @ 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
648697 public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_site_not_null () throws SQLException , ClassNotFoundException , IOException {
649698 DBConnection controller_conn = new DBConnection ();
650699 controller_conn .connect (controller_host , controller_port , "admin" , "123456" );
@@ -663,16 +712,16 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
663712 controller_conn .run ("5000" );
664713 List <DBTask > tasks = new ArrayList <>();
665714 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( );" );
667716 tasks .add (task );
668717 }
669718 pool1 .execute (tasks );
719+ pool1 .waitForThreadCompletion ();
670720 BasicTable node2 = (BasicTable )controller_conn .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port =" +PORT );
671721 System .out .println (node2 .getString ());
672722 Assert .assertEquals (true , Integer .valueOf (node2 .getColumn (1 ).get (0 ).toString ())>=100 );
673723 controller_conn .run ("try{startDataNode('" +HOST +":" +ipportArray [0 ].split (":" )[1 ]+"')}catch(ex){}" );
674724 controller_conn .run ("2000" );
675725 pool1 .shutdown ();
676-
677726 }
678727}
0 commit comments