Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests | Random generate Message Id and drop later to avoid conflicts with already set messages. #1017

Merged
merged 3 commits into from
Apr 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -527,16 +527,23 @@ private void testStatementPoolingInternal(String mode) throws Exception {
if (mode.equalsIgnoreCase("bulkcopy")) {
modifyConnectionForBulkCopyAPI(con);
}

int msgId = Constants.RANDOM.nextInt(50000, 99999);

// Test behavior with statement pooling.
con.setStatementPoolingCacheSize(10);
this.executeSQL(con,
"IF NOT EXISTS (SELECT * FROM sys.messages WHERE message_id = 99586) EXEC sp_addmessage 99586, 16, 'Prepared handle GAH!';");

this.executeSQL(con, "IF EXISTS (SELECT * FROM sys.messages WHERE message_id = " + msgId
+ ") EXEC sp_dropmessage @msgnum = " + msgId + ", @lang = 'all';");
this.executeSQL(con, "EXEC sp_addmessage " + msgId + ", 16, 'Prepared handle GAH!';");
// Test with missing handle failures (fake).
this.executeSQL(con, "CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName)
+ " (col INT);INSERT " + AbstractSQLGenerator.escapeIdentifier(tableName) + " VALUES (1);");
this.executeSQL(con, "CREATE PROC #updateProc1 AS UPDATE "
+ AbstractSQLGenerator.escapeIdentifier(tableName) + " SET col += 1; IF EXISTS (SELECT * FROM "
+ AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE col % 5 = 0) RAISERROR(99586,16,1);");
this.executeSQL(con,
"CREATE PROC #updateProc1 AS UPDATE " + AbstractSQLGenerator.escapeIdentifier(tableName)
+ " SET col += 1; IF EXISTS (SELECT * FROM "
+ AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE col % 5 = 0) RAISERROR("
+ msgId + ",16,1);");
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement("#updateProc1")) {
for (int i = 0; i < 100; ++i) {
try {
Expand All @@ -551,6 +558,9 @@ private void testStatementPoolingInternal(String mode) throws Exception {
}
}
}
} finally {
this.executeSQL(con, "IF EXISTS (SELECT * FROM sys.messages WHERE message_id = " + msgId
+ ") EXEC sp_dropmessage @msgnum = " + msgId + ", @lang = 'all';");
}

// test updated value, should be 1 + 100 = 101
Expand All @@ -562,13 +572,17 @@ private void testStatementPoolingInternal(String mode) throws Exception {
}

// Test batching with missing handle failures (fake).
this.executeSQL(con,
"IF NOT EXISTS (SELECT * FROM sys.messages WHERE message_id = 99586) EXEC sp_addmessage 99586, 16, 'Prepared handle GAH!';");

this.executeSQL(con, "IF EXISTS (SELECT * FROM sys.messages WHERE message_id = " + msgId
+ ") EXEC sp_dropmessage @msgnum = " + msgId + ", @lang = 'all';");
this.executeSQL(con, "EXEC sp_addmessage " + msgId + ", 16, 'Prepared handle GAH!';");
this.executeSQL(con, "CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName2)
+ " (col INT);INSERT " + AbstractSQLGenerator.escapeIdentifier(tableName2) + " VALUES (1);");
this.executeSQL(con, "CREATE PROC #updateProc2 AS UPDATE "
+ AbstractSQLGenerator.escapeIdentifier(tableName2) + " SET col += 1; IF EXISTS (SELECT * FROM "
+ AbstractSQLGenerator.escapeIdentifier(tableName2) + " WHERE col % 5 = 0) RAISERROR(99586,16,1);");
this.executeSQL(con,
"CREATE PROC #updateProc2 AS UPDATE " + AbstractSQLGenerator.escapeIdentifier(tableName2)
+ " SET col += 1; IF EXISTS (SELECT * FROM "
+ AbstractSQLGenerator.escapeIdentifier(tableName2) + " WHERE col % 5 = 0) RAISERROR("
+ msgId + ",16,1);");
try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement("#updateProc2")) {
for (int i = 0; i < 100; ++i) {
pstmt.addBatch();
Expand Down Expand Up @@ -597,6 +611,9 @@ private void testStatementPoolingInternal(String mode) throws Exception {
rs.next();
assertSame(101, rs.getInt(1));
}
} finally {
this.executeSQL(con, "IF EXISTS (SELECT * FROM sys.messages WHERE message_id = " + msgId
+ ") EXEC sp_dropmessage @msgnum = " + msgId + ", @lang = 'all';");
}

// Test behavior with statement pooling enabled
Expand Down