未验证 提交 4eba506f 编写于 作者: B Bo Ding 提交者: GitHub

test scripts for all connector's sample codes (#11354)

* test: add test scripts

* test: change mod of test scripts to 755

* map docs-examples to container

* test: add test_python.sh

* test: add test_c.sh

* test: add test_go.sh

* test: fix test_go.sh

* test: add test_node.sh

* test: fix test_node.sh

* test: add test_rust.sh

* test: fix connect.rs

* test: fix csharp demo program

* test: add test_csharp.sh

* typo

* test: add java sample code to test
Co-authored-by: Ntangfangzhi <fztang@taosdata.com>
上级 2932408d
首先添加 [TDengine.Connector](https://www.nuget.org/packages/TDengine.Connector/) 的引用:
```bash
dotnet add package TDengine.Connector
```xml title=csharp.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.ConnectExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
```
```csharp
......
......@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
namespace TDengineExample
{
public class AsyncQuerySample
public class AsyncQueryExample
{
static void Main() {
IntPtr conn = GetConnection();
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.AsyncQueryExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.ConnectExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.InfluxDBLineExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.OptsTelnetExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.QueryExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.SQLInsertExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.StmtInsertExample</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject>TDengineExample.SubscribeDemo</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TDengine.Connector" Version="1.0.6" />
</ItemGroup>
</Project>
......@@ -2,10 +2,5 @@ module goexample
go 1.17
require github.com/taosdata/driver-go/v2 v2.0.1-0.20220222122038-174cb6c68124
require github.com/taosdata/driver-go/v2 develop
require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
)
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/taosdata/driver-go/v2 v2.0.1-0.20220222122038-174cb6c68124 h1:xDsYj1FnTBhhjMovgg67YtvTcRwICOTtUFkTxTS1LBM=
github.com/taosdata/driver-go/v2 v2.0.1-0.20220222122038-174cb6c68124/go.mod h1:ZAb4yDucTytX1Gy69F3nTRV+lEXmjkyF4J6OiYCR9NI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
......@@ -17,7 +17,7 @@ public class JSONProtocolExample {
private static void createDatabase(Connection conn) throws SQLException {
try (Statement stmt = conn.createStatement()) {
stmt.execute("CREATE DATABASE test");
stmt.execute("CREATE DATABASE IF NOT EXISTS test");
stmt.execute("USE test");
}
}
......
......@@ -27,7 +27,7 @@ public class LineProtocolExample {
private static void createDatabase(Connection conn) throws SQLException {
try (Statement stmt = conn.createStatement()) {
// the default precision is ms (microsecond), but we use us(microsecond) here.
stmt.execute("CREATE DATABASE test precision 'us'");
stmt.execute("CREATE DATABASE IF NOT EXISTS test PRECISION 'us'");
stmt.execute("USE test");
}
}
......
package com.taos.example;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class QueryExample {
static void printResult(ResultSet resultSet) throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
while (resultSet.next()) {
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String columnLabel = metaData.getColumnLabel(i);
String value = resultSet.getString(i);
System.out.printf("%s: %s\t", columnLabel, value);
}
System.out.println();
}
}
}
......@@ -53,8 +53,8 @@ public class SubscribeDemo {
subscribe.close(true); // 关闭订阅
if (connection != null)
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
} catch (SQLException throwable) {
throwable.printStackTrace();
}
}
}
......
......@@ -29,7 +29,7 @@ public class TelnetLineProtocolExample {
private static void createDatabase(Connection conn) throws SQLException {
try (Statement stmt = conn.createStatement()) {
// the default precision is ms (microsecond), but we use us(microsecond) here.
stmt.execute("CREATE DATABASE test precision 'us'");
stmt.execute("CREATE DATABASE IF NOT EXISTS test precision 'us'");
stmt.execute("USE test");
}
}
......
package com.taos.test;
import com.taos.example.*;
import org.junit.FixMethodOrder;
import org.junit.Test;
import java.sql.*;
@FixMethodOrder
public class TestAll {
private String[] args = new String[]{};
public void dropDB(String dbName) throws SQLException {
String jdbcUrl = "jdbc:TAOS://localhost:6030?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbName);
}
}
}
public void insertData() throws SQLException {
String jdbcUrl = "jdbc:TAOS://localhost:6030?user=root&password=taosdata";
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
try (Statement stmt = conn.createStatement()) {
String sql = "INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 14:38:05.000',10.30000,219,0.31000)\n" +
" power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 15:38:15.000',12.60000,218,0.33000)\n" +
" power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 15:38:16.800',12.30000,221,0.31000)\n" +
" power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES('2018-10-03 15:38:16.650',10.30000,218,0.25000)\n" +
" power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 15:38:05.500',11.80000,221,0.28000)\n" +
" power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 15:38:16.600',13.40000,223,0.29000)\n" +
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:05.000',10.80000,223,0.29000)\n" +
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:06.000',10.80000,223,0.29000)\n" +
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:07.000',10.80000,223,0.29000)\n" +
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:08.500',11.50000,221,0.35000)";
stmt.execute(sql);
}
}
}
@Test
public void testJNIConnect() throws SQLException {
JNIConnectExample.main(args);
}
@Test
public void testRestConnect() throws SQLException {
RESTConnectExample.main(args);
}
@Test
public void testRestInsert() throws SQLException {
dropDB("power");
RestInsertExample.main(args);
}
@Test
public void testQuery() throws SQLException {
RestQueryExample.main(args);
}
@Test
public void testStmtInsert() throws SQLException {
dropDB("power");
StmtInsertExample.main(args);
}
@Test
public void testSubscribe() {
Thread thread = new Thread(()-> {
try {
Thread.sleep(1000);
insertData();
} catch (SQLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
});
thread.start();
SubscribeDemo.main(args);
}
@Test
public void testSchemaless() throws SQLException {
LineProtocolExample.main(args);
TelnetLineProtocolExample.main(args);
JSONProtocolExample.main(args);
}
}
......@@ -12,7 +12,8 @@ fn taos_connect() -> Result<Taos, Error> {
.connect()
}
fn main() {
#[tokio::main]
async fn main() {
#[allow(unused_variables)]
let taos = taos_connect().expect("connect error");
println!("Connected")
......
#!/bin/bash
set -e
taosd >> /dev/null 2>&1 &
taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/c
# 1
gcc connect_example.c -o connect_example -ltaos
./connect_example
# 2
taos -s "drop database if exists power"
gcc -o insert_example insert_example.c -ltaos
./insert_example
# 3
taos -s "drop database if exists power"
gcc -o stmt_example stmt_example.c -ltaos
./stmt_example
# 4
taos -s "drop database if exists power"
gcc -o multi_bind_example multi_bind_example.c -ltaos
./multi_bind_example
# 5
gcc -o query_example query_example.c -ltaos
./query_example
# 6
taos -s "drop database if exists test"
gcc -o line_example line_example.c -ltaos
./line_example
# 7
taos -s "drop database if exists test"
gcc -o telnet_line_example telnet_line_example.c -ltaos
./telnet_line_example
# 8
taos -s "drop database if exists test"
gcc -o json_protocol_example json_protocol_example.c -ltaos
./json_protocol_example
#!/bin/bash
set -e
pgrep taosd || taosd >> /dev/null 2>&1 &
pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/csharp
dotnet run --project connect.csproj
taos -s "drop database if exists power"
dotnet run --project sqlinsert.csproj
dotnet run --project query.csproj
dotnet run --project asyncquery.csproj
taos -s "drop database if exists power"
dotnet run --project stmtinsert.csproj
taos -s "drop database if exists test"
dotnet run --project influxdbline.csproj
taos -s "drop database if exists test"
dotnet run --project optstelnet.csproj
taos -s "drop database if exists test"
dotnet run --project optsjson.csproj
#!/bin/bash
set -e
taosd >> /dev/null 2>&1 &
taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/go
go run ./connect/restexample/main.go
taos -s "drop database if exists power"
go run ./insert/sql/main.go
taos -s "drop database if exists power"
go run ./insert/stmt/main.go
taos -s "drop database if exists test"
go run ./insert/line/main.go
taos -s "drop database if exists test"
go run ./insert/telnet/main.go
taos -s "drop database if exists test"
go run ./insert/json/main.go
go run ./query/sync/main.go
#!/bin/bash
set -e
taosd >> /dev/null 2>&1 &
taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/java
mvn test
\ No newline at end of file
#!/bin/bash
set -e
pgrep taosd || taosd >> /dev/null 2>&1 &
pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/node
npm install
cd nativeexample
node connect.js
taos -s "drop database if exists power"
node insert_example.js
node query_example.js
taos -s "drop database if exists power"
node param_bind_example.js
taos -s "drop database if exists power"
node multi_bind_example.js
taos -s "drop database if exists test"
node influxdb_line_example.js
taos -s "drop database if exists test"
node opentsdb_telnet_example.js
taos -s "drop database if exists test"
node opentsdb_json_example.js
#!/bin/bash
set -e
taosd >> /dev/null 2>&1 &
taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/python
# 1
python3 connect_exmaple.py
# 2
taos -s "drop database if exists power"
python3 native_insert_example.py
# 3
taos -s "drop database power"
python3 bind_param_example.py
# 4
taos -s "drop database power"
python3 multi_bind_example.py
# 5
python3 query_example.py
# 6
python3 async_query_example.py
# 7
taos -s "drop database if exists test"
python3 line_protocol_example.py
# 8
taos -s "drop database test"
python3 telnet_line_protocol_example.py
# 9
taos -s "drop database test"
python3 json_protocol_example.py
# 10
python3 subscribe_demo.py
#!/bin/bash
set -e
pgrep taosd || taosd >> /dev/null 2>&1 &
pgrep taosadapter || taosadapter >> /dev/null 2>&1 &
cd ../../docs-examples/rust
cargo run -p nativeexample --example connect
cargo run -p restexample --example connect
taos -s "drop database if exists power"
cargo run -p restexample --example insert_example
cargo run -p restexample --example query_example
taos -s "drop database if exists power"
cargo run -p nativeexample --example stmt_example
taos -s "drop database if exists test"
cargo run -p schemalessexample --example influxdb_line_example
taos -s "drop database if exists test"
cargo run -p schemalessexample --example opentsdb_telnet_example
taos -s "drop database if exists test"
cargo run -p schemalessexample --example opentsdb_json_example
\ No newline at end of file
......@@ -95,6 +95,7 @@ docker run \
-v $REPDIR/packaging/cfg/taos.cfg:/etc/taos/taos.cfg:ro \
-v $REPDIR/packaging:$CONTAINER_TESTDIR/packaging:ro \
-v $REPDIR/README.md:$CONTAINER_TESTDIR/README.md:ro \
-v $REPDIR/docs-examples:$CONTAINER_TESTDIR/docs-examples \
-v $REPDIR/src/connector/python/taos:/usr/local/lib/python3.8/site-packages/taos:ro \
-e LD_LIBRARY_PATH=/home/debug/build/lib:/home/debug/build/lib64 \
--rm --ulimit core=-1 taos_test:v1.0 $CONTAINER_TESTDIR/tests/parallel_test/run_case.sh -d "$exec_dir" -c "$cmd" $timeout_param
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册