Skip to content

Commit c49da16

Browse files
committed
AJ-830,AJ-833:add test case about listener for run function and connect when 'isClientAuth' is true
1 parent f3bcf8e commit c49da16

File tree

1 file changed

+134
-5
lines changed

1 file changed

+134
-5
lines changed

test/com/xxdb/DBConnectionTest.java

Lines changed: 134 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.math.BigDecimal;
1919
import java.net.*;
2020
import java.sql.*;
21+
import java.sql.Array;
2122
import java.text.SimpleDateFormat;
2223
import java.time.*;
2324
import java.util.*;
@@ -408,6 +409,20 @@ public void Test_Connect_readTimeout_fail_2() throws IOException, InterruptedExc
408409
Assert.assertEquals(true,re.contains("read timed out."));
409410
System.out.println(re);
410411
}
412+
413+
@Test
414+
public void test_Connect_Reconnect_true_tryReconnectNums_int() throws IOException {
415+
int port=7102;
416+
int trynums=2;
417+
DBConnection conn =new DBConnection();
418+
String re = null;
419+
try {
420+
conn.connect(HOST,port,0,true,trynums);
421+
}catch (Exception ex) {
422+
re = ex.getMessage();
423+
}
424+
assertEquals("Connect to "+HOST+":"+port+" failed after "+trynums+" reconnect attempts.",re);
425+
}
411426
@Test
412427
public void test_Connect_tryReconnectNums_Filed_enableHighAvailability_false_enableLoadBalance_false() throws IOException {
413428
int port=7102;
@@ -3130,7 +3145,7 @@ public void TestFetchSizeLessThan1892() throws IOException {
31303145
EntityBlockReader v = (EntityBlockReader) conn.run("table(1..22486 as id)", (ProgressListener) null, 4, 4, 8191);
31313146
}
31323147

3133-
@Test
3148+
//@Test
31343149
public void TestFetchBigData() throws IOException {
31353150
EntityBlockReader v = (EntityBlockReader) conn.run("table(1..50080000 as id)", (ProgressListener) null, 4, 4, 8200);
31363151
BasicTable data = (BasicTable) v.read();
@@ -4588,7 +4603,7 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
45884603
{
45894604
System.out.println(ex);
45904605
}
4591-
sleep(10000);
4606+
sleep(5000);
45924607
//DBConnection conn1 = new DBConnection();
45934608
conn1.connect(HOST,PORT,"admin","123456",null,false);
45944609
sleep(500);
@@ -4608,7 +4623,7 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
46084623
{
46094624
System.out.println(ex);
46104625
}
4611-
sleep(1000);
4626+
sleep(5000);
46124627
conn1.connect(HOST,PORT,"admin","123456",null,false);
46134628
conn1.run("a=1;\n a");
46144629
assertEquals(true, conn1.isConnected());
@@ -4628,7 +4643,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
46284643
{
46294644
System.out.println(ex);
46304645
}
4631-
sleep(1000);
4646+
sleep(5000);
46324647
conn1.run("a=1;\n a");
46334648
//The connection switches to a different node to execute the code
46344649
try{
@@ -4637,7 +4652,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
46374652
{
46384653
System.out.println(ex);
46394654
}
4640-
sleep(1000);
4655+
sleep(5000);
46414656
assertEquals(true, conn1.isConnected());
46424657
}
46434658
//@Test //AJ-287
@@ -5416,5 +5431,119 @@ public void test_DBConnection_run_parallelism_3() throws IOException, Interrupte
54165431
System.out.println(re1.getString());
54175432
Assert.assertEquals("22",re1.getColumn(6).get(0).getString());
54185433
}
5434+
@Test //isClientAuth开启
5435+
public void test_not_login_run_fuction() throws Exception {
5436+
DBConnection db = new DBConnection();
5437+
db.connect("192.168.0.69", 8868);
5438+
Entity version = db.run("version",new ArrayList<>());
5439+
System.out.println(version.getString());
5440+
assertNotNull(version.getString());
5441+
5442+
Entity isClientAuth = db.run("isClientAuth",new ArrayList<>());
5443+
System.out.println(isClientAuth.getString());
5444+
assertNotNull(isClientAuth.getString());
5445+
5446+
Entity getNodeType = db.run("getNodeType",new ArrayList<>());
5447+
System.out.println(getNodeType.getString());
5448+
assertNotNull(getNodeType.getString());
5449+
5450+
Entity getNodeAlias = db.run("getNodeAlias",new ArrayList<>());
5451+
System.out.println(getNodeAlias.getString());
5452+
assertNotNull(getNodeAlias.getString());
5453+
5454+
Entity getControllerAlias = db.run("getControllerAlias",new ArrayList<>());
5455+
System.out.println(getControllerAlias.getString());
5456+
assertNotNull(getControllerAlias.getString());
5457+
5458+
Entity license = db.run("license",new ArrayList<>());
5459+
System.out.println(license.getString());
5460+
assertNotNull(license.getString());
5461+
5462+
Entity getActiveMaster = db.run("getActiveMaster",new ArrayList<>());
5463+
System.out.println(getActiveMaster.getString());
5464+
assertNotNull(getActiveMaster.getString());
5465+
5466+
Entity getClusterPerf = db.run("getClusterPerf",new ArrayList<>());
5467+
System.out.println(getClusterPerf.getString());
5468+
assertNotNull(getClusterPerf.getString());
5469+
5470+
Entity loadClusterNodesConfigs = db.run("loadClusterNodesConfigs",new ArrayList<>());
5471+
System.out.println(loadClusterNodesConfigs.getString());
5472+
assertNotNull(loadClusterNodesConfigs.getString());
5473+
5474+
Entity getConfig = db.run("getConfig",new ArrayList<>());
5475+
System.out.println(getConfig.getString());
5476+
assertNotNull(getConfig.getString());
5477+
5478+
Entity getCurrentSessionAndUser = db.run("getCurrentSessionAndUser",new ArrayList<>());
5479+
System.out.println(getCurrentSessionAndUser.getString());
5480+
assertNotNull(getCurrentSessionAndUser.getString());
5481+
5482+
Entity getDynamicPublicKey = db.run("getDynamicPublicKey",new ArrayList<>());
5483+
System.out.println(getDynamicPublicKey.getString());
5484+
assertNotNull(getDynamicPublicKey.getString());
5485+
5486+
String re = null;
5487+
try{
5488+
db.run("1+1");
5489+
}catch(Exception e){
5490+
re = e.getMessage();
5491+
}
5492+
assertEquals(true, re.contains("Login is required for script execution with client authentication enabled."));
5493+
}
5494+
//@Test
5495+
public void test_not_login_run_fuction_authenticateByTicket() throws Exception {
5496+
DBConnection db = new DBConnection();
5497+
db.connect("192.168.0.69", 8868);
5498+
List<Entity> entity = new ArrayList<>();
5499+
entity.add(new BasicString("kdC8Ta0JzMc0czTyBByX2Jn3eD89uOJ9FXGuUjRdxL8EpoNze1xWGBpsI5wV7zer\n" +
5500+
"NP8gGsHy6X3JpHY5D+GzOH2qkPtpauTBTgUaNEr2BYcTnZXtq65xmvv0moeygELF\n" +
5501+
"rlUPYVL4CiL8ueLYxl0SyBzbG4sB7/pR0b5/PcIfb1g="));
5502+
db.run("authenticateByTicket",entity);
5503+
db.run("1+1");
5504+
}
5505+
@Test
5506+
public void test_not_login_run_fuction_login() throws Exception {
5507+
DBConnection db = new DBConnection();
5508+
db.connect("192.168.0.69", 8868);
5509+
List<Entity> entity1 = new ArrayList<>();
5510+
entity1.add(new BasicString("admin"));
5511+
entity1.add(new BasicString("123456"));
5512+
db.run("login",entity1);
5513+
db.run("1+1");
5514+
}
5515+
@Test
5516+
public void test_not_login_run_fuction_not_support() throws Exception {
5517+
DBConnection db = new DBConnection();
5518+
db.connect("192.168.0.69", 8868);
5519+
String re = null;
5520+
try{
5521+
db.run("getAllDBs",new ArrayList<>());
5522+
}catch(Exception e){
5523+
re = e.getMessage();
5524+
}
5525+
assertEquals(true, re.contains("Login is required for script execution with client authentication enabled. RefId: S04009. function: getAllDBs"));
5526+
}
5527+
@Test //isClientAuth开启
5528+
public void test_Connect_enableHighAvailability_true() throws IOException {
5529+
DBConnection conn =new DBConnection();
5530+
conn.connect(HOST,8868,"admin","123456","table(1..10 as id);",true,new String[]{"192.168.0.69:8868"});
5531+
}
54195532

5533+
@Test
5534+
public void test_run_fuction_listener() throws Exception {
5535+
DBConnection db = new DBConnection();
5536+
db.connect(HOST, PORT, "admin", "123456");
5537+
ProgressListener listener = new ProgressListener() {
5538+
@Override
5539+
public void progress(String message) {
5540+
System.out.println("message: \n" + message);
5541+
}
5542+
};
5543+
List<Entity> entity = new ArrayList<>();
5544+
entity.add(new BasicString("BVE="));
5545+
entity.add(new BasicString("2中国BVE="));
5546+
Entity print = db.run("print", entity, 3, 3, 0, true, listener);
5547+
System.out.println("print:" + print.getString());
5548+
}
54205549
}

0 commit comments

Comments
 (0)