23
23
24
24
import static com .xxdb .Prepare .*;
25
25
import static com .xxdb .comm .SqlStdEnum .*;
26
+ import static com .xxdb .data .Entity .DATA_FORM .DF_TABLE ;
27
+ import static com .xxdb .data .Entity .DATA_TYPE .*;
26
28
import static java .lang .Thread .sleep ;
27
29
import static org .junit .Assert .*;
28
30
@@ -606,7 +608,7 @@ public void testIntScalar() throws Exception {
606
608
scalar .setNull ();
607
609
assertTrue (scalar .isNull ());
608
610
assertEquals (Entity .DATA_CATEGORY .INTEGRAL ,scalar .getDataCategory ());
609
- assertEquals (Entity . DATA_TYPE . DT_INT ,scalar .getDataType ());
611
+ assertEquals (DT_INT ,scalar .getDataType ());
610
612
assertEquals (-1 ,scalar .hashBucket (1 ));
611
613
assertEquals (-2147483648 ,scalar .hashCode ());
612
614
assertEquals ("null" ,scalar .getJsonString ());
@@ -758,7 +760,7 @@ public void testSecondScalar() throws Exception {
758
760
scalar .setNull ();
759
761
assertTrue (scalar .isNull ());
760
762
assertEquals (Entity .DATA_CATEGORY .TEMPORAL ,scalar .getDataCategory ());
761
- assertEquals (Entity . DATA_TYPE . DT_SECOND ,scalar .getDataType ());
763
+ assertEquals (DT_SECOND ,scalar .getDataType ());
762
764
assertEquals (-1 ,scalar .hashBucket (1 ));
763
765
assertEquals (-2147483648 ,scalar .hashCode ());
764
766
assertEquals ("null" ,scalar .getJsonString ());
@@ -887,7 +889,7 @@ public void testStringScalar() throws Exception {
887
889
scalar .setNull ();
888
890
assertTrue (scalar .isNull ());
889
891
assertEquals (Entity .DATA_CATEGORY .LITERAL ,scalar .getDataCategory ());
890
- assertEquals (Entity . DATA_TYPE . DT_STRING ,scalar .getDataType ());
892
+ assertEquals (DT_STRING ,scalar .getDataType ());
891
893
assertEquals (0 ,scalar .hashBucket (1 ));
892
894
assertEquals (0 ,scalar .hashCode ());
893
895
assertEquals ("null" ,scalar .getJsonString ());
@@ -1767,7 +1769,7 @@ public void testDictionaryUpload() throws IOException {
1767
1769
public void testDictionaryUpload_1 () throws IOException {
1768
1770
DBConnection conn = new DBConnection ();
1769
1771
conn .connect (HOST ,PORT ,"admin" ,"123456" );
1770
- BasicDictionary bd = new BasicDictionary (Entity . DATA_TYPE . DT_INT , Entity .DATA_TYPE .DT_ANY );
1772
+ BasicDictionary bd = new BasicDictionary (DT_INT , Entity .DATA_TYPE .DT_ANY );
1771
1773
Map <String ,Entity > data = new HashMap <>();
1772
1774
data .put ("bd" ,bd );
1773
1775
conn .upload (data );
@@ -1837,7 +1839,7 @@ public void testAnyVector_Duration_Upload() throws Exception {
1837
1839
@ Test
1838
1840
public void testSet () throws IOException {
1839
1841
BasicSet result = (BasicSet ) conn .run ("set(1+3*1..100)" );
1840
- assertEquals (Entity . DATA_TYPE . DT_INT , result .getDataType ());
1842
+ assertEquals (DT_INT , result .getDataType ());
1841
1843
assertEquals (Entity .DATA_FORM .DF_SET , result .getDataForm ());
1842
1844
1843
1845
}
@@ -1849,7 +1851,7 @@ public void testSetUpload() throws IOException {
1849
1851
map .put ("set" , set );
1850
1852
conn .upload (map );
1851
1853
Entity sets = conn .run ("set" );
1852
- assertEquals (Entity . DATA_TYPE . DT_INT , sets .getDataType ());
1854
+ assertEquals (DT_INT , sets .getDataType ());
1853
1855
assertEquals (Entity .DATA_FORM .DF_SET , sets .getDataForm ());
1854
1856
}
1855
1857
@@ -3919,6 +3921,7 @@ public void test_tryUpload() throws IOException{
3919
3921
@ Test
3920
3922
public void test_SSL () throws Exception {
3921
3923
DBConnection conn = new DBConnection (false ,true );
3924
+ conn .connect (HOST ,PORT ,"admin" ,"123456" );
3922
3925
assertTrue (conn .connect (HOST ,PORT ,"admin" ,"123456" ));
3923
3926
HashMap <String ,Entity > map = new HashMap <>();
3924
3927
map .put ("x" ,conn .run ("x=[1 3 6 10];" ));
@@ -5154,8 +5157,9 @@ public void test_DBConnection_run_parallelism_1() throws IOException {
5154
5157
5155
5158
DBConnection conn1 = new DBConnection ();
5156
5159
conn1 .connect (HOST ,PORT ,"parallelism_test" ,"123456" );
5157
- BasicTable re1 = (BasicTable )conn .run ("getConsoleJobs();" ,4 ,5 ,false );
5160
+ BasicTable re1 = (BasicTable )conn .run ("getConsoleJobs();" ,3 ,5 ,false );
5158
5161
Assert .assertEquals ("5" ,re1 .getColumn (6 ).get (0 ).getString ());
5162
+ System .out .println (re1 .getColumn (5 ).get (0 ).getString ());
5159
5163
}
5160
5164
@ Test //api设置的parallelism大于server的setMaxJobParallelism
5161
5165
public void test_DBConnection_run_parallelism_2 () throws IOException {
@@ -5278,10 +5282,10 @@ public void test_not_login_run_fuction_not_support() throws Exception {
5278
5282
}
5279
5283
assertEquals (true , re .contains ("Login is required for script execution with client authentication enabled. RefId: S04009. function: getAllDBs" ));
5280
5284
}
5281
- @ Test //isClientAuth开启
5285
+ // @Test //isClientAuth开启
5282
5286
public void test_Connect_enableHighAvailability_true () throws IOException {
5283
5287
DBConnection conn =new DBConnection ();
5284
- conn .connect (HOST ,8868 ,"admin" ,"123456" ,"table(1..10 as id);" ,true ,new String []{"192.168.0.69:8868" });
5288
+ conn .connect (HOST ,PORT ,"admin" ,"123456" ,"table(1..10 as id);" ,true ,new String []{"192.168.0.69:8868" });
5285
5289
}
5286
5290
5287
5291
@ Test
@@ -5300,4 +5304,167 @@ public void progress(String message) {
5300
5304
Entity print = db .run ("print" , entity , 3 , 3 , 0 , true , listener );
5301
5305
System .out .println ("print:" + print .getString ());
5302
5306
}
5303
- }
5307
+ @ Test
5308
+ public void TestDownloadUpload_hugeTable () throws Exception {
5309
+ DBConnection conn = new DBConnection ();
5310
+ conn .connect (HOST ,PORT ,"admin" ,"123456" );
5311
+ BasicTable re = (BasicTable )conn .run ("t=table(second(0..999999) as sd, take(`AAPL, 1000000) as str, 0..999999 as cint, arrayVector(1..1000000*3, take(NULL 1.123 -9928345.0, 3000000)) as cdoublev); \n t" );
5312
+ assertEquals (DF_TABLE ,re .getDataForm ());
5313
+ assertEquals (1000000 ,re .rows ());
5314
+ assertEquals (4 ,re .columns ());
5315
+ assertEquals (DT_SECOND ,re .getColumn (0 ).getDataType ());
5316
+ assertEquals (DT_STRING ,re .getColumn (1 ).getDataType ());
5317
+ assertEquals (DT_INT ,re .getColumn (2 ).getDataType ());
5318
+ assertEquals (DT_DOUBLE_ARRAY ,re .getColumn (3 ).getDataType ());
5319
+ Entity ex_col0 = conn .run ("take(second(0..999999), 1000000)" );
5320
+ Entity ex_col1 = conn .run ("take(`AAPL, 1000000)" );
5321
+ Entity ex_col2 = conn .run ("0..999999" );
5322
+ Entity ex_col3 = conn .run ("arrayVector(1..1000000*3, take(NULL 1.123 -9928345.0, 3000000))" );
5323
+
5324
+ assertEquals (ex_col0 .getString (),re .getColumn (0 ).getString ());
5325
+ assertEquals (ex_col1 .getString (),re .getColumn (1 ).getString ());
5326
+ assertEquals (ex_col2 .getString (),re .getColumn (2 ).getString ());
5327
+ assertEquals (ex_col3 .getString (),re .getColumn (3 ).getString ());
5328
+
5329
+ Map <String , Entity > map = new HashMap <String , Entity >();
5330
+ map .put ("res" , re );
5331
+ conn .upload (map );
5332
+ Entity assertion_result = conn .run ("all(each(eqObj, values res, values t, 5))" );
5333
+ assertEquals ("true" , assertion_result .getString ());
5334
+ }
5335
+
5336
+ @ Test
5337
+ public void Test_DBConnection_enableSCRAM_false () throws Exception {
5338
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,false );
5339
+ conn .connect (HOST ,PORT ,"admin" ,"123456" );
5340
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5341
+ System .out .println (re .getString ());
5342
+ assertEquals ("2" , re .getString ());
5343
+ }
5344
+
5345
+ @ Test
5346
+ public void Test_DBConnection_enableSCRAM_false_user_authMode_scram () throws Exception {
5347
+ PrepareUser_authMode ("scramUser" ,"123456" ,"scram" );
5348
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,false );
5349
+ conn .connect (HOST ,PORT ,"scramUser" ,"123456" );
5350
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5351
+ System .out .println (re .getString ());
5352
+ assertEquals ("2" , re .getString ());
5353
+ conn .close ();
5354
+ }
5355
+
5356
+ @ Test
5357
+ public void Test_DBConnection_enableSCRAM_true_user_admin () throws Exception {
5358
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5359
+ String re = null ;
5360
+ try {
5361
+ conn .connect (HOST ,PORT ,"admin" ,"123456" );
5362
+ }catch (Exception e ){
5363
+ re = e .getMessage ();
5364
+ }
5365
+ assertEquals ("user 'admin' doesn't support scram authMode." , re );
5366
+ }
5367
+
5368
+ @ Test
5369
+ public void Test_DBConnection_enableSCRAM_true_user_not_support () throws Exception {
5370
+ PrepareUser_authMode ("test2" ,"123456" ,"sha256" );
5371
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5372
+ String re = null ;
5373
+ try {
5374
+ conn .connect (HOST ,PORT ,"test2" ,"123456" );
5375
+ }catch (Exception e ){
5376
+ re = e .getMessage ();
5377
+ }
5378
+ assertEquals ("user 'test2' doesn't support scram authMode." , re );
5379
+ }
5380
+ @ Test
5381
+ public void Test_DBConnection_enableSCRAM_true () throws Exception {
5382
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5383
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5384
+ conn .connect (HOST ,PORT ,"test1" ,"123456" );
5385
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5386
+ System .out .println (re .getString ());
5387
+ assertEquals ("2" , re .getString ());
5388
+ }
5389
+
5390
+ @ Test
5391
+ public void Test_DBConnection_enableSCRAM_true_asynchronousTask_true () throws Exception {
5392
+ PrepareUser_authMode ("scramUser" ,"123456" ,"scram" );
5393
+ DBConnection conn = new DBConnection (true , false ,false ,false ,false ,null ,true );
5394
+ String re = null ;
5395
+ try {
5396
+ conn .connect (HOST ,PORT ,"test1" ,"123456" );
5397
+ }catch (Exception ex ){
5398
+ re = ex .getMessage ();
5399
+ }
5400
+ assertEquals ("SCRAM login failed, server error: get server nonce failed." , re );
5401
+ }
5402
+
5403
+ @ Test
5404
+ public void Test_DBConnection_enableSCRAM_true_useSSL_true () throws Exception {
5405
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5406
+ DBConnection conn = new DBConnection (false , true ,false ,false ,false ,null ,true );
5407
+ conn .connect (HOST ,PORT ,"test1" ,"123456" );
5408
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5409
+ System .out .println (re .getString ());
5410
+ assertEquals ("2" , re .getString ());
5411
+ }
5412
+
5413
+ @ Test
5414
+ public void Test_DBConnection_enableSCRAM_true_compress_true () throws Exception {
5415
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5416
+ DBConnection conn = new DBConnection (false , false ,true ,false ,false ,null ,true );
5417
+ conn .connect (HOST ,PORT ,"test1" ,"123456" );
5418
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5419
+ System .out .println (re .getString ());
5420
+ assertEquals ("2" , re .getString ());
5421
+ }
5422
+
5423
+ @ Test
5424
+ public void Test_DBConnection_enableSCRAM_true_usePython_true () throws Exception {
5425
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5426
+ DBConnection conn = new DBConnection (false , false ,false ,true ,false ,null ,true );
5427
+ conn .connect (HOST ,PORT ,"test1" ,"123456" );
5428
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5429
+ System .out .println (re .getString ());
5430
+ assertEquals ("2" , re .getString ());
5431
+ }
5432
+
5433
+ @ Test
5434
+ public void Test_DBConnection_enableSCRAM_true_login () throws Exception {
5435
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5436
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5437
+ conn .connect (HOST ,PORT );
5438
+ conn .login ("test1" ,"123456" ,true );
5439
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5440
+ System .out .println (re .getString ());
5441
+ assertEquals ("2" , re .getString ());
5442
+ }
5443
+
5444
+ @ Test
5445
+ public void Test_DBConnection_enableSCRAM_true_login_enableEncryption () throws Exception {
5446
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5447
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5448
+ conn .connect (HOST ,PORT );
5449
+ conn .login ("test1" ,"123456" ,false );
5450
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5451
+ System .out .println (re .getString ());
5452
+ assertEquals ("2" , re .getString ());
5453
+ }
5454
+
5455
+ @ Test
5456
+ public void Test_DBConnection_enableSCRAM_true_login_function () throws Exception {
5457
+ PrepareUser_authMode ("test1" ,"123456" ,"scram" );
5458
+ DBConnection conn = new DBConnection (false , false ,false ,false ,false ,null ,true );
5459
+ conn .connect (HOST ,PORT );
5460
+ List <Entity > list = new ArrayList <>();
5461
+ list .add (new BasicString ("test1" ));
5462
+ list .add (new BasicString ("123456" ));
5463
+ conn .run ("login" ,list );
5464
+ BasicInt re = (BasicInt ) conn .run ("1+1" );
5465
+ System .out .println (re .getString ());
5466
+ assertEquals ("2" , re .getString ());
5467
+ }
5468
+
5469
+
5470
+ }
0 commit comments