From 800b878f9969577bc9fddf3a25ee4257c758090e Mon Sep 17 00:00:00 2001 From: Bo Ding Date: Thu, 14 Apr 2022 19:36:21 +0800 Subject: [PATCH] test: add test scripts for document sample code to CI task (#11482) * docs: add R example source code * test: check if RJDBC was installed * test: add R test scripts * test: chmod of test_R.sh * test: fix test_go.sh; add R sample to document * test: add test scripts to cases.task * test: fix errors caused by tset_python.sh and test_java.sh * test: fix test_python.sh * test: modify java test case and improve opentsdb-json.mdx * test: fix test_R.sh --- docs-cn/04-connect/_connect_r.mdx | 12 +----------- docs-cn/06-insert-data/03-opentsdb-telnet.mdx | 2 +- docs-cn/06-insert-data/04-opentsdb-json.mdx | 4 +++- docs-cn/08-advance-feature/02-subscribe.mdx | 4 ++-- docs-examples/R/connect_native.r | 16 ++++++++++++++++ docs-examples/R/connect_rest.r | 12 ++++++++++++ .../src/test/java/com/taos/test/TestAll.java | 10 ++++------ docs-examples/node/package.json | 2 +- docs-examples/python/connect_exmaple.py | 1 - tests/docs-examples-test/test_R.sh | 14 ++++++++++++++ tests/docs-examples-test/test_go.sh | 2 ++ tests/docs-examples-test/test_node.sh | 5 ++++- tests/docs-examples-test/test_python.sh | 1 + tests/parallel_test/cases.task | 8 ++++++++ 14 files changed, 69 insertions(+), 24 deletions(-) create mode 100644 docs-examples/R/connect_native.r create mode 100644 docs-examples/R/connect_rest.r create mode 100755 tests/docs-examples-test/test_R.sh diff --git a/docs-cn/04-connect/_connect_r.mdx b/docs-cn/04-connect/_connect_r.mdx index 076cbf6670..68ab515136 100644 --- a/docs-cn/04-connect/_connect_r.mdx +++ b/docs-cn/04-connect/_connect_r.mdx @@ -1,13 +1,3 @@ ```r -> library("DBI") -> library("rJava") -> library("RJDBC") -> driver_path = "C:/TDengine/connector/jdbc/taos-jdbcdriver-2.0.37-dist.jar" -> driver = JDBC("com.taosdata.jdbc.TSDBDriver", driver_path) -> conn = dbConnect(driver, "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata") -> dbGetQuery(conn, "SELECT server_version()") - server_version() -1 2.4.0.12 -> dbDisconnect(conn) -[1] TRUE +{{#include docs-examples/R/connect_native.r:demo}} ``` \ No newline at end of file diff --git a/docs-cn/06-insert-data/03-opentsdb-telnet.mdx b/docs-cn/06-insert-data/03-opentsdb-telnet.mdx index 576fe4fdc6..7efb3e1cf9 100644 --- a/docs-cn/06-insert-data/03-opentsdb-telnet.mdx +++ b/docs-cn/06-insert-data/03-opentsdb-telnet.mdx @@ -24,7 +24,7 @@ OpentsDB 行协议同样采用一行字符串来表示一行数据。OpentsDB - metric 将作为超级表名。 - timestamp 本行数据对应的时间戳。根据时间戳的长度自动识别时间精度。支持秒和毫秒两种时间精度 - value 度量值,必须为一个数值。对应的列名也是 “value”。 -- 最后一部分是标签集, 用空格分隔不同标签。 +- 最后一部分是标签集, 用空格分隔不同标签, 所有标签自动转化为 nchar 数据类型; 例如: diff --git a/docs-cn/06-insert-data/04-opentsdb-json.mdx b/docs-cn/06-insert-data/04-opentsdb-json.mdx index 1ee8235bbf..0767dba0c1 100644 --- a/docs-cn/06-insert-data/04-opentsdb-json.mdx +++ b/docs-cn/06-insert-data/04-opentsdb-json.mdx @@ -42,10 +42,12 @@ OpentsDB JSON 格式协议采用一个 JSON 字符串表示一行或多行数据 与 OpentsDB 行协议类似, metric 将作为超级表名, timestamp 表示时间戳,value 表示度量值, tags 表示标签集。 + 参考[OpenTSDB HTTP API文档](http://opentsdb.net/docs/build/html/api_http/put.html)。 :::note -TDengine 只接收 JSON **数组格式**的字符串,即使一行数据也需要转换成数组形式。 +- 对于 JSON 格式协议,TDengine 并不会自动把所有标签转成 nchar 类型, 字符串将将转为 nchar 类型, 数值将同样转换为 double 类型。 +- TDengine 只接收 JSON **数组格式**的字符串,即使一行数据也需要转换成数组形式。 ::: diff --git a/docs-cn/08-advance-feature/02-subscribe.mdx b/docs-cn/08-advance-feature/02-subscribe.mdx index b4fc63bdf3..f9952edf56 100644 --- a/docs-cn/08-advance-feature/02-subscribe.mdx +++ b/docs-cn/08-advance-feature/02-subscribe.mdx @@ -206,7 +206,7 @@ Query OK, 5 row(s) in set (0.004896s) - + {/* @@ -223,7 +223,7 @@ Query OK, 5 row(s) in set (0.004896s) - + */} ### 运行示例程序 diff --git a/docs-examples/R/connect_native.r b/docs-examples/R/connect_native.r new file mode 100644 index 0000000000..18c142872b --- /dev/null +++ b/docs-examples/R/connect_native.r @@ -0,0 +1,16 @@ +if (! "RJDBC" %in% installed.packages()[, "Package"]) { + install.packages('RJDBC', repos='http://cran.us.r-project.org') +} + +# ANCHOR: demo +library("DBI") +library("rJava") +library("RJDBC") + +args<- commandArgs(trailingOnly = TRUE) +driver_path = args[1] # path to jdbc-driver for example: "/root/taos-jdbcdriver-2.0.37-dist.jar" +driver = JDBC("com.taosdata.jdbc.TSDBDriver", driver_path) +conn = dbConnect(driver, "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata") +dbGetQuery(conn, "SELECT server_version()") +dbDisconnect(conn) +# ANCHOR_END: demo \ No newline at end of file diff --git a/docs-examples/R/connect_rest.r b/docs-examples/R/connect_rest.r new file mode 100644 index 0000000000..5ceec572fc --- /dev/null +++ b/docs-examples/R/connect_rest.r @@ -0,0 +1,12 @@ +if (! "RJDBC" %in% installed.packages()[, "Package"]) { + install.packages('RJDBC', repos='http://cran.us.r-project.org') +} + +library("DBI") +library("rJava") +library("RJDBC") +driver_path = "/home/debug/build/lib/taos-jdbcdriver-2.0.38-dist.jar" +driver = JDBC("com.taosdata.jdbc.rs.RestfulDriver", driver_path) +conn = dbConnect(driver, "jdbc:TAOS-RS://localhost:6041?user=root&password=taosdata") +dbGetQuery(conn, "SELECT server_version()") +dbDisconnect(conn) \ No newline at end of file diff --git a/docs-examples/java/src/test/java/com/taos/test/TestAll.java b/docs-examples/java/src/test/java/com/taos/test/TestAll.java index 41d9a9fa20..92fe14a49d 100644 --- a/docs-examples/java/src/test/java/com/taos/test/TestAll.java +++ b/docs-examples/java/src/test/java/com/taos/test/TestAll.java @@ -39,7 +39,6 @@ public class TestAll { } } - @Test public void testJNIConnect() throws SQLException { JNIConnectExample.main(args); @@ -54,10 +53,6 @@ public class TestAll { public void testRestInsert() throws SQLException { dropDB("power"); RestInsertExample.main(args); - } - - @Test - public void testQuery() throws SQLException { RestQueryExample.main(args); } @@ -70,7 +65,7 @@ public class TestAll { @Test public void testSubscribe() { - Thread thread = new Thread(()-> { + Thread thread = new Thread(() -> { try { Thread.sleep(1000); insertData(); @@ -88,6 +83,9 @@ public class TestAll { public void testSchemaless() throws SQLException { LineProtocolExample.main(args); TelnetLineProtocolExample.main(args); + // for json protocol, tags may be double type. but for telnet protocol tag must be nchar type. + // To avoid type mismatch, we delete database test. + dropDB("test"); JSONProtocolExample.main(args); } } diff --git a/docs-examples/node/package.json b/docs-examples/node/package.json index 6790099bcf..f56196d2e5 100644 --- a/docs-examples/node/package.json +++ b/docs-examples/node/package.json @@ -4,7 +4,7 @@ "main": "index.js", "license": "MIT", "dependencies": { - "td2.0-connector": "^2.0.11", + "td2.0-connector": "^2.0.12", "td2.0-rest-connector": "^1.0.0" } } diff --git a/docs-examples/python/connect_exmaple.py b/docs-examples/python/connect_exmaple.py index 5d57ae6815..719af79fd1 100644 --- a/docs-examples/python/connect_exmaple.py +++ b/docs-examples/python/connect_exmaple.py @@ -5,7 +5,6 @@ def test_connection(): # all parameters are optional. # if database is specified, # then it must exist. - # we use database log here, because it always exists. conn = taos.connect(host="localhost", port=6030, user="root", diff --git a/tests/docs-examples-test/test_R.sh b/tests/docs-examples-test/test_R.sh new file mode 100755 index 0000000000..8d2db4546f --- /dev/null +++ b/tests/docs-examples-test/test_R.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +pgrep taosd || taosd >> /dev/null 2>&1 & +pgrep taosadapter || taosadapter >> /dev/null 2>&1 & + +cd ../../docs-examples/R + +jar_path=`find ../../../debug/build -name taos-jdbcdriver-*-dist.jar` +echo jar_path=$jar_path +R -f connect_native.r --args $jar_path +# R -f connect_rest.r --args $jar_path # bug 14704 + diff --git a/tests/docs-examples-test/test_go.sh b/tests/docs-examples-test/test_go.sh index 8d71311719..d959d8c1ed 100755 --- a/tests/docs-examples-test/test_go.sh +++ b/tests/docs-examples-test/test_go.sh @@ -7,6 +7,8 @@ taosadapter >> /dev/null 2>&1 & cd ../../docs-examples/go +go mod tidy + go run ./connect/restexample/main.go taos -s "drop database if exists power" diff --git a/tests/docs-examples-test/test_node.sh b/tests/docs-examples-test/test_node.sh index 0437a501f3..14aab236f9 100755 --- a/tests/docs-examples-test/test_node.sh +++ b/tests/docs-examples-test/test_node.sh @@ -8,8 +8,11 @@ pgrep taosadapter || taosadapter >> /dev/null 2>&1 & cd ../../docs-examples/node npm install +cd restexample; -cd nativeexample +node connect.js + +cd ../nativeexample node connect.js diff --git a/tests/docs-examples-test/test_python.sh b/tests/docs-examples-test/test_python.sh index 6fdb894c98..e145f1bd6d 100755 --- a/tests/docs-examples-test/test_python.sh +++ b/tests/docs-examples-test/test_python.sh @@ -8,6 +8,7 @@ taosadapter >> /dev/null 2>&1 & cd ../../docs-examples/python # 1 +taos -s "create database if not exists log" python3 connect_exmaple.py # 2 diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 732089906a..ca539f5bff 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -151,6 +151,7 @@ 48,,script,./test.sh -f general/parser/nestquery.sim 48,,script,./test.sh -f general/parser/col_arithmetic_operation.sim 48,,pytest,python3 test.py -f query/queryStateWindow.py +41,,docs-examples-test,./test_csharp.sh 47,,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestInsertWithJsonSml-illegalData.py 47,,script,./test.sh -f unique/stable/balance_replica1.sim 47,,script,./test.sh -f unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim @@ -172,6 +173,7 @@ 42,,script,./test.sh -f unique/dnode/monitor_bug.sim 42,,script,./test.sh -f unique/arbitrator/sync_replica3_alterTable_drop.sim 42,,script,./test.sh -f general/wal/kill.sim +41,,docs-examples-test,./test_c.sh 41,,script,./test.sh -f unique/dnode/lossdata.sim 41,,script,./test.sh -f unique/arbitrator/sync_replica3_dropDb.sim 41,,script,./test.sh -f unique/arbitrator/sync_replica2_alterTable_drop.sim @@ -196,6 +198,7 @@ 37,,script,./test.sh -f unique/arbitrator/offline_replica2_alterTable_online.sim 37,,script,./test.sh -f general/table/delete_reuse1.sim 37,,script,./test.sh -f general/db/delete_reuse2.sim +36,,docs-examples-test,./test_rust.sh 36,,script,./test.sh -f unique/stable/replica3_vnode3.sim 36,,script,./test.sh -f unique/stable/dnode2_stop.sim 36,,script,./test.sh -f unique/arbitrator/sync_replica2_alterTable_add.sim @@ -326,6 +329,7 @@ 19,,pytest,python3 test.py -f import_merge/importDataHPO.py 19,,pytest,python3 test.py -f import_merge/importCSV.py 19,,pytest,python3 test.py -f functions/function_operations.py -r 1 +18,,docs-examples-test,./test_java.sh 18,,script,./test.sh -f unique/stable/replica3_dnode6.sim 18,,script,./test.sh -f general/vector/table_field.sim 18,,script,./test.sh -f general/vector/single.sim @@ -554,6 +558,7 @@ 11,,pytest,python3 test.py -f import_merge/importLastHPO.py 11,,pytest,python3 test.py -f import_merge/importDataTO.py 11,,pytest,python3 test.py -f import_merge/importBlock1Sub.py +10,,docs-examples-test,./test_python.sh 10,,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestInsertWithJsonStmt-otherPara.py 10,,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestInsertWithJsonStmt.py 10,,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestInsertWithJson-autoCreate.py @@ -564,6 +569,7 @@ 10,,pytest,python3 testCompress.py 10,,pytest,python3 test.py -f client/client.py 10,,script,./test.sh -f general/compute/scalar_pow.sim +9,,docs-examples-test,./test_go.sh 9,,script,./test.sh -f general/parser/alter1.sim 9,,script,./test.sh -f general/db/delete.sim 9,,pytest,python3 test.py -f tools/taosdemoTestLimitOffset.py @@ -587,6 +593,7 @@ 8,,develop-test,python3 ./test.py -f 5-taos-tools/taosdump/taosdumpTestTypeInt.py 8,,develop-test,python3 ./test.py -f 5-taos-tools/taosdump/taosdumpTestTypeDouble.py 8,,pytest,python3 test.py -f update/update2.py +7,,docs-examples-test,./test_node.sh 7,,system-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestInsertWithJsonSml-otherPara.py 7,,pytest,python3 test.py -f tools/taosdumpTest2.py 7,,pytest,python3 test.py -f tools/taosdemoTestdatatype.py @@ -806,6 +813,7 @@ 3,,develop-test,python3 ./test.py -f 2-query/function_tail.py 2,,develop-test,python3 ./test.py -f 2-query/function_unique.py 2,,develop-test,python3 ./test.py -f 2-query/function_hll.py +1,,docs-examples-test, ./test_R.sh 1,,develop-test,python3 ./test.py -f 2-query/function_state.py 1,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/demo.py 3,,develop-test,python3 ./test.py -f 5-taos-tools/taosdump/taosdumpTestInspect.py -- GitLab