提交 41ecacf1 编写于 作者: H huolibo

[feature]<TD-10424> add test examples

上级 8c90553a
package com.taosdata.jdbc;
import com.alibaba.fastjson.JSONObject;
import org.junit.*;
import java.sql.*;
import java.util.Random;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
public class OpenTSDBMigrateTest {
private static final String host = "127.0.0.1";
private static final String dbname = "opentsdb_migrate_test";
private static final Random random = new Random(System.currentTimeMillis());
private static TSDBConnection conn;
@Test
public void telnetPut() {
System.out.println("test");
try {
public void telnetPut() throws SQLException {
// given
String[] lines = new String[]{"stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
String[] lines = new String[]{
"stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\""};
// // when
"stb0.2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\" id=\"name\""
};
// when
conn.getConnector().insertTelnetLines(lines);
// then
// long actual = rs.getLong(1);
// Assert.assertEquals(ms, actual);
// actual = rs.getLong("ts");
// Assert.assertEquals(ms, actual);
} catch (SQLException e) {
e.printStackTrace();
Set<String> collect = Arrays.stream(lines)
.map(String::trim).filter(s -> s.length() > 0)
.map(s -> s.split("\\s+")[0].replaceAll("\\.", "_"))
.collect(Collectors.toSet());
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("show stables");
Assert.assertNotNull(rs);
ResultSetMetaData metaData = rs.getMetaData();
Assert.assertTrue(metaData.getColumnCount() > 0);
while (rs.next()) {
Assert.assertTrue(collect.contains(rs.getString(1)));
}
rs.close();
statement.close();
}
@Before
public void before() {
@Test
public void jsonPut() throws SQLException {
// given
String json = "{\n" +
" \"metric\": \"stb0.3\",\n" +
" \"timestamp\": 1626006833610123,\n" +
" \"value\": 10,\n" +
" \"tags\": {\n" +
" \"t1\": true,\n" +
" \"t2\": false,\n" +
" \"t3\": 10,\n" +
" \"t4\": \"123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>\"\n" +
" }\n" +
"}";
// when
conn.getConnector().insertJsonPayload(json);
// then
JSONObject jObject = JSONObject.parseObject(json);
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("show stables");
Assert.assertNotNull(rs);
ResultSetMetaData metaData = rs.getMetaData();
Assert.assertTrue(metaData.getColumnCount() > 0);
while (rs.next()) {
Assert.assertEquals(jObject.getString("metric").replaceAll("\\.", "_"), rs.getString(1));
}
statement.execute("drop table " + jObject.getString("metric").replaceAll("\\.", "_"));
rs.close();
statement.close();
}
@BeforeClass
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册