Skip to content

Commit

Permalink
randomize test table name (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lilgreenbird authored Oct 12, 2023
1 parent 3a7daf3 commit 3447893
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand All @@ -36,19 +35,26 @@
@Tag(Constants.xSQLv11)
@Tag(Constants.xAzureSQLDW)
public class ResultSetsWithResiliencyTest extends AbstractTest {
static String tableName = AbstractSQLGenerator.escapeIdentifier("resilencyTestTable");
static String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("resiliencyTestTable"));
static int numberOfRows = 10;

private static String callableStatementICROnDoneTestSp = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("CallableStatement_ICROnDoneTest_SP"));
private static String callableStatementICROnDoneErrorTestSp = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("CallableStatement_ICROnDoneErrorTest_SP"));
private static String callableStatementICROnDoneTestSp = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("CallableStatement_ICROnDoneTest_SP"));
private static String callableStatementICROnDoneErrorTestSp = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("CallableStatement_ICROnDoneErrorTest_SP"));
private static String createClientCursorInitTableQuery = "create table %s (col1 int, col2 varchar(8000), col3 int identity(1,1))";
private static String createFetchBufferTableQuery = "create table %s (col1 int not null)";
private static String insertIntoFetchBufferTableQuery = "insert into %s (col1) values (%s);";
private static final String clientCursorInitTable1 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable1"));
private static final String clientCursorInitTable2 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable2"));
private static final String clientCursorInitTable3 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable3"));
private static final String fetchBufferTestTable1 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("fetchBufferTestTable1"));
private static final String fetchBufferTestTable2 = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("fetchBufferTestTable2"));
private static final String clientCursorInitTable1 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable1"));
private static final String clientCursorInitTable2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable2"));
private static final String clientCursorInitTable3 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("clientCursorInitTable3"));
private static final String fetchBufferTestTable1 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("fetchBufferTestTable1"));
private static final String fetchBufferTestTable2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("fetchBufferTestTable2"));
private static final String clientCursorInitTableQuery1 = "select * from " + clientCursorInitTable1;
private static final String clientCursorInitTableQuery2 = "select * from " + clientCursorInitTable2;
private static final String clientCursorInitTableQuery3 = "select * from " + clientCursorInitTable3;
Expand Down Expand Up @@ -169,18 +175,17 @@ public void testAdaptiveBufferingWithPartiallyBufferedResultSet() throws SQLExce
public void testResultSetClientCursorInitializerOnDone() throws SQLException {
try (Connection con = ResiliencyUtils.getConnection(connectionString); Statement stmt = con.createStatement()) {

boolean hasResults = stmt.execute(clientCursorInitTableQuery1+ "; " + clientCursorInitTableQuery2);
while(hasResults) {
boolean hasResults = stmt.execute(clientCursorInitTableQuery1 + "; " + clientCursorInitTableQuery2);
while (hasResults) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {}
hasResults = stmt.getMoreResults();
}

ResiliencyUtils.killConnection(con, connectionString, 1);

try (ResultSet rs = con.createStatement()
.executeQuery(clientCursorInitTableQuery3)) {
while(rs.next()) {}
try (ResultSet rs = con.createStatement().executeQuery(clientCursorInitTableQuery3)) {
while (rs.next()) {}
}
}
}
Expand All @@ -191,7 +196,7 @@ public void testResultSetErrorClientCursorInitializerOnDone() throws SQLExceptio

try {
boolean hasResults = stmt.execute(clientCursorInitTableQuery1 + "; " + errorQuery);
while(hasResults) {
while (hasResults) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {}
hasResults = stmt.getMoreResults();
Expand All @@ -205,8 +210,7 @@ public void testResultSetErrorClientCursorInitializerOnDone() throws SQLExceptio

ResiliencyUtils.killConnection(con, connectionString, 1);

try (ResultSet rs = con.createStatement()
.executeQuery(clientCursorInitTableQuery3)) {
try (ResultSet rs = con.createStatement().executeQuery(clientCursorInitTableQuery3)) {
while (rs.next()) {}
}
}
Expand Down Expand Up @@ -238,10 +242,8 @@ public void testCallableStatementOnDone() throws SQLException {

@Test
public void testCallableStatementErrorOnDone() throws SQLException {
String errorCallableStmt = "{CALL "
+ callableStatementICROnDoneErrorTestSp + " (?, ?)}";
String validCallableStmt = "{CALL "
+ callableStatementICROnDoneTestSp + " (?, ?)}";
String errorCallableStmt = "{CALL " + callableStatementICROnDoneErrorTestSp + " (?, ?)}";
String validCallableStmt = "{CALL " + callableStatementICROnDoneTestSp + " (?, ?)}";

try (Connection con = ResiliencyUtils.getConnection(connectionString)) {

Expand Down Expand Up @@ -286,7 +288,7 @@ public void testResultSetFetchBufferOnDone() throws SQLException {

try (Statement stmt = con.createStatement()) {
boolean hasResults = stmt.execute(fetchBufferTableQuery1 + "; " + fetchBufferTableQuery2);
while(hasResults) {
while (hasResults) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {}
hasResults = stmt.getMoreResults();
Expand Down Expand Up @@ -326,7 +328,7 @@ public void testResultSetErrorFetchBufferOnDone() throws SQLException {

try (Statement stmt = con.createStatement()) {
boolean hasResults = stmt.execute(fetchBufferTableQuery1 + "; " + errorQuery);
while(hasResults) {
while (hasResults) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {}
hasResults = stmt.getMoreResults();
Expand Down Expand Up @@ -386,7 +388,7 @@ public void testMultipleResultSets() throws Exception {
@Test
public void testResultSetWithException() throws Exception {
try (Connection c = ResiliencyUtils.getConnection(connectionString); Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT 1/0")) {
ResultSet rs = s.executeQuery("SELECT 1/0")) {

while (rs.next()) {
ResiliencyUtils.killConnection(c, connectionString, 0);
Expand Down

0 comments on commit 3447893

Please sign in to comment.