From 510465b9d9c5d5c5a01a93d3673649de3fdcc39d Mon Sep 17 00:00:00 2001 From: zhaoyanggh Date: Fri, 27 Aug 2021 10:39:33 +0800 Subject: [PATCH] add test case --- .../jdbc/cases/InsertNegativeDoubleTest.java | 71 ------------------- tests/pytest/insert/specialSql.py | 48 +++++++++++++ 2 files changed, 48 insertions(+), 71 deletions(-) delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertNegativeDoubleTest.java create mode 100644 tests/pytest/insert/specialSql.py diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertNegativeDoubleTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertNegativeDoubleTest.java deleted file mode 100644 index 626557a831..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertNegativeDoubleTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.taosdata.jdbc.cases; - -import com.taosdata.jdbc.TSDBDriver; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.sql.*; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; - -public class InsertNegativeDoubleTest { - - static Connection connection; - static Statement statement; - static String dbName = "test"; - static String stbName = "meters"; - static String host = "127.0.0.1"; - - @Before - public void createDatabase() { - try { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - - statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("use " + dbName); - - String createTableSql = "create table " + stbName + "(ts timestamp, double_col double)"; - statement.executeUpdate(createTableSql); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - @Test - public void testQueryBinaryData() throws SQLException { - String insertSql = "insert into " + stbName + " values(now, -123456789.123456789)"; - statement.executeUpdate(insertSql); - - String querySql = "select * from " + stbName; - ResultSet rs = statement.executeQuery(querySql); - - while (rs.next()) { - double value = rs.getDouble(2); - assert(java.lang.Double.compare(-123456789.123456789, value) == 0); - } - rs.close(); - } - - @After - public void close() { - try { - if (statement != null) - statement.close(); - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/tests/pytest/insert/specialSql.py b/tests/pytest/insert/specialSql.py new file mode 100644 index 0000000000..908c14ead9 --- /dev/null +++ b/tests/pytest/insert/specialSql.py @@ -0,0 +1,48 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdLog.info("=============== step1") + tdSql.execute( + 'create stable properties_asch5snuykd (ts timestamp, create_time timestamp, number_value double, value int) tags (device_id nchar(8), property nchar(8))' + ) + tdSql.execute( + "insert into\n\t\t \n\t\t\tdb.properties_b86ca7d11556e0fdd43fd12ac08651f9 using db.properties_asch5snuykd\n\t\t\t(\n\t\t\t \n\t\t\t\tdevice_id\n\t\t\t , \n\t\t\t\tproperty\n\t\t\t \n\t\t\t)\n\t\t\ttags\n\t\t\t(\n\t\t\t \n\t\t\t\t'dev1'\n\t\t\t , \n\t\t\t\t'pres'\n\t\t\t \n\t\t\t)\n\t\t\t(\n\t\t\t \n\t\t\t\tts\n\t\t\t , \n\t\t\t\tcreate_time\n\t\t\t , \n\t\t\t\tnumber_value\n\t\t\t , \n\t\t\t\tvalue\n\t\t\t \n\t\t\t)\n\t\t\tvalues\n\t\t\t \n\t\t\t\t(\n\t\t\t\t \n\t\t\t\t\t1629443494659\n\t\t\t\t , \n\t\t\t\t\t1629443494660\n\t\t\t\t , \n\t\t\t\t\t-1000.0\n\t\t\t\t , \n\t\t\t\t\t'-1000'\n\t\t\t\t \n\t\t\t\t)\n;" + ) + + tdSql.query( + "select * from db.properties_b86ca7d11556e0fdd43fd12ac08651f9") + tdSql.checkRows(1) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) -- GitLab