18
18
import java .math .BigDecimal ;
19
19
import java .net .*;
20
20
import java .sql .*;
21
+ import java .sql .Array ;
21
22
import java .text .SimpleDateFormat ;
22
23
import java .time .*;
23
24
import java .util .*;
@@ -408,6 +409,20 @@ public void Test_Connect_readTimeout_fail_2() throws IOException, InterruptedExc
408
409
Assert .assertEquals (true ,re .contains ("read timed out." ));
409
410
System .out .println (re );
410
411
}
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
+ }
411
426
@ Test
412
427
public void test_Connect_tryReconnectNums_Filed_enableHighAvailability_false_enableLoadBalance_false () throws IOException {
413
428
int port =7102 ;
@@ -3130,7 +3145,7 @@ public void TestFetchSizeLessThan1892() throws IOException {
3130
3145
EntityBlockReader v = (EntityBlockReader ) conn .run ("table(1..22486 as id)" , (ProgressListener ) null , 4 , 4 , 8191 );
3131
3146
}
3132
3147
3133
- @ Test
3148
+ // @Test
3134
3149
public void TestFetchBigData () throws IOException {
3135
3150
EntityBlockReader v = (EntityBlockReader ) conn .run ("table(1..50080000 as id)" , (ProgressListener ) null , 4 , 4 , 8200 );
3136
3151
BasicTable data = (BasicTable ) v .read ();
@@ -4588,7 +4603,7 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
4588
4603
{
4589
4604
System .out .println (ex );
4590
4605
}
4591
- sleep (10000 );
4606
+ sleep (5000 );
4592
4607
//DBConnection conn1 = new DBConnection();
4593
4608
conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4594
4609
sleep (500 );
@@ -4608,7 +4623,7 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
4608
4623
{
4609
4624
System .out .println (ex );
4610
4625
}
4611
- sleep (1000 );
4626
+ sleep (5000 );
4612
4627
conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4613
4628
conn1 .run ("a=1;\n a" );
4614
4629
assertEquals (true , conn1 .isConnected ());
@@ -4628,7 +4643,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
4628
4643
{
4629
4644
System .out .println (ex );
4630
4645
}
4631
- sleep (1000 );
4646
+ sleep (5000 );
4632
4647
conn1 .run ("a=1;\n a" );
4633
4648
//The connection switches to a different node to execute the code
4634
4649
try {
@@ -4637,7 +4652,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
4637
4652
{
4638
4653
System .out .println (ex );
4639
4654
}
4640
- sleep (1000 );
4655
+ sleep (5000 );
4641
4656
assertEquals (true , conn1 .isConnected ());
4642
4657
}
4643
4658
//@Test //AJ-287
@@ -5416,5 +5431,119 @@ public void test_DBConnection_run_parallelism_3() throws IOException, Interrupte
5416
5431
System .out .println (re1 .getString ());
5417
5432
Assert .assertEquals ("22" ,re1 .getColumn (6 ).get (0 ).getString ());
5418
5433
}
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
+ }
5419
5532
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
+ }
5420
5549
}
0 commit comments