提交 092aecb5 编写于 作者: 刘蓓

[TD-358]<test>:Reproduce oom bug

上级 a96a7e89
......@@ -85,6 +85,7 @@ public class OpenTSDBMigrateTest {
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname + " precision 'ns'");
stmt.execute("use " + dbname);
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
......@@ -94,7 +95,6 @@ public class OpenTSDBMigrateTest {
public void afterClass() {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
......
package com.taosdata.jdbc.oom;
import com.taosdata.jdbc.TSDBPreparedStatement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.ArrayList;
public class BatchInsertTest {
Connection connection;
String host = "127.0.0.1";
String dbname = "batch_test";
@Test
public void batchInsert() throws SQLException {
Statement statement = connection.createStatement();
String tname = "weather_test";
String dropSql = "drop table if exists " + tname;
String createSql = "create table " + tname + "(ts timestamp, f1 nchar(10), f5 int)";
statement.execute(dropSql);
statement.execute(createSql);
TSDBPreparedStatement preparedStatement = (TSDBPreparedStatement) connection.prepareStatement("insert into ? values(?, ?, ?)");
preparedStatement.setTableName(tname);
int numOfRows = 1000;
ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() - 1000);
}
preparedStatement.setTimestamp(0, ts);
ArrayList<String> stringList = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) {
stringList.add("test" + i);
}
preparedStatement.setNString(1, stringList, 10);
ArrayList<Integer> intList = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) {
intList.add(i);
}
preparedStatement.setInt(2, intList);
preparedStatement.columnDataAddBatch();
preparedStatement.columnDataExecuteBatch();
preparedStatement.columnDataClearBatch();
preparedStatement.close();
}
@Before
public void before() {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
statement.execute("drop database if exists " + dbname);
statement.execute("create database if not exists " + dbname);
statement.execute("use " + dbname);
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
@After
public void after() {
try (Statement statement = connection.createStatement()) {
statement.execute("drop database if exists " + dbname);
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
package com.taosdata.jdbc.oom;
import com.google.common.collect.Lists;
import com.taosdata.jdbc.TSDBConnection;
import com.taosdata.jdbc.TSDBPreparedStatement;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class BindTest {
private static TSDBConnection conn;
private static final String host = "127.0.0.1";
private static final String dbname = "memory_test";
@Test
public void memoryTest() throws SQLException {
String sql = "insert into ? using st tags (?) (ts, speed, longitude, latitude, altitude, guid, origin_byte) VALUES (?, ?, ?, ?, ?, ?, ?)";
TSDBPreparedStatement s = (TSDBPreparedStatement) conn.prepareStatement(sql);
while (true) {
long l = System.currentTimeMillis() - 1000;
List<RealTimeData> list = Lists.newArrayList();
for (int i = 0; i < 1000; i++) {
RealTimeData rd = new RealTimeData();
rd.setTs(l + i);
rd.setLongitude(11000L);
rd.setLatitude(10000L);
rd.setAltitude(100);
rd.setSpeed(100);
rd.setGuid("123456");
rd.setOriginByte("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
list.add(rd);
};
bindTest(list, "t_1",s);
}
}
public static void bindTest(List<RealTimeData> list, String table , TSDBPreparedStatement s) throws SQLException {
ArrayList<Long> ts = new ArrayList<>();
ArrayList<Integer> speed = new ArrayList<>();
ArrayList<Long> longitude = new ArrayList<>();
ArrayList<Long> latitude = new ArrayList<>();
ArrayList<Long> altitude = new ArrayList<>();
ArrayList<String> guid = new ArrayList<>();
ArrayList<String> originByte = new ArrayList<>();
ts.addAll(list.stream().map(i -> i.getTs()).collect(Collectors.toList()));
speed.addAll(list.stream().map(i -> i.getSpeed()).collect(Collectors.toList()));
longitude.addAll(list.stream().map(i -> i.getLongitude()).collect(Collectors.toList()));
latitude.addAll(list.stream().map(i -> i.getLatitude()).collect(Collectors.toList()));
altitude.addAll(list.stream().map(i -> i.getAltitude()).collect(Collectors.toList()));
guid.addAll(list.stream().map(i -> i.getGuid()).collect(Collectors.toList()));
originByte.addAll(list.stream().map(i -> i.getOriginByte()).collect(Collectors.toList()));
s.setTableName(table);
s.setTagInt(0, 2);
s.setTimestamp(0, ts);
s.setInt(1, speed);
s.setLong(2, longitude);
s.setLong(3, latitude);
s.setLong(4, altitude);
s.setNString(5, guid, 20);
s.setNString(6, originByte, 200);
s.columnDataAddBatch();
s.columnDataExecuteBatch();
s.columnDataClearBatch();
}
@BeforeClass
public static void beforeClass() {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
try {
conn = (TSDBConnection) DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists " + dbname);
stmt.execute("create database if not exists " + dbname);
stmt.execute("use " + dbname);
stmt.execute("create stable if not exists st (ts timestamp, speed int, longitude bigint, latitude bigint, altitude bigint, guid nchar(100), origin_byte nchar(150)) tags (t int)");
} catch (SQLException e) {
e.printStackTrace();
}
}
@AfterClass
public static void afterClass() {
try (Statement stmt = conn.createStatement()) {
stmt.execute("drop database if exists " + dbname);
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package com.taosdata.jdbc.oom;
public class RealTimeData {
private long ts; // BIGINT
private long longitude;
private long latitude;
private long altitude;
private int speed; // int
private String guid;
private String originByte;// NCHAR
public long getTs() {
return ts;
}
public void setTs(long ts) {
this.ts = ts;
}
public long getLongitude() {
return longitude;
}
public void setLongitude(long longitude) {
this.longitude = longitude;
}
public long getLatitude() {
return latitude;
}
public void setLatitude(long latitude) {
this.latitude = latitude;
}
public long getAltitude() {
return altitude;
}
public void setAltitude(long altitude) {
this.altitude = altitude;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public String getGuid() {
return guid;
}
public void setGuid(String guid) {
this.guid = guid;
}
public String getOriginByte() {
return originByte;
}
public void setOriginByte(String originByte) {
this.originByte = originByte;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册