Skip to content

Commit d1eeb3f

Browse files
author
chengyitian
committed
Merge remote-tracking branch 'origin/release3.00.2.5' into release3.00.2.5
2 parents 58eb321 + 07d8c03 commit d1eeb3f

11 files changed

+507
-12
lines changed

test/com/xxdb/ConnectionPoolTest.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
import java.time.LocalDate;
1616
import java.time.LocalDateTime;
1717
import java.util.ArrayList;
18+
import java.util.Arrays;
1819
import java.util.List;
1920
import java.util.ResourceBundle;
2021

22+
import static com.xxdb.Prepare.PrepareUser_authMode;
2123
import static org.junit.Assert.assertEquals;
2224

2325
public class ConnectionPoolTest {
@@ -130,6 +132,45 @@ public void test_DBConnectionPool_count_1() throws IOException {
130132
pool1.shutdown();
131133
}
132134

135+
@Test
136+
public void test_DBConnectionPool_user_authMode_scream() throws Exception {
137+
PrepareUser_authMode("scramUser","123456","scram");
138+
conn.run("if(existsDatabase(\"dfs://testArrayVector\")){\n" +
139+
"dropDatabase(\"dfs://testArrayVector\")\n" +
140+
"}\n" +
141+
"db=database(\"dfs://testArrayVector\",RANGE,int(1..10),,\"TSDB\")\n" +
142+
"t = table(1000000:0,`sym`tradeDate`volume`valueTrade,[INT,DATETIME,INT[],DOUBLE])\n" +
143+
"pt = db.createPartitionedTable(t,`pt,`sym,,`tradeDate)");
144+
conn.run("grant(\"scramUser\", DB_OWNER, \"dfs://test*\");\n grant(\"scramUser\", DB_MANAGE);\n grant(\"scramUser\", TABLE_READ,\"*\");\n grant(\"scramUser\", TABLE_WRITE,\"dfs://testArrayVector/pt\");");
145+
ExclusiveDBConnectionPool pool = new ExclusiveDBConnectionPool(HOST,PORT,"scramUser","123456",3,false,false);
146+
PartitionedTableAppender appender = new PartitionedTableAppender("dfs://testArrayVector","pt","sym",pool);
147+
List<String> colNames = new ArrayList<>();
148+
colNames.add("sym");
149+
colNames.add("tradesDate");
150+
colNames.add("volume");
151+
colNames.add("valueTrade");
152+
List<Vector> cols = new ArrayList<>();
153+
BasicIntVector biv = new BasicIntVector(new int[]{1,2,3});
154+
cols.add(biv);
155+
BasicDateTimeVector bdtv = new BasicDateTimeVector(new int[]{10,20,30});
156+
cols.add(bdtv);
157+
List<Vector> value = new ArrayList<>();
158+
value.add(new BasicIntVector(new int[]{1,2,3}));
159+
value.add(new BasicIntVector(new int[]{4,5,6,7,8}));
160+
value.add(new BasicIntVector(new int[]{9,10,11,13,17,21}));
161+
BasicArrayVector bav = new BasicArrayVector(value);
162+
cols.add(bav);
163+
BasicDoubleVector bdv = new BasicDoubleVector(new double[]{1.1,3.6,7.9});
164+
cols.add(bdv);
165+
BasicTable bt = new BasicTable(colNames,cols);
166+
int x = appender.append(bt);
167+
BasicTable res = (BasicTable) conn.run("select * from loadTable(\"dfs://testArrayVector\",\"pt\");");
168+
assertEquals(3,res.rows());
169+
assertEquals(Entity.DATA_TYPE.DT_INT_ARRAY,res.getColumn(2).getDataType());
170+
System.out.println(res.getColumn(2).getString());
171+
pool.shutdown();
172+
}
173+
133174

134175
@Test
135176
public void testHashHashstring() throws Exception {
@@ -2529,5 +2570,53 @@ public void Test_PartitionedTableAppender_iotAnyVector_big_data() throws Excepti
25292570
assertEquals("9000000", bt10.getColumn(0).getString(0));
25302571
pool.shutdown();
25312572
}
2573+
2574+
//@Test
2575+
public void Test_PartitionedTableAppender_iotAnyVector_1() throws Exception {
2576+
String script = "if(existsDatabase(\"dfs://testIOT_allDateType1\")) dropDatabase(\"dfs://testIOT_allDateType1\")\n" +
2577+
" create database \"dfs://testIOT_allDateType1\" partitioned by RANGE(100000*(0..10)),RANGE(2020.01.01 2022.01.01 2038.01.01), engine='IOTDB'\n" +
2578+
" create table \"dfs://testIOT_allDateType1\".\"pt\"(\n" +
2579+
" deviceId INT,\n" +
2580+
" timestamp TIMESTAMP,\n" +
2581+
" location SYMBOL,\n" +
2582+
" value IOTANY,\n" +
2583+
" )\n" +
2584+
"partitioned by deviceId, timestamp,\n" +
2585+
"sortColumns=[`deviceId, `location, `timestamp],\n" +
2586+
"latestKeyCache=true;\n" +
2587+
"pt = loadTable(\"dfs://testIOT_allDateType1\",\"pt\");\n" ;
2588+
conn.run(script);
2589+
BasicByte bbyte = new BasicByte((byte) 127);
2590+
BasicShort bshort = new BasicShort((short) 0);
2591+
BasicInt bint = new BasicInt(-4);
2592+
BasicLong blong = new BasicLong(-4);
2593+
BasicBoolean bbool = new BasicBoolean(false);
2594+
BasicFloat bfloat = new BasicFloat((float) 1.99);
2595+
BasicDouble bdouble = new BasicDouble(1.99);
2596+
BasicString bsting = new BasicString("最新特殊字符:!@#$%^&*()_++_}{|{\":>?</.,';\\][=-0987654321`~asdQWHH这个点做工&&,。、te长qqa");
2597+
Scalar[] scalar = new Scalar[]{bbyte, bshort, bint, blong, bbool, bfloat, bdouble, bsting, bdouble, bsting};
2598+
BasicIotAnyVector BIV = new BasicIotAnyVector(scalar);
2599+
BasicIntVector deviceId = new BasicIntVector(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
2600+
2601+
BasicAnyVector BIV1 = new BasicAnyVector(10);
2602+
for (int i = 0; i < 10; i++) {
2603+
BIV1.set(i, new BasicInt(i));
2604+
}
2605+
2606+
BasicTimestampVector timestamp = new BasicTimestampVector(new long[]{1577836800001l, 1577836800002l, 1577836800003l, 1577836800004l, 1577836800005l, 1577836800006l, 1577836800007l, 1577836800008l, 1577836800009l, 1577836800010l});
2607+
BasicSymbolVector location = new BasicSymbolVector(Arrays.asList(new String[]{"d1d", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10"}));
2608+
2609+
List<Entity> args = Arrays.asList(deviceId, timestamp, location, BIV);
2610+
List<String> colNames = Arrays.asList("deviceId", "timestamp", "location", "BIV");
2611+
List<Vector> cols = Arrays.asList(deviceId, timestamp, location, BIV);
2612+
BasicTable table = new BasicTable(colNames, cols);
2613+
2614+
ExclusiveDBConnectionPool pool = new ExclusiveDBConnectionPool(HOST,PORT,"admin","123456",3,false,false);
2615+
PartitionedTableAppender appender = new PartitionedTableAppender("dfs://testIOT_allDateType1","pt","deviceId", pool);
2616+
appender.append(table);
2617+
BasicTable bt10 = (BasicTable) conn.run("select count(*) from loadTable(\"dfs://testIOT_allDateType1\",`pt);");
2618+
assertEquals("10", bt10.getColumn(0).getString(0));
2619+
pool.shutdown();
2620+
}
25322621
}
25332622

test/com/xxdb/DBConnectionTest.java

Lines changed: 177 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import static com.xxdb.Prepare.*;
2525
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.*;
2628
import static java.lang.Thread.sleep;
2729
import static org.junit.Assert.*;
2830

@@ -606,7 +608,7 @@ public void testIntScalar() throws Exception {
606608
scalar.setNull();
607609
assertTrue(scalar.isNull());
608610
assertEquals(Entity.DATA_CATEGORY.INTEGRAL,scalar.getDataCategory());
609-
assertEquals(Entity.DATA_TYPE.DT_INT,scalar.getDataType());
611+
assertEquals(DT_INT,scalar.getDataType());
610612
assertEquals(-1,scalar.hashBucket(1));
611613
assertEquals(-2147483648,scalar.hashCode());
612614
assertEquals("null",scalar.getJsonString());
@@ -758,7 +760,7 @@ public void testSecondScalar() throws Exception {
758760
scalar.setNull();
759761
assertTrue(scalar.isNull());
760762
assertEquals(Entity.DATA_CATEGORY.TEMPORAL,scalar.getDataCategory());
761-
assertEquals(Entity.DATA_TYPE.DT_SECOND,scalar.getDataType());
763+
assertEquals(DT_SECOND,scalar.getDataType());
762764
assertEquals(-1,scalar.hashBucket(1));
763765
assertEquals(-2147483648,scalar.hashCode());
764766
assertEquals("null",scalar.getJsonString());
@@ -887,7 +889,7 @@ public void testStringScalar() throws Exception {
887889
scalar.setNull();
888890
assertTrue(scalar.isNull());
889891
assertEquals(Entity.DATA_CATEGORY.LITERAL,scalar.getDataCategory());
890-
assertEquals(Entity.DATA_TYPE.DT_STRING,scalar.getDataType());
892+
assertEquals(DT_STRING,scalar.getDataType());
891893
assertEquals(0,scalar.hashBucket(1));
892894
assertEquals(0,scalar.hashCode());
893895
assertEquals("null",scalar.getJsonString());
@@ -1767,7 +1769,7 @@ public void testDictionaryUpload() throws IOException {
17671769
public void testDictionaryUpload_1() throws IOException {
17681770
DBConnection conn = new DBConnection();
17691771
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);
17711773
Map<String,Entity> data = new HashMap<>();
17721774
data.put("bd",bd);
17731775
conn.upload(data);
@@ -1837,7 +1839,7 @@ public void testAnyVector_Duration_Upload() throws Exception {
18371839
@Test
18381840
public void testSet() throws IOException {
18391841
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());
18411843
assertEquals(Entity.DATA_FORM.DF_SET, result.getDataForm());
18421844

18431845
}
@@ -1849,7 +1851,7 @@ public void testSetUpload() throws IOException {
18491851
map.put("set", set);
18501852
conn.upload(map);
18511853
Entity sets = conn.run("set");
1852-
assertEquals(Entity.DATA_TYPE.DT_INT, sets.getDataType());
1854+
assertEquals(DT_INT, sets.getDataType());
18531855
assertEquals(Entity.DATA_FORM.DF_SET, sets.getDataForm());
18541856
}
18551857

@@ -3919,6 +3921,7 @@ public void test_tryUpload() throws IOException{
39193921
@Test
39203922
public void test_SSL() throws Exception {
39213923
DBConnection conn = new DBConnection(false,true);
3924+
conn.connect(HOST,PORT,"admin","123456");
39223925
assertTrue(conn.connect(HOST,PORT,"admin","123456"));
39233926
HashMap<String,Entity> map = new HashMap<>();
39243927
map.put("x",conn.run("x=[1 3 6 10];"));
@@ -5154,8 +5157,9 @@ public void test_DBConnection_run_parallelism_1() throws IOException {
51545157

51555158
DBConnection conn1 = new DBConnection();
51565159
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);
51585161
Assert.assertEquals("5",re1.getColumn(6).get(0).getString());
5162+
System.out.println(re1.getColumn(5).get(0).getString());
51595163
}
51605164
@Test//api设置的parallelism大于server的setMaxJobParallelism
51615165
public void test_DBConnection_run_parallelism_2() throws IOException {
@@ -5278,10 +5282,10 @@ public void test_not_login_run_fuction_not_support() throws Exception {
52785282
}
52795283
assertEquals(true, re.contains("Login is required for script execution with client authentication enabled. RefId: S04009. function: getAllDBs"));
52805284
}
5281-
@Test //isClientAuth开启
5285+
//@Test //isClientAuth开启
52825286
public void test_Connect_enableHighAvailability_true() throws IOException {
52835287
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"});
52855289
}
52865290

52875291
@Test
@@ -5300,4 +5304,167 @@ public void progress(String message) {
53005304
Entity print = db.run("print", entity, 3, 3, 0, true, listener);
53015305
System.out.println("print:" + print.getString());
53025306
}
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

Comments
 (0)