-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from taosdata/main
merge from main
- Loading branch information
Showing
5 changed files
with
203 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.taosdata.jdbc.ws; | ||
|
||
import com.taosdata.jdbc.utils.SpecifyAddress; | ||
import org.junit.*; | ||
|
||
import java.sql.*; | ||
import java.util.AbstractCollection; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Properties; | ||
|
||
@FixMethodOrder | ||
public class WSBigQueryTest { | ||
String host = "127.0.0.1"; | ||
String db_name = "ws_prepare"; | ||
String tableName = "wpt"; | ||
String superTable = "wpt_st"; | ||
Connection connection; | ||
|
||
|
||
@Test | ||
public void testExecuteBatchInsert() throws SQLException { | ||
String sql = "insert into " + db_name + "." + tableName + " (ts, c1) values(?, ?)"; | ||
PreparedStatement statement = connection.prepareStatement(sql); | ||
HashSet<Object> collect = new HashSet<>(); | ||
|
||
for (int i = 0; i < 20000; i++) { | ||
collect.add(i); | ||
statement.setTimestamp(1, new Timestamp(System.currentTimeMillis() + i)); | ||
statement.setInt(2, i); | ||
statement.addBatch(); | ||
} | ||
statement.executeBatch(); | ||
|
||
String sql1 = "select * from " + db_name + "." + tableName; | ||
statement = connection.prepareStatement(sql1); | ||
boolean b = statement.execute(); | ||
Assert.assertTrue(b); | ||
ResultSet resultSet = statement.getResultSet(); | ||
while (resultSet.next()) { | ||
Assert.assertTrue(collect.contains(resultSet.getInt(2))); | ||
} | ||
statement.close(); | ||
} | ||
|
||
@Before | ||
public void before() throws SQLException { | ||
String url = SpecifyAddress.getInstance().getRestWithoutUrl(); | ||
if (url == null) { | ||
url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata&batchfetch=true"; | ||
} else { | ||
url += "?user=root&password=taosdata&batchfetch=true"; | ||
} | ||
Properties properties = new Properties(); | ||
connection = DriverManager.getConnection(url, properties); | ||
Statement statement = connection.createStatement(); | ||
statement.execute("drop database if exists " + db_name); | ||
statement.execute("create database " + db_name); | ||
statement.execute("use " + db_name); | ||
statement.execute("create table if not exists " + db_name + "." + tableName + " (ts timestamp, c1 int)"); | ||
statement.close(); | ||
} | ||
|
||
@After | ||
public void after() throws SQLException { | ||
try (Statement statement = connection.createStatement()) { | ||
statement.execute("drop database if exists " + db_name); | ||
} | ||
connection.close(); | ||
} | ||
} |