Skip to content

Commit 116c9dd

Browse files
committed
AJ-559: add test case about SimpleDBConnectionPool
1 parent 876dda6 commit 116c9dd

File tree

1 file changed

+103
-13
lines changed

1 file changed

+103
-13
lines changed

test/com/xxdb/SimpleDBConnectionPoolTest.java

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,20 @@ public void test_SimpleDBConnectionPool_config_userId_error() throws IOException
127127
@Test
128128
public void test_SimpleDBConnectionPool_config_userId_null() throws IOException, InterruptedException {
129129
SimpleDBConnectionPoolConfig config1 = new SimpleDBConnectionPoolConfig();
130-
config1.setHostName(controller_host);
131-
config1.setPort(controller_port);
130+
config1.setHostName(HOST);
131+
config1.setPort(PORT);
132132
//config1.setUserId("admin");
133133
//config1.setPassword("123456");
134134
config1.setInitialPoolSize(5);
135135
pool = new SimpleDBConnectionPool(config1);
136136
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();"));
139144
}
140145
@Test
141146
public void test_SimpleDBConnectionPool_config_userId_not_admin() throws IOException, InterruptedException {
@@ -175,8 +180,13 @@ public void test_SimpleDBConnectionPool_config_password_null() throws IOExceptio
175180
config1.setInitialPoolSize(5);
176181
pool = new SimpleDBConnectionPool(config1);
177182
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();"));
180190
}
181191

182192
@Test
@@ -364,6 +374,7 @@ public void test_SimpleDBConnectionPool_config_LoadBalance_true_highAvailablity_
364374
assertEquals(100, pool.getTotalConnectionsCount());
365375
assertEquals(true, config1.isLoadBalance());
366376
DBConnection poolEntity = pool.getConnection();
377+
poolEntity.run("sleep(2000)");
367378
BasicTable re = (BasicTable) poolEntity.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0");
368379
for (int i = 0; i < re.rows(); i++) {
369380
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
388399
assertEquals(100,pool.getTotalConnectionsCount());
389400
assertEquals(false,config1.isLoadBalance());
390401
DBConnection poolEntity = pool.getConnection();
391-
poolEntity.run("2000");
402+
poolEntity.run("sleep(2000)");
392403
BasicTable re = (BasicTable) poolEntity.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0");
393404
for (int i = 0; i < re.rows(); i++) {
394405
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
443454
DBConnection poolEntity = pool.getConnection();
444455
controller_conn.run("try{startDataNode('"+HOST+":"+PORT+"')}catch(ex){}");
445456
int port1 = port_list[1];
457+
poolEntity.run("sleep(2000)");
446458
BasicTable re = (BasicTable) poolEntity.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0");
447459
for (int i = 0; i < re.rows(); i++) {
448460
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
471483
config1.setHighAvailabilitySites(ipports);
472484
pool = new SimpleDBConnectionPool(config1);
473485
assertEquals(100,pool.getTotalConnectionsCount());
474-
assertEquals(false,config1.isLoadBalance());
486+
assertEquals(true,config1.isLoadBalance());
475487
DBConnection poolEntity = pool.getConnection();
476488
controller_conn.run("try{startDataNode('"+HOST+":"+PORT+"')}catch(ex){}");
477489
int port1 = port_list[1];
490+
poolEntity.run("sleep(2000)");
478491
BasicTable re = (BasicTable) poolEntity.run("select port ,connectionNum from rpc(getControllerAlias(),getClusterPerf) where mode= 0");
479492
for (int i = 0; i < re.rows(); i++) {
480493
System.out.println("port:" + re.getColumn(0).get(i) + " connectionNum:" + re.getColumn(1).get(i));
481494
String port = re.getColumn(0).get(i).toString();
482495
String connectionNum = re.getColumn(1).get(i).toString();
483496
if(Integer.valueOf(port) != PORT) {
484497
assertEquals(true, Integer.valueOf(connectionNum) > 25);
498+
assertEquals(true, Integer.valueOf(connectionNum) <= 50);
485499
}
486500
}
487501
controller_conn.close();
@@ -1190,7 +1204,7 @@ public void test_SimpleDBConnectionPool_insert_into_memoryTable_arrayVector_all_
11901204

11911205
@Test
11921206
public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType() throws IOException, InterruptedException {
1193-
config.setInitialPoolSize(10);
1207+
config.setInitialPoolSize(100);
11941208
pool = new SimpleDBConnectionPool(config);
11951209
String script = "login(`admin, `123456); \n"+
11961210
"if(existsDatabase('dfs://test_append_type_tsdb1'))" +
@@ -1239,8 +1253,8 @@ public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType() throws IO
12391253
"pt.append!(data)\n";
12401254
poolEntry1.run(script1);
12411255
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) {
12441258
threads[i] = new Thread(() -> {
12451259
DBConnection poolEntry2 = pool.getConnection();
12461260
try {
@@ -1256,10 +1270,86 @@ public void test_SimpleDBConnectionPool_insert_into_dfs_all_dateType() throws IO
12561270
poolEntry2.close();
12571271
});
12581272
}
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++) {
12601350
threads[i].start();
12611351
}
1262-
for (int i = 0; i < 10; i++){
1352+
for (int i = 0; i < 100; i++){
12631353
threads[i].join();
12641354
}
12651355
pool.close();

0 commit comments

Comments
 (0)