未验证 提交 87918caa 编写于 作者: Z Zhiyu Yang 提交者: GitHub

Feature/td 5432 (#6963)

* [TD-5342]<feature>: change fastjson and guava version, add retryHandle in HttpClientPoolUtil

* fix some simple problems
上级 225fb597
...@@ -37,13 +37,6 @@ ...@@ -37,13 +37,6 @@
<maven.test.jvmargs></maven.test.jvmargs> <maven.test.jvmargs></maven.test.jvmargs>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<!-- for restful -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
...@@ -52,12 +45,18 @@ ...@@ -52,12 +45,18 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.76</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>30.0-jre</version> <version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
// do nothing // do nothing
} }
@Override private void checkResultSetTypeAndResultSetConcurrency(int resultSetType, int resultSetConcurrency) throws SQLException {
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { switch (resultSetType) {
case ResultSet.TYPE_FORWARD_ONLY: case ResultSet.TYPE_FORWARD_ONLY:
break; break;
...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
default: default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
} }
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
return createStatement(); return createStatement();
} }
...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
case ResultSet.TYPE_FORWARD_ONLY:
break;
case ResultSet.TYPE_SCROLL_INSENSITIVE:
case ResultSet.TYPE_SCROLL_SENSITIVE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
switch (resultSetConcurrency) {
case ResultSet.CONCUR_READ_ONLY:
break;
case ResultSet.CONCUR_UPDATABLE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
return prepareStatement(sql); return prepareStatement(sql);
} }
......
...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getFetchDirection() throws SQLException { public int getFetchDirection() throws SQLException {
return 0; return ResultSet.FETCH_FORWARD;
} }
@Override @Override
...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet { ...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getType() throws SQLException { public int getType() throws SQLException {
return 0; return ResultSet.TYPE_FORWARD_ONLY;
} }
@Override @Override
public int getConcurrency() throws SQLException { public int getConcurrency() throws SQLException {
return 0; return ResultSet.CONCUR_READ_ONLY;
} }
@Override @Override
...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getHoldability() throws SQLException { public int getHoldability() throws SQLException {
return 0; return ResultSet.CLOSE_CURSORS_AT_COMMIT;
} }
@Override @Override
......
...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers { ...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet
public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed
private static final Set<Integer> errorNumbers = new HashSet(); private static final Set<Integer> errorNumbers = new HashSet<>();
static { static {
errorNumbers.add(ERROR_CONNECTION_CLOSED); errorNumbers.add(ERROR_CONNECTION_CLOSED);
......
...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { ...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
return; return;
// parse row data // parse row data
for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) { for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
List<Object> row = new ArrayList(); List<Object> row = new ArrayList<>();
JSONArray jsonRow = data.getJSONArray(rowIndex); JSONArray jsonRow = data.getJSONArray(rowIndex);
for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) { for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) {
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type)); row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type));
......
...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext; ...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.message.BasicHeaderElementIterator;
...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil { ...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE);
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL); connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL);
httpClient = HttpClients.custom().setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY).setConnectionManager(connectionManager).build(); httpClient = HttpClients.custom()
.setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY)
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
} }
} }
......
...@@ -4,14 +4,14 @@ public class OSUtils { ...@@ -4,14 +4,14 @@ public class OSUtils {
private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String OS = System.getProperty("os.name").toLowerCase();
public static boolean isWindows() { public static boolean isWindows() {
return OS.indexOf("win") >= 0; return OS.contains("win");
} }
public static boolean isMac() { public static boolean isMac() {
return OS.indexOf("mac") >= 0; return OS.contains("mac");
} }
public static boolean isLinux() { public static boolean isLinux() {
return OS.indexOf("nux") >= 0; return OS.contains("nux");
} }
} }
...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils; ...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils;
public class SqlSyntaxValidator { public class SqlSyntaxValidator {
private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe"}; private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe", "reset"};
private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"}; private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"};
private static final String[] querySQL = {"select", "show", "describe"}; private static final String[] querySQL = {"select", "show", "describe"};
...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator { ...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator {
public static boolean isUseSql(String sql) { public static boolean isUseSql(String sql) {
return sql.trim().toLowerCase().startsWith("use"); return sql.trim().toLowerCase().startsWith("use");
// || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*");
}
public static boolean isShowSql(String sql) {
return sql.trim().toLowerCase().startsWith("show");
}
public static boolean isDescribeSql(String sql) {
return sql.trim().toLowerCase().startsWith("describe");
}
public static boolean isInsertSql(String sql) {
return sql.trim().toLowerCase().startsWith("insert") || sql.trim().toLowerCase().startsWith("import");
} }
public static boolean isSelectSql(String sql) { public static boolean isSelectSql(String sql) {
return sql.trim().toLowerCase().startsWith("select"); return sql.trim().toLowerCase().startsWith("select");
} }
public static boolean isShowDatabaseSql(String sql) {
return sql.trim().toLowerCase().matches("show\\s*databases");
}
} }
...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong;
public class TaosInfo implements TaosInfoMBean { public class TaosInfo implements TaosInfoMBean {
private static volatile TaosInfo instance; private static volatile TaosInfo instance;
private AtomicLong connect_open = new AtomicLong(); private final AtomicLong connect_open = new AtomicLong();
private AtomicLong connect_close = new AtomicLong(); private final AtomicLong connect_close = new AtomicLong();
private AtomicLong statement_count = new AtomicLong(); private final AtomicLong statement_count = new AtomicLong();
static { static {
try { try {
......
...@@ -22,8 +22,7 @@ import java.util.stream.IntStream; ...@@ -22,8 +22,7 @@ import java.util.stream.IntStream;
public class Utils { public class Utils {
private static Pattern ptn = Pattern.compile(".*?'"); private static final Pattern ptn = Pattern.compile(".*?'");
private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter(); private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter();
private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter(); private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter();
private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter(); private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter();
...@@ -74,7 +73,7 @@ public class Utils { ...@@ -74,7 +73,7 @@ public class Utils {
public static String escapeSingleQuota(String origin) { public static String escapeSingleQuota(String origin) {
Matcher m = ptn.matcher(origin); Matcher m = ptn.matcher(origin);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int end = 0; int end = 0;
while (m.find()) { while (m.find()) {
end = m.end(); end = m.end();
...@@ -87,7 +86,7 @@ public class Utils { ...@@ -87,7 +86,7 @@ public class Utils {
sb.append(seg); sb.append(seg);
} }
} else { // len > 1 } else { // len > 1
sb.append(seg.substring(0, seg.length() - 2)); sb.append(seg, 0, seg.length() - 2);
char lastcSec = seg.charAt(seg.length() - 2); char lastcSec = seg.charAt(seg.length() - 2);
if (lastcSec == '\\') { if (lastcSec == '\\') {
sb.append("\\'"); sb.append("\\'");
...@@ -195,7 +194,7 @@ public class Utils { ...@@ -195,7 +194,7 @@ public class Utils {
public static String formatTimestamp(Timestamp timestamp) { public static String formatTimestamp(Timestamp timestamp) {
int nanos = timestamp.getNanos(); int nanos = timestamp.getNanos();
if (nanos % 1000000l != 0) if (nanos % 1000000L != 0)
return timestamp.toLocalDateTime().format(microSecFormatter); return timestamp.toLocalDateTime().format(microSecFormatter);
return timestamp.toLocalDateTime().format(milliSecFormatter); return timestamp.toLocalDateTime().format(milliSecFormatter);
} }
......
...@@ -5,7 +5,6 @@ import org.junit.Assert; ...@@ -5,7 +5,6 @@ import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import javax.management.OperationsException;
import java.sql.*; import java.sql.*;
import java.util.Properties; import java.util.Properties;
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.lang.management.ManagementFactory; import static org.junit.Assert.assertEquals;
import java.lang.management.RuntimeMXBean; import static org.junit.Assert.assertTrue;
import java.lang.management.ThreadMXBean;
public class TSDBJNIConnectorTest { public class TSDBJNIConnectorTest {
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.taosdata.jdbc.rs.RestfulParameterMetaData;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
......
...@@ -2,7 +2,6 @@ package com.taosdata.jdbc; ...@@ -2,7 +2,6 @@ package com.taosdata.jdbc;
import org.junit.*; import org.junit.*;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest { ...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest { ...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest {
Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); Assert.assertEquals(ts, rs.getTimestamp(1).getTime());
Assert.assertEquals(2, rs.getInt(2)); Assert.assertEquals(2, rs.getInt(2));
Assert.assertEquals(2, rs.getInt("f1")); Assert.assertEquals(2, rs.getInt("f1"));
Assert.assertEquals(3l, rs.getLong(3)); Assert.assertEquals(3L, rs.getLong(3));
Assert.assertEquals(3l, rs.getLong("f2")); Assert.assertEquals(3L, rs.getLong("f2"));
Assert.assertEquals(3.14f, rs.getFloat(4), 0.0); Assert.assertEquals(3.14f, rs.getFloat(4), 0.0);
Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0); Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0);
Assert.assertEquals(3.1415, rs.getDouble(5), 0.0); Assert.assertEquals(3.1415, rs.getDouble(5), 0.0);
...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest { ...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest { ...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Float> s3 = new ArrayList<Float>(); ArrayList<Float> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest { ...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest {
s.setFloat(2, s3); s.setFloat(2, s3);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Double> s4 = new ArrayList<Double>(); ArrayList<Double> s4 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s4.add(null); s4.add(null);
...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest { ...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest {
s.setDouble(3, s4); s.setDouble(3, s4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Long> ts2 = new ArrayList<Long>(); ArrayList<Long> ts2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
ts2.add(null); ts2.add(null);
...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest { ...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest {
if (i % random == 0) { if (i % random == 0) {
sb.add(null); sb.add(null);
} else { } else {
sb.add(i % 2 == 0 ? true : false); sb.add(i % 2 == 0);
} }
} }
s.setBoolean(6, sb); s.setBoolean(6, sb);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s5 = new ArrayList<String>(); ArrayList<String> s5 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s5.add(null); s5.add(null);
...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest { ...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest { ...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest { ...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest {
public void bindDataWithSingleTagTest() throws SQLException { public void bindDataWithSingleTagTest() throws SQLException {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
String types[] = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"}; String[] types = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"};
for (String type : types) { for (String type : types) {
stmt.execute("drop table if exists weather_test"); stmt.execute("drop table if exists weather_test");
...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest { ...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest {
} }
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("分支" + i % 4); s2.add("分支" + i % 4);
} }
s.setNString(1, s2, 10); s.setNString(1, s2, 10);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s3.add("test" + i % 4); s3.add("test" + i % 4);
} }
...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest { ...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest {
s.setTagString(1, "test"); s.setTagString(1, "test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("test" + i % 4); s2.add("test" + i % 4);
} }
...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest { ...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest {
public void setBigDecimal() throws SQLException { public void setBigDecimal() throws SQLException {
// given // given
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
BigDecimal bigDecimal = new BigDecimal(3.14444); BigDecimal bigDecimal = new BigDecimal("3.14444");
// when // when
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest { ...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
......
...@@ -95,13 +95,13 @@ public class TSDBResultSetTest { ...@@ -95,13 +95,13 @@ public class TSDBResultSetTest {
@Test @Test
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
Assert.assertEquals(1609430400000l, f1.longValue()); Assert.assertEquals(1609430400000L, f1.longValue());
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class TSDBResultSetTest { ...@@ -125,13 +125,13 @@ public class TSDBResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertTrue(Arrays.equals("abc".getBytes(), f6)); Assert.assertTrue(Arrays.equals("abc".getBytes(), f6));
...@@ -223,7 +223,7 @@ public class TSDBResultSetTest { ...@@ -223,7 +223,7 @@ public class TSDBResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -421,7 +421,7 @@ public class TSDBResultSetTest { ...@@ -421,7 +421,7 @@ public class TSDBResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases; ...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import java.sql.*; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
public class BadLocaleSettingTest { public class BadLocaleSettingTest {
......
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -9,13 +10,13 @@ import java.util.Properties; ...@@ -9,13 +10,13 @@ import java.util.Properties;
public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
private static String host1 = "192.168.17.156"; private static final String host1 = "192.168.17.156";
private static String user1 = "root"; private static final String user1 = "root";
private static String password1 = "tqueue"; private static final String password1 = "tqueue";
private Connection conn1; private Connection conn1;
private static String host2 = "192.168.17.82"; private static final String host2 = "192.168.17.82";
private static String user2 = "root"; private static final String user2 = "root";
private static String password2 = "taosdata"; private static final String password2 = "taosdata";
private Connection conn2; private Connection conn2;
@Test @Test
...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { ...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()"); ResultSet rs = stmt.executeQuery("select server_status()");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
Assert.assertNotNull(meta);
while (rs.next()) { while (rs.next()) {
} }
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -13,7 +13,7 @@ import java.util.Properties; ...@@ -13,7 +13,7 @@ import java.util.Properties;
public class DriverAutoloadTest { public class DriverAutoloadTest {
private Properties properties; private Properties properties;
private String host = "127.0.0.1"; private final String host = "127.0.0.1";
@Test @Test
public void testRestful() throws SQLException { public void testRestful() throws SQLException {
......
...@@ -13,9 +13,9 @@ import java.util.Random; ...@@ -13,9 +13,9 @@ import java.util.Random;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InsertDbwithoutUseDbTest { public class InsertDbwithoutUseDbTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Properties properties; private static Properties properties;
private static Random random = new Random(System.currentTimeMillis()); private static final Random random = new Random(System.currentTimeMillis());
@Test @Test
public void case001() throws ClassNotFoundException, SQLException { public void case001() throws ClassNotFoundException, SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,13 +8,13 @@ import java.util.Properties; ...@@ -8,13 +8,13 @@ import java.util.Properties;
public class InvalidResultSetPointerTest { public class InvalidResultSetPointerTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static final String dbName = "test"; private static final String dbName = "test";
private static final String stbName = "stb"; private static final String stbName = "stb";
private static final String tbName = "tb"; private static final String tbName = "tb";
private static Connection connection; private static Connection connection;
private static int numOfSTb = 30000; private static final int numOfSTb = 30000;
private static int numOfTb = 3; private static final int numOfTb = 3;
private static int numOfThreads = 100; private static int numOfThreads = 100;
@Test @Test
...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest { ...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest {
b = numOfSTb % numOfThreads; b = numOfSTb % numOfThreads;
} }
multiThreadingClass instance[] = new multiThreadingClass[numOfThreads]; multiThreadingClass[] instance = new multiThreadingClass[numOfThreads];
int last = 0; int last = 0;
for (int i = 0; i < numOfThreads; i++) { for (int i = 0; i < numOfThreads; i++) {
......
...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit; ...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit;
public class MultiThreadsWithSameStatementTest { public class MultiThreadsWithSameStatementTest {
private static class Service {
private class Service {
public Connection conn; public Connection conn;
public Statement stmt; public Statement stmt;
......
...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals; ...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals;
public class StableTest { public class StableTest {
private static Connection connection; private static Connection connection;
private static String dbName = "test"; private static final String dbName = "test";
private static String stbName = "st"; private static final String stbName = "st";
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
@BeforeClass @BeforeClass
public static void createDatabase() { public static void createDatabase() {
......
...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest { ...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest {
return null; return null;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("show databases"); ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) { while (rs.next()) {
...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest { ...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest {
} }
}); });
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try { try {
conn.close(); conn.close();
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
......
...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest {
private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456; private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456;
private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private static final String date1 = format.format(new Date(timestamp1)); private static final String date1 = format.format(new Date(timestamp1));
private static final String date4 = format.format(new Date(timestamp1 + 10l)); private static final String date4 = format.format(new Date(timestamp1 + 10L));
private static final String date2 = date1 + "123455"; private static final String date2 = date1 + "123455";
private static final String date3 = date4 + "123456"; private static final String date3 = date4 + "123456";
......
...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest { ...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest { ...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -95,13 +95,13 @@ public class RestfulResultSetTest { ...@@ -95,13 +95,13 @@ public class RestfulResultSetTest {
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
long actual = (f1 == null) ? 0 : f1.longValue(); long actual = (f1 == null) ? 0 : f1.longValue();
Assert.assertEquals(1609430400000l, actual); Assert.assertEquals(1609430400000L, actual);
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class RestfulResultSetTest { ...@@ -125,13 +125,13 @@ public class RestfulResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertEquals("abc", new String(f6)); Assert.assertEquals("abc", new String(f6));
...@@ -222,7 +222,7 @@ public class RestfulResultSetTest { ...@@ -222,7 +222,7 @@ public class RestfulResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -434,7 +434,7 @@ public class RestfulResultSetTest { ...@@ -434,7 +434,7 @@ public class RestfulResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -10,17 +10,17 @@ public class OSUtilsTest { ...@@ -10,17 +10,17 @@ public class OSUtilsTest {
@Test @Test
public void inWindows() { public void inWindows() {
Assert.assertEquals(OS.indexOf("win") >= 0, OSUtils.isWindows()); Assert.assertEquals(OS.contains("win"), OSUtils.isWindows());
} }
@Test @Test
public void isMac() { public void isMac() {
Assert.assertEquals(OS.indexOf("mac") >= 0, OSUtils.isMac()); Assert.assertEquals(OS.contains("mac"), OSUtils.isMac());
} }
@Test @Test
public void isLinux() { public void isLinux() {
Assert.assertEquals(OS.indexOf("nux") >= 0, OSUtils.isLinux()); Assert.assertEquals(OS.contains("nux"), OSUtils.isLinux());
} }
@Before @Before
......
...@@ -21,47 +21,4 @@ public class TimestampUtil { ...@@ -21,47 +21,4 @@ public class TimestampUtil {
SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
return sdf.format(new Date(time)); return sdf.format(new Date(time));
} }
public static class TimeTuple {
public Long start;
public Long end;
public Long timeGap;
TimeTuple(long start, long end, long timeGap) {
this.start = start;
this.end = end;
this.timeGap = timeGap;
}
}
public static TimeTuple range(long start, long timeGap, long size) {
long now = System.currentTimeMillis();
if (timeGap < 1)
timeGap = 1;
if (start == 0)
start = now - size * timeGap;
// 如果size小于1异常
if (size < 1)
throw new IllegalArgumentException("size less than 1.");
// 如果timeGap为1,已经超长,需要前移start
if (start + size > now) {
start = now - size;
return new TimeTuple(start, now, 1);
}
long end = start + (long) (timeGap * size);
if (end > now) {
//压缩timeGap
end = now;
double gap = (end - start) / (size * 1.0f);
if (gap < 1.0f) {
timeGap = 1;
start = end - size;
} else {
timeGap = (long) gap;
end = start + (long) (timeGap * size);
}
}
return new TimeTuple(start, end, timeGap);
}
} }
...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils; ...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
public class UtilsTest { public class UtilsTest {
...@@ -19,14 +17,14 @@ public class UtilsTest { ...@@ -19,14 +17,14 @@ public class UtilsTest {
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'''''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'\'\'\''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册