2828
2929import static com .xxdb .Prepare .*;
3030import static com .xxdb .comm .SqlStdEnum .*;
31+ import static java .lang .Thread .sleep ;
3132import static org .junit .Assert .*;
3233
3334public class DBConnectionTest {
@@ -2544,7 +2545,7 @@ public void TestPartitionTable() throws IOException, InterruptedException {
25442545 sb .append ("pt.append!(t1);" );
25452546 conn .run (sb .toString ());
25462547 conn .run ("pnodeRun(purgeCacheEngine)" );
2547- Thread . sleep (5000 );
2548+ sleep (5000 );
25482549 BasicLong res_x = (BasicLong ) conn .run ("exec count(*) from pt where x=1" );
25492550 assertEquals (true , res_x .getLong () > 0 );
25502551 //PartitionTableJoin
@@ -2636,10 +2637,10 @@ public void TestCloseOnce() throws IOException, InterruptedException {
26362637 DBConnection connClose = new DBConnection ();
26372638 //连接一次
26382639 connClose .connect (HOST , PORT , "admin" , "123456" );
2639- Thread . sleep (5000 );
2640+ sleep (5000 );
26402641 int connCount = getConnCount ();
26412642 connClose .close ();
2642- Thread . sleep (5000 );
2643+ sleep (5000 );
26432644 int connCount1 = getConnCount ();
26442645 assertEquals (connCount - 1 , connCount1 );
26452646 }
@@ -2658,10 +2659,10 @@ public void TestClose() throws IOException, InterruptedException {
26582659 }
26592660
26602661 }
2661- Thread . sleep (2000 );
2662+ sleep (2000 );
26622663 int connCount = getConnCount ();
26632664 connNew .close ();
2664- Thread . sleep (2000 );
2665+ sleep (2000 );
26652666 int connCount1 = getConnCount ();
26662667 assertEquals (connCount - 1 , connCount1 );
26672668 }
@@ -3457,7 +3458,7 @@ public void run() {
34573458 Timer timer = new Timer ("Timer" );
34583459 TimerTask rec = new reconnect ();
34593460 timer .scheduleAtFixedRate (rec , 0L , 500L );
3460- Thread . sleep (500L );
3461+ sleep (500L );
34613462 timer .cancel ();
34623463 }
34633464
@@ -3553,7 +3554,7 @@ public void test_TryRun_fetchSize() throws IOException, InterruptedException {
35533554 conn .tryRun ("x;" ,1 ,1 ,8192 ,true );
35543555 long afterDT = System .currentTimeMillis ();
35553556 System .out .println (afterDT -beforeDT );
3556- Thread . sleep (5000 );
3557+ sleep (5000 );
35573558 conn .run ("y=1..10000000" );
35583559 long startDT = System .currentTimeMillis ();
35593560 conn .tryRun ("y;" ,1 ,1 ,1000000 ,true );
@@ -3686,7 +3687,7 @@ public void test_TryRun_args_fetchSize() throws IOException, InterruptedExceptio
36863687 conn .tryRun ("sum" ,argus1 ,1 ,1 ,8192 );
36873688 long afterDT = System .currentTimeMillis ();
36883689 System .out .println (afterDT -beforeDT );
3689- Thread . sleep (10000 );
3690+ sleep (10000 );
36903691 List <Entity > argus2 = new ArrayList <>();
36913692 conn .run ("y=1..10000000" );
36923693 argus2 .add (conn .run ("y;" ));
@@ -4289,7 +4290,7 @@ public void test_insert_into_decimal128_arrayvector() throws Exception {
42894290 public void TestConnectWithoutUserid () throws IOException , InterruptedException {
42904291 DBConnection conn = new DBConnection ();
42914292 conn .connect (HOST ,PORT );
4292- Thread . sleep (500 );
4293+ sleep (500 );
42934294 assertEquals (true , conn .isConnected ());
42944295 }
42954296 @ Test
@@ -4308,7 +4309,7 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
43084309 }
43094310 //DBConnection conn1 = new DBConnection();
43104311 conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
4311- Thread . sleep (500 );
4312+ sleep (500 );
43124313 String e = null ;
43134314 try {
43144315 conn1 .run ("a=1;\n a" );
@@ -4318,14 +4319,14 @@ public void Test_connect_EnableHighAvailability_false() throws IOException, Inte
43184319 System .out .println (ex );
43194320 }
43204321 assertNotNull (e );
4321- Thread . sleep (1000 );
4322+ sleep (1000 );
43224323 try {
43234324 conn .run ("startDataNode(\" " +nodeAlias +"\" )" );
43244325 }catch (Exception ex )
43254326 {
43264327 System .out .println (ex );
43274328 }
4328- Thread . sleep (1000 );
4329+ sleep (1000 );
43294330 conn1 .connect (HOST ,PORT ,"admin" ,"123456" ,null ,false );
43304331 conn1 .run ("a=1;\n a" );
43314332 assertEquals (true , conn1 .isConnected ());
@@ -4345,7 +4346,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
43454346 {
43464347 System .out .println (ex );
43474348 }
4348- Thread . sleep (1000 );
4349+ sleep (1000 );
43494350 conn1 .run ("a=1;\n a" );
43504351 //The connection switches to a different node to execute the code
43514352 try {
@@ -4354,7 +4355,7 @@ public void Test_connect_EnableHighAvailability_true() throws IOException, Inter
43544355 {
43554356 System .out .println (ex );
43564357 }
4357- Thread . sleep (1000 );
4358+ sleep (1000 );
43584359 assertEquals (true , conn1 .isConnected ());
43594360 }
43604361 //@Test //AJ-287
@@ -4393,7 +4394,7 @@ public void Test_connect_EnableHighAvailability_true_1() throws IOException, Int
43934394 {
43944395 System .out .println (ex );
43954396 }
4396- Thread . sleep (1000 );
4397+ sleep (1000 );
43974398 conn1 .run ("a=1;\n a" );
43984399 //The connection switches to a different node to execute the code
43994400 try {
@@ -4402,7 +4403,7 @@ public void Test_connect_EnableHighAvailability_true_1() throws IOException, Int
44024403 {
44034404 System .out .println (ex );
44044405 }
4405- Thread . sleep (1000 );
4406+ sleep (1000 );
44064407 assertEquals (true , conn1 .isConnected ());
44074408 }
44084409 @ Test
@@ -4417,7 +4418,7 @@ public void Test_reConnect__true() throws IOException, InterruptedException {
44174418 {
44184419 System .out .println (ex );
44194420 }
4420- Thread . sleep (1000 );
4421+ sleep (1000 );
44214422 conn1 .run ("a=1;\n a" );
44224423 //The connection switches to a different node to execute the code
44234424 try {
@@ -4426,7 +4427,7 @@ public void Test_reConnect__true() throws IOException, InterruptedException {
44264427 {
44274428 System .out .println (ex );
44284429 }
4429- Thread . sleep (1000 );
4430+ sleep (1000 );
44304431 assertEquals (true , conn1 .isConnected ());
44314432 }
44324433 @ Test //reConnect is not valid
@@ -4441,7 +4442,7 @@ public void Test_reConnect__false() throws IOException, InterruptedException {
44414442 {
44424443 System .out .println (ex );
44434444 }
4444- Thread . sleep (1000 );
4445+ sleep (1000 );
44454446 conn1 .run ("a=1;\n a" );
44464447 //The connection switches to a different node to execute the code
44474448 try {
@@ -4450,7 +4451,7 @@ public void Test_reConnect__false() throws IOException, InterruptedException {
44504451 {
44514452 System .out .println (ex );
44524453 }
4453- Thread . sleep (1000 );
4454+ sleep (1000 );
44544455 assertEquals (true , conn1 .isConnected ());
44554456 }
44564457 //@Test
@@ -4492,7 +4493,7 @@ public void test_BasicDBTask1223()throws Exception{
44924493 public void Test_Connect_SqlStdEnum_DolphinDB () throws IOException , InterruptedException {
44934494 DBConnection conn = new DBConnection (DolphinDB );
44944495 conn .connect (HOST ,PORT );
4495- Thread . sleep (500 );
4496+ sleep (500 );
44964497 assertEquals (true , conn .isConnected ());
44974498 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("cumavg(1 2 3);" );
44984499 System .out .println (ba .getString ());
@@ -4510,7 +4511,7 @@ public void Test_Connect_SqlStdEnum_DolphinDB() throws IOException, InterruptedE
45104511 public void Test_Connect_SqlStdEnum_DolphinDB_1 () throws IOException , InterruptedException {
45114512 DBConnection conn = new DBConnection ();
45124513 conn .connect (HOST ,PORT );
4513- Thread . sleep (500 );
4514+ sleep (500 );
45144515 assertEquals (true , conn .isConnected ());
45154516 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'ddb')" );
45164517 System .out .println (ba .getString ());
@@ -4528,7 +4529,7 @@ public void Test_Connect_SqlStdEnum_DolphinDB_1() throws IOException, Interrupte
45284529 public void Test_Connect_SqlStdEnum_DolphinDB_2 () throws IOException , InterruptedException {
45294530 DBConnection conn = new DBConnection (DolphinDB );
45304531 conn .connect (HOST ,PORT );
4531- Thread . sleep (500 );
4532+ sleep (500 );
45324533 assertEquals (true , conn .isConnected ());
45334534 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'ddb')" );
45344535 System .out .println (ba .getString ());
@@ -4567,7 +4568,7 @@ public void Test_Connect_SqlStdEnum_Oracle() throws IOException, InterruptedExce
45674568 DBConnection conn = new DBConnection (Oracle );
45684569 conn .connect (HOST ,PORT );
45694570 conn .connect (HOST ,PORT );
4570- Thread . sleep (500 );
4571+ sleep (500 );
45714572 assertEquals (true , conn .isConnected ());
45724573 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("cumavg(1 2 3);" );
45734574 System .out .println (ba .getString ());
@@ -4589,7 +4590,7 @@ public void Test_Connect_SqlStdEnum_Oracle_1() throws IOException, InterruptedEx
45894590 DBConnection conn = new DBConnection ();
45904591 conn .connect (HOST ,PORT );
45914592 conn .connect (HOST ,PORT );
4592- Thread . sleep (500 );
4593+ sleep (500 );
45934594 assertEquals (true , conn .isConnected ());
45944595 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'oracle');" );
45954596 System .out .println (ba .getString ());
@@ -4611,7 +4612,7 @@ public void Test_Connect_SqlStdEnum_Oracle_2() throws IOException, InterruptedEx
46114612 DBConnection conn = new DBConnection (Oracle );
46124613 conn .connect (HOST ,PORT );
46134614 conn .connect (HOST ,PORT );
4614- Thread . sleep (500 );
4615+ sleep (500 );
46154616 assertEquals (true , conn .isConnected ());
46164617 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'ddb');" );
46174618 System .out .println (ba .getString ());
@@ -4632,7 +4633,7 @@ public void Test_Connect_SqlStdEnum_Oracle_2() throws IOException, InterruptedEx
46324633 public void Test_Connect_SqlStdEnum_MySQL () throws IOException , InterruptedException {
46334634 DBConnection conn = new DBConnection (MySQL );
46344635 conn .connect (HOST ,PORT );
4635- Thread . sleep (500 );
4636+ sleep (500 );
46364637 assertEquals (true , conn .isConnected ());
46374638 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("cumavg(1 2 3);" );
46384639 System .out .println (ba .getString ());
@@ -4658,7 +4659,7 @@ public void Test_Connect_SqlStdEnum_MySQL() throws IOException, InterruptedExcep
46584659 public void Test_Connect_SqlStdEnum_MySQL_1 () throws IOException , InterruptedException {
46594660 DBConnection conn = new DBConnection ();
46604661 conn .connect (HOST ,PORT );
4661- Thread . sleep (500 );
4662+ sleep (500 );
46624663 assertEquals (true , conn .isConnected ());
46634664 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'mysql');" );
46644665 System .out .println (ba .getString ());
@@ -4685,7 +4686,7 @@ public void Test_Connect_SqlStdEnum_MySQL_2() throws IOException, InterruptedExc
46854686 DBConnection conn = new DBConnection (MySQL );
46864687 conn .connect (HOST ,PORT );
46874688 conn .connect (HOST ,PORT );
4688- Thread . sleep (500 );
4689+ sleep (500 );
46894690 assertEquals (true , conn .isConnected ());
46904691 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'ddb');" );
46914692 System .out .println (ba .getString ());
@@ -4717,7 +4718,7 @@ public void Test_Connect_SqlStdEnum_getByName() throws IOException, InterruptedE
47174718 DBConnection conn = new DBConnection ( getByName ("MySQL" ));
47184719 conn .connect (HOST ,PORT );
47194720 conn .connect (HOST ,PORT );
4720- Thread . sleep (500 );
4721+ sleep (500 );
47214722 assertEquals (true , conn .isConnected ());
47224723 BasicDoubleVector ba = (BasicDoubleVector )conn .run ("runSQL(\" cumavg(1 2 3)\" , 'ddb');" );
47234724 System .out .println (ba .getString ());
@@ -5092,4 +5093,46 @@ public void test_allDateType_array_combine() throws IOException {
50925093// thread1.start();
50935094// thread.join();
50945095// }
5096+
5097+ @ Test //api设置的parallelism小于server的setMaxJobParallelism
5098+ public void test_DBConnection_run_parallelism_1 () throws IOException {
5099+ PrepareUser ("parallelism_test" ,"123456" );
5100+ conn = new DBConnection ();
5101+ conn .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5102+ String script2 ="setMaxJobParallelism(\" parallelism_test\" ,22);\n sleep(20);\n getConsoleJobs();" ;
5103+ BasicTable re = (BasicTable )conn .run (script2 ,4 ,5 ,false );
5104+ System .out .println (re .getString ());
5105+ Assert .assertEquals ("5" ,re .getColumn (6 ).get (0 ).getString ());
5106+ }
5107+ @ Test //api设置的parallelism大于server的setMaxJobParallelism
5108+ public void test_DBConnection_run_parallelism_2 () throws IOException {
5109+ PrepareUser ("parallelism_test" ,"123456" );
5110+ conn = new DBConnection ();
5111+ conn .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5112+ String script2 ="setMaxJobParallelism(\" parallelism_test\" ,22);\n sleep(100);\n getConsoleJobs();" ;
5113+ BasicTable re = (BasicTable )conn .run (script2 ,5 ,30 ,false );
5114+ System .out .println (re .getColumn (6 ).get (0 ).getString ());
5115+ //Assert.assertEquals("22",re.getColumn(6).get(0).getString());
5116+
5117+ DBConnection conn1 = new DBConnection ();
5118+ conn1 .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5119+ BasicTable re1 = (BasicTable )conn1 .run (script2 ,5 ,30 ,false );
5120+ Assert .assertEquals ("22" ,re1 .getColumn (6 ).get (0 ).getString ());
5121+ }
5122+
5123+ @ Test //api没有设置parallelism,取默认值64,大于server的setMaxJobParallelism
5124+ public void test_DBConnection_run_parallelism_3 () throws IOException , InterruptedException {
5125+ DBConnection conn = new DBConnection ();
5126+ PrepareUser ("parallelism_test" ,"123456" );
5127+ conn .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5128+ conn .run ("setMaxJobParallelism(\" parallelism_test\" ,22);" );
5129+ BasicTable re = (BasicTable )conn .run ("getConsoleJobs();" );
5130+ System .out .println (re .getString ());
5131+
5132+ DBConnection conn1 = new DBConnection ();
5133+ conn1 .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5134+ BasicTable re1 = (BasicTable )conn1 .run ("getConsoleJobs();" );
5135+ System .out .println (re1 .getString ());
5136+ Assert .assertEquals ("22" ,re1 .getColumn (6 ).get (0 ).getString ());
5137+ }
50955138}
0 commit comments