@@ -127,15 +127,20 @@ public void test_SimpleDBConnectionPool_config_userId_error() throws IOException
127
127
@ Test
128
128
public void test_SimpleDBConnectionPool_config_userId_null () throws IOException , InterruptedException {
129
129
SimpleDBConnectionPoolConfig config1 = new SimpleDBConnectionPoolConfig ();
130
- config1 .setHostName (controller_host );
131
- config1 .setPort (controller_port );
130
+ config1 .setHostName (HOST );
131
+ config1 .setPort (PORT );
132
132
//config1.setUserId("admin");
133
133
//config1.setPassword("123456");
134
134
config1 .setInitialPoolSize (5 );
135
135
pool = new SimpleDBConnectionPool (config1 );
136
136
DBConnection poolEntity = pool .getConnection ();
137
- BasicBoolean re = (BasicBoolean )poolEntity .run ("isLoggedIn(`admin)" );
138
- assertEquals (false ,re .getBoolean ());
137
+ String re = null ;
138
+ try {
139
+ poolEntity .run ("getGroupList();" );
140
+ }catch (Exception ex ){
141
+ re = ex .getMessage ();
142
+ }
143
+ assertEquals (true ,re .contains ("getGroupList() => Only administrators execute function getGroupList' script: 'getGroupList();" ));
139
144
}
140
145
@ Test
141
146
public void test_SimpleDBConnectionPool_config_userId_not_admin () throws IOException , InterruptedException {
@@ -175,8 +180,13 @@ public void test_SimpleDBConnectionPool_config_password_null() throws IOExceptio
175
180
config1 .setInitialPoolSize (5 );
176
181
pool = new SimpleDBConnectionPool (config1 );
177
182
DBConnection poolEntity = pool .getConnection ();
178
- BasicBoolean re = (BasicBoolean )poolEntity .run ("isLoggedIn(`test)" );
179
- assertEquals (false ,re .getBoolean ());
183
+ String re = null ;
184
+ try {
185
+ poolEntity .run ("getGroupList();" );
186
+ }catch (Exception ex ){
187
+ re = ex .getMessage ();
188
+ }
189
+ assertEquals (true ,re .contains ("getGroupList() => Only administrators execute function getGroupList' script: 'getGroupList();" ));
180
190
}
181
191
182
192
@ Test
@@ -364,6 +374,7 @@ public void test_SimpleDBConnectionPool_config_LoadBalance_true_highAvailablity_
364
374
assertEquals (100 , pool .getTotalConnectionsCount ());
365
375
assertEquals (true , config1 .isLoadBalance ());
366
376
DBConnection poolEntity = pool .getConnection ();
377
+ poolEntity .run ("sleep(2000)" );
367
378
BasicTable re = (BasicTable ) poolEntity .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
368
379
for (int i = 0 ; i < re .rows (); i ++) {
369
380
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
@@ -388,7 +399,7 @@ public void test_SimpleDBConnectionPool_config_LoadBalance_false_highAvailablity
388
399
assertEquals (100 ,pool .getTotalConnectionsCount ());
389
400
assertEquals (false ,config1 .isLoadBalance ());
390
401
DBConnection poolEntity = pool .getConnection ();
391
- poolEntity .run ("2000" );
402
+ poolEntity .run ("sleep( 2000) " );
392
403
BasicTable re = (BasicTable ) poolEntity .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
393
404
for (int i = 0 ; i < re .rows (); i ++) {
394
405
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
@@ -443,6 +454,7 @@ public void test_SimpleDBConnectionPool_config_HighAvailability_true_LoadBalance
443
454
DBConnection poolEntity = pool .getConnection ();
444
455
controller_conn .run ("try{startDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
445
456
int port1 = port_list [1 ];
457
+ poolEntity .run ("sleep(2000)" );
446
458
BasicTable re = (BasicTable ) poolEntity .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
447
459
for (int i = 0 ; i < re .rows (); i ++) {
448
460
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
@@ -471,17 +483,19 @@ public void test_SimpleDBConnectionPool_config_HighAvailability_true_LoadBalance
471
483
config1 .setHighAvailabilitySites (ipports );
472
484
pool = new SimpleDBConnectionPool (config1 );
473
485
assertEquals (100 ,pool .getTotalConnectionsCount ());
474
- assertEquals (false ,config1 .isLoadBalance ());
486
+ assertEquals (true ,config1 .isLoadBalance ());
475
487
DBConnection poolEntity = pool .getConnection ();
476
488
controller_conn .run ("try{startDataNode('" +HOST +":" +PORT +"')}catch(ex){}" );
477
489
int port1 = port_list [1 ];
490
+ poolEntity .run ("sleep(2000)" );
478
491
BasicTable re = (BasicTable ) poolEntity .run ("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0" );
479
492
for (int i = 0 ; i < re .rows (); i ++) {
480
493
System .out .println ("port:" + re .getColumn (0 ).get (i ) + " connectionNum:" + re .getColumn (1 ).get (i ));
481
494
String port = re .getColumn (0 ).get (i ).toString ();
482
495
String connectionNum = re .getColumn (1 ).get (i ).toString ();
483
496
if (Integer .valueOf (port ) != PORT ) {
484
497
assertEquals (true , Integer .valueOf (connectionNum ) > 25 );
498
+ assertEquals (true , Integer .valueOf (connectionNum ) <= 50 );
485
499
}
486
500
}
487
501
controller_conn .close ();
@@ -1190,7 +1204,7 @@ public void test_SimpleDBConnectionPool_insert_into_memoryTable_arrayVector_all_
1190
1204
1191
1205
@ Test
1192
1206
public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType () throws IOException , InterruptedException {
1193
- config .setInitialPoolSize (10 );
1207
+ config .setInitialPoolSize (100 );
1194
1208
pool = new SimpleDBConnectionPool (config );
1195
1209
String script = "login(`admin, `123456); \n " +
1196
1210
"if(existsDatabase('dfs://test_append_type_tsdb1'))" +
@@ -1239,8 +1253,8 @@ public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType() throws IO
1239
1253
"pt.append!(data)\n " ;
1240
1254
poolEntry1 .run (script1 );
1241
1255
poolEntry1 .close ();
1242
- Thread [] threads = new Thread [10 ];
1243
- for (int i = 0 ; i < 10 ; ++i ) {
1256
+ Thread [] threads = new Thread [100 ];
1257
+ for (int i = 0 ; i < 100 ; ++i ) {
1244
1258
threads [i ] = new Thread (() -> {
1245
1259
DBConnection poolEntry2 = pool .getConnection ();
1246
1260
try {
@@ -1256,10 +1270,86 @@ public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType() throws IO
1256
1270
poolEntry2 .close ();
1257
1271
});
1258
1272
}
1259
- for (int i = 0 ; i < 10 ; i ++) {
1273
+ for (int i = 0 ; i < 100 ; i ++) {
1274
+ threads [i ].start ();
1275
+ }
1276
+ for (int i = 0 ; i < 100 ; i ++){
1277
+ threads [i ].join ();
1278
+ }
1279
+ pool .close ();
1280
+ }
1281
+ @ Test
1282
+ public void test_SimpleDBConnectionPool_insert_into_DimensionTable_all_dateType () throws IOException , InterruptedException {
1283
+ config .setInitialPoolSize (100 );
1284
+ pool = new SimpleDBConnectionPool (config );
1285
+ String script = "login(`admin, `123456); \n " +
1286
+ "if(existsDatabase('dfs://test_append_type_tsdb1'))" +
1287
+ "{ dropDatabase('dfs://test_append_type_tsdb1')} \n " +
1288
+ "n=1000;\n " +
1289
+ "t1 = table(n:0, `col1`boolv`charv`shortv`intv`longv`doublev`floatv`datev`monthv`timev`minutev`secondv`datetimev`timestampv`nanotimev`nanotimestampv`symbolv`stringv`uuidv`datehourv`ippaddrv`int128v`blobv`decimal32v`decimal64v`decimal128v, [INT, BOOL, CHAR, SHORT, INT, LONG, DOUBLE, FLOAT, DATE, MONTH, TIME, MINUTE, SECOND, DATETIME, TIMESTAMP, NANOTIME, NANOTIMESTAMP, SYMBOL, STRING, UUID, DATEHOUR, IPADDR, INT128, BLOB, DECIMAL32(3), DECIMAL64(8), DECIMAL128(10)]);\n " +
1290
+ "share t1 as tt;\n " +
1291
+ "db=database('dfs://test_append_type_tsdb1', RANGE, 0 100 200 300 400 500 600 700 800 900 1001,,'TSDB') \n " +
1292
+ "db.createTable(t1, `pt,,`col1)\n " ;
1293
+ DBConnection poolEntry = pool .getConnection ();
1294
+ poolEntry .run (script );
1295
+ poolEntry .close ();
1296
+ DBConnection poolEntry1 = pool .getConnection ();
1297
+ String script1 = "n = 1000;\n " +
1298
+ "col1 = 1..1000;\n " +
1299
+ "boolv = bool(rand([true, false, NULL], n));\n " +
1300
+ "charv = char(rand(rand(-100..100, 1000) join take(char(), 4), n));\n " +
1301
+ "shortv = short(rand(rand(-100..100, 1000) join take(short(), 4), n));\n " +
1302
+ "intv = int(rand(rand(-100..100, 1000) join take(int(), 4), n));\n " +
1303
+ "longv = long(rand(rand(-100..100, 1000) join take(long(), 4), n));\n " +
1304
+ "doublev = double(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n));\n " +
1305
+ "floatv = float(rand(rand(-100..100, 1000)*0.23 join take(float(), 4), n));\n " +
1306
+ "datev = date(rand(rand(-100..100, 1000) join take(date(), 4), n));\n " +
1307
+ "monthv = month(rand(1967.12M+rand(-100..100, 1000) join take(month(), 4), n));\n " +
1308
+ "timev = time(rand(rand(0..100, 1000) join take(time(), 4), n));\n " +
1309
+ "minutev = minute(rand(12:13m+rand(-100..100, 1000) join take(minute(), 4), n));\n " +
1310
+ "secondv = second(rand(12:13:12+rand(-100..100, 1000) join take(second(), 4), n));\n " +
1311
+ "datetimev = datetime(rand(1969.12.23+rand(-100..100, 1000) join take(datetime(), 4), n));\n " +
1312
+ "timestampv = timestamp(rand(1970.01.01T00:00:00.023+rand(-100..100, 1000) join take(timestamp(), 4), n));\n " +
1313
+ "nanotimev = nanotime(rand(12:23:45.452623154+rand(-100..100, 1000) join take(nanotime(), 4), n));\n " +
1314
+ "nanotimestampv = nanotimestamp(rand(rand(-100..100, 1000) join take(nanotimestamp(), 4), n));\n " +
1315
+ "symbolv = rand((\" syms\" +string(rand(100, 1000))) join take(string(), 4), n);\n " +
1316
+ "stringv = rand((\" stringv\" +string(rand(100, 1000))) join take(string(), 4), n);\n " +
1317
+ "uuidv = rand(rand(uuid(), 1000) join take(uuid(), 4), n);\n " +
1318
+ "datehourv = datehour(rand(datehour(1969.12.31T12:45:12)+rand(-100..100, 1000) join take(datehour(), 4), n));\n " +
1319
+ "ippaddrv = rand(rand(ipaddr(), 1000) join take(ipaddr(), 4), n);\n " +
1320
+ "int128v = rand(rand(int128(), 1000) join take(int128(), 4), n);\n " +
1321
+ "blobv = blob(string(rand((\" blob\" +string(rand(100, 1000))) join take(\" \" , 4), n)));\n " +
1322
+ "complexv = rand(complex(rand(100, 1000), rand(100, 1000)) join NULL, n);\n " +
1323
+ "pointv = rand(point(rand(100, 1000), rand(100, 1000)) join NULL, n);\n " +
1324
+ "decimal32v = decimal32(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 3);\n " +
1325
+ "decimal64v = decimal64(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 8);\n " +
1326
+ "decimal128v = decimal128(rand(rand(-100..100, 1000)*0.23 join take(double(), 4), n), 10);\n " +
1327
+ "share table(col1, boolv, charv, intv, shortv, longv, floatv, doublev, datev, monthv, timev, minutev, secondv, datetimev, timestampv, nanotimev, nanotimestampv, symbolv, stringv, uuidv, datehourv, ippaddrv, int128v, blobv, decimal32v, decimal64v, decimal128v) as data;\n " +
1328
+ "pt = loadTable(\" dfs://test_append_type_tsdb1\" ,`pt)\n " +
1329
+ "pt.append!(data)\n " ;
1330
+ poolEntry1 .run (script1 );
1331
+ poolEntry1 .close ();
1332
+ Thread [] threads = new Thread [100 ];
1333
+ for (int i = 0 ; i < 100 ; ++i ) {
1334
+ threads [i ] = new Thread (() -> {
1335
+ DBConnection poolEntry2 = pool .getConnection ();
1336
+ try {
1337
+ BasicTable re1 = (BasicTable )poolEntry2 .run ("select count(*) from loadTable(\" dfs://test_append_type_tsdb1\" ,`pt);" );
1338
+ assertEquals ("1000" ,re1 .getColumn (0 ).get (0 ).toString ());
1339
+ BasicTable re2 = (BasicTable )poolEntry2 .run ("select * from loadTable(\" dfs://test_append_type_tsdb1\" ,`pt);" );
1340
+ for (int j =0 ; j <1000 ; j ++){
1341
+ assertEquals (String .valueOf (j +1 ),re2 .getColumn (0 ).get (j ).toString ());
1342
+ }
1343
+ } catch (IOException e ) {
1344
+ throw new RuntimeException (e );
1345
+ }
1346
+ poolEntry2 .close ();
1347
+ });
1348
+ }
1349
+ for (int i = 0 ; i < 100 ; i ++) {
1260
1350
threads [i ].start ();
1261
1351
}
1262
- for (int i = 0 ; i < 10 ; i ++){
1352
+ for (int i = 0 ; i < 100 ; i ++){
1263
1353
threads [i ].join ();
1264
1354
}
1265
1355
pool .close ();
0 commit comments