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

Fix for random JUnit failures in framework tests #762

Merged
merged 7 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void testRepetativeCM() {
}

// add column mapping for duplicate column in destination
bulkWrapper.setColumnMapping(1, 24);
bulkWrapper.setColumnMapping(1, 25);

// perform bulkCopy without validating results or dropping destination table
BulkCopyTestUtil.performBulkCopy(bulkWrapper, sourceTable1, destTable, false, false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ private class ColumnMetadata {
if (JDBCType.BIT == sqlType.getJdbctype()) {
CurrentRow[j] = ((0 == ThreadLocalRandom.current().nextInt(2)) ? Boolean.FALSE : Boolean.TRUE);
} else {
CurrentRow[j] = sqlType.createdata();
if(j==0) {
CurrentRow[j] = i+1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just use SQL Server's auto-increment instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that, but it requires IDENTITY_INSERT to be enabled in order to make TVP and Bulk Copy work, with lots of test changes. I don't think it's worth the effort if we have to eventually enable IDENTITY_INSERT.

} else {
CurrentRow[j] = sqlType.createdata();
}
}
}
data.add(CurrentRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, bo
destinationTable = sourceTable.cloneSchema();
stmt.createTable(destinationTable);
try (DBResultSet srcResultSet = stmt
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY " + sourceTable.getEscapedColumnName(0));
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy(
(Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
if (wrapper.isUsingBulkCopyOptions()) {
Expand Down Expand Up @@ -112,7 +112,7 @@ static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DB
try (DBConnection con = new DBConnection(wrapper.getConnectionString());
DBStatement stmt = con.createStatement();
DBResultSet srcResultSet = stmt
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY " + sourceTable.getEscapedColumnName(0));
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy(
(Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
if (wrapper.isUsingBulkCopyOptions()) {
Expand Down Expand Up @@ -156,7 +156,7 @@ static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DB
try (DBConnection con = new DBConnection(wrapper.getConnectionString());
DBStatement stmt = con.createStatement();
DBResultSet srcResultSet = stmt
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY " + sourceTable.getEscapedColumnName(0));
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy(
(Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
try {
Expand Down Expand Up @@ -214,7 +214,7 @@ static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DB
try (DBConnection con = new DBConnection(wrapper.getConnectionString());
DBStatement stmt = con.createStatement();
DBResultSet srcResultSet = stmt
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY " + sourceTable.getEscapedColumnName(0));
SQLServerBulkCopy bulkCopy = wrapper.isUsingConnection() ? new SQLServerBulkCopy(
(Connection) con.product()) : new SQLServerBulkCopy(wrapper.getConnectionString())) {
try {
Expand Down Expand Up @@ -271,9 +271,9 @@ static void performBulkCopy(BulkCopyTestWrapper wrapper, DBTable sourceTable, DB
static void validateValues(DBConnection con, DBTable sourceTable, DBTable destinationTable) throws SQLException {
try (DBStatement srcStmt = con.createStatement(); DBStatement dstStmt = con.createStatement();
DBResultSet srcResultSet = srcStmt
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + ";");
.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY " + sourceTable.getEscapedColumnName(0));
DBResultSet dstResultSet = dstStmt
.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + " ORDER BY " + destinationTable.getEscapedColumnName(0))) {
ResultSetMetaData destMeta = ((ResultSet) dstResultSet.product()).getMetaData();
int totalColumns = destMeta.getColumnCount();

Expand Down Expand Up @@ -321,7 +321,7 @@ static void validateValues(DBConnection con, ISQLServerBulkRecord srcData,
DBTable destinationTable) throws Exception {

try (DBStatement dstStmt = con.createStatement(); DBResultSet dstResultSet = dstStmt
.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + ";")) {
.executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + " ORDER BY " + destinationTable.getEscapedColumnName(0))) {
ResultSetMetaData destMeta = ((ResultSet) dstResultSet.product()).getMetaData();
int totalColumns = destMeta.getColumnCount();

Expand Down
67 changes: 16 additions & 51 deletions src/test/java/com/microsoft/sqlserver/jdbc/bvt/bvtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ public void testDriverNameAndDriverVersion() throws SQLException {
*/
@Test
public void testCreateStatement() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName() + ";";

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement();
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {
rs.verify(table1);
}
}
Expand Down Expand Up @@ -116,12 +113,9 @@ public void testCreateStatementWithQueryTimeout() throws SQLException {
*/
@Test
public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY);
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {

rs.next();
rs.verifyCurrentRow(table1);
Expand Down Expand Up @@ -167,12 +161,9 @@ public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFou
*/
@Test
public void testStmtScrollSensitiveReadOnly() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {
rs.next();
rs.next();
rs.verifyCurrentRow(table1);
Expand All @@ -192,14 +183,10 @@ public void testStmtScrollSensitiveReadOnly() throws SQLException {
*/
@Test
public void testStmtForwardOnlyUpdateable() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE);
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {
rs.next();

// Verify resultset behavior
rs.next();
rs.verifyCurrentRow(table1);
Expand All @@ -223,12 +210,9 @@ public void testStmtForwardOnlyUpdateable() throws SQLException {
*/
@Test
public void testStmtScrollSensitiveUpdatable() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE);
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {

// Verify resultset behavior
rs.next();
Expand Down Expand Up @@ -272,11 +256,9 @@ public void testStmtSSScrollDynamicOptimisticCC() throws SQLException {
public void testStmtSserverCursorForwardOnly() throws SQLException {

DBResultSetTypes rsType = DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_READ_ONLY;
String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(rsType.resultsetCursor, rsType.resultSetConcurrency);
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {
// Verify resultset behavior
rs.next();
rs.verify(table1);
Expand All @@ -291,9 +273,9 @@ public void testStmtSserverCursorForwardOnly() throws SQLException {
@Test
public void testCreatepreparedStatement() throws SQLException {

String colName = table1.getColumnName(7);
String colName = table1.getEscapedColumnName(7);
String value = table1.getRowData(7, 0).toString();
String query = "SELECT * from " + table1.getEscapedTableName() + " where [" + colName + "] = ? ";
String query = "SELECT * from " + table1.getEscapedTableName() + " where " + colName + " = ? ";

try (DBConnection conn = new DBConnection(connectionString);
DBPreparedStatement pstmt = conn.prepareStatement(query)) {
Expand All @@ -312,11 +294,8 @@ public void testCreatepreparedStatement() throws SQLException {
*/
@Test
public void testResultSet() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement();
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {
// verify resultSet
rs.verify(table1);
}
Expand All @@ -329,11 +308,8 @@ public void testResultSet() throws SQLException {
*/
@Test
public void testResultSetAndClose() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement();
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {

try {
if (null != rs)
Expand All @@ -351,15 +327,11 @@ public void testResultSetAndClose() throws SQLException {
*/
@Test
public void testTwoResultsetsDifferentStmt() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();
String query2 = "SELECT * FROM " + table2.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt1 = conn.createStatement();
DBStatement stmt2 = conn.createStatement()) {

DBResultSet rs1 = stmt1.executeQuery(query);
DBResultSet rs2 = stmt2.executeQuery(query2);
DBResultSet rs1 = stmt1.selectAll(table1);
DBResultSet rs2 = stmt2.selectAll(table2);

// Interleave resultset calls
rs1.next();
Expand All @@ -383,14 +355,10 @@ public void testTwoResultsetsDifferentStmt() throws SQLException {
*/
@Test
public void testTwoResultsetsSameStmt() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();
String query2 = "SELECT * FROM " + table2.getEscapedTableName();

try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement()) {

DBResultSet rs1 = stmt.executeQuery(query);
DBResultSet rs2 = stmt.executeQuery(query2);
DBResultSet rs1 = stmt.selectAll(table1);
DBResultSet rs2 = stmt.selectAll(table2);
// Interleave resultset calls. rs is expected to be closed
try {
rs1.next();
Expand Down Expand Up @@ -418,9 +386,8 @@ public void testTwoResultsetsSameStmt() throws SQLException {
*/
@Test
public void testResultSetAndCloseStmt() throws SQLException {
String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement();
DBResultSet rs = stmt.executeQuery(query)) {
DBResultSet rs = stmt.selectAll(table1)) {

stmt.close(); // this should close the resultSet
try {
Expand All @@ -439,10 +406,8 @@ public void testResultSetAndCloseStmt() throws SQLException {
*/
@Test
public void testResultSetSelectMethod() throws SQLException {

String query = "SELECT * FROM " + table1.getEscapedTableName();
try (DBConnection conn = new DBConnection(connectionString + ";selectMethod=cursor;");
DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.executeQuery(query)) {
DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.selectAll(table1)) {
rs.verify(table1);
}
}
Expand Down
Loading