Skip to content

Commit d95fe9e

Browse files
committed
AJ-675: add test case about loadBalance
1 parent 91fd0cf commit d95fe9e

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

test/com/xxdb/LoadBalanceTest.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public void Test_getConnection_enableHighAvailability_true_enableLoadBalance_fal
536536
@Test
537537
public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false() throws SQLException, ClassNotFoundException, IOException, InterruptedException {
538538
DBConnectionPool pool1 = new ExclusiveDBConnectionPool(HOST,PORT,"admin","123456",100,false,false);
539-
Thread.sleep(10000);
539+
Thread.sleep(1000);
540540
DBConnection connection1 = new DBConnection();
541541
connection1.connect(HOST, PORT, "admin", "123456",false);
542542
connection1.run("sleep(3000)");
@@ -549,7 +549,7 @@ public void Test_DBConnectionPool_enableHighAvailability_false_loadBalance_false
549549
@Test
550550
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false() throws SQLException, ClassNotFoundException, IOException, InterruptedException {
551551
DBConnectionPool pool1 = new ExclusiveDBConnectionPool(HOST,PORT,"admin","123456",100,false,true);
552-
Thread.sleep(10000);
552+
Thread.sleep(1000);
553553
DBConnection connection1 = new DBConnection();
554554
connection1.connect(HOST, PORT, "admin", "123456",false);
555555
connection1.run("sleep(3000)");
@@ -643,7 +643,7 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_true()
643643
DBConnectionPool pool1 = new ExclusiveDBConnectionPool(HOST,PORT,"admin","123456",100,true,true,ipports,null, false, false, false);
644644
DBConnection connection1 = new DBConnection();
645645
connection1.connect(HOST, PORT, "admin", "123456",true);
646-
connection1.run("sleep(1000)");
646+
connection1.run("sleep(2000)");
647647
BasicTable re = (BasicTable) connection1.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0");
648648
for (int i = 0; i < re.rows(); i++) {
649649
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
659659
DBConnection controller_conn = new DBConnection();
660660
controller_conn.connect(controller_host, controller_port, "admin", "123456");
661661
controller_conn.run("try{stopDataNode('"+HOST+":"+PORT+"')}catch(ex){}");
662+
controller_conn.run("sleep(1000)");
662663
DBConnectionPool pool1 = new ExclusiveDBConnectionPool(HOST,PORT,"admin","123456",100,true,true,ipports,null, false, false, false);
663664
controller_conn.run("try{startDataNode('"+HOST+":"+PORT+"')}catch(ex){}");
665+
controller_conn.run("sleep(1000)");
664666
DBConnection connection1 = new DBConnection();
665667
connection1.connect(HOST, PORT, "admin", "123456",false);
666668
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];");
668685
for (int i = 0; i < re.rows(); i++) {
669686
System.out.println("port:" + re.getColumn(0).get(i) + " connectionNum:" + re.getColumn(1).get(i));
670687
String port = re.getColumn(0).get(i).toString();
671688
String connectionNum = re.getColumn(1).get(i).toString();
672689
if(Integer.valueOf(port)!=PORT) {
673-
assertEquals(true, Integer.valueOf(connectionNum) > 25);
690+
assertEquals(true, Integer.valueOf(connectionNum) > 20);
674691
assertEquals(true, Integer.valueOf(connectionNum) < 50);
675692
}
676693
}
677694
pool1.shutdown();
678695
}
679696
@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
690697
public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_site_not_null() throws SQLException, ClassNotFoundException, IOException {
691698
DBConnection controller_conn = new DBConnection();
692699
controller_conn.connect(controller_host, controller_port, "admin", "123456");
@@ -705,16 +712,16 @@ public void Test_DBConnectionPool_enableHighAvailability_true_loadBalance_false_
705712
controller_conn.run("5000");
706713
List<DBTask> tasks = new ArrayList<>();
707714
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();");
709716
tasks.add(task);
710717
}
711718
pool1.execute(tasks);
719+
pool1.waitForThreadCompletion();
712720
BasicTable node2 = (BasicTable)controller_conn.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0 and port ="+PORT);
713721
System.out.println(node2.getString());
714722
Assert.assertEquals(true, Integer.valueOf(node2.getColumn(1).get(0).toString())>=100);
715723
controller_conn.run("try{startDataNode('"+HOST+":"+ipportArray[0].split(":")[1]+"')}catch(ex){}");
716724
controller_conn.run("2000");
717725
pool1.shutdown();
718-
719726
}
720727
}

0 commit comments

Comments
 (0)