diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ed76a53be..5f1ac8fff 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,8 +10,10 @@ jobs: matrix: SQL-2017: Target_SQL: 'SQL-2k17-03' + Ex_Groups: 'xSQLv14' SQL-2008R2: Target_SQL: 'SQL-2k8R2-SP3-1' + Ex_Groups: 'xSQLv12' maxParallel: 2 steps: - powershell: | @@ -31,7 +33,7 @@ jobs: displayName: 'Maven build 43' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild43' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild43 -DexcludeGroups=$(Ex_Groups)' testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build 43' javaHomeOption: Path @@ -43,7 +45,7 @@ jobs: displayName: 'Maven build 42' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild42' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pbuild42 -DexcludeGroups=$(Ex_Groups)' testRunTitle: 'Maven build 42' javaHomeOption: Path jdkDirectory: $(JDK11) diff --git a/pom.xml b/pom.xml index 69a849779..3bda11c37 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,17 @@ + + xSQLv15 UTF-8 - 1.2.0 1.6.3 @@ -235,7 +244,8 @@ ${skipTestTag} - ${testGroup} + + ${excludeGroups}, xJDBC42 @@ -305,7 +315,8 @@ ${skipTestTag} - ${testGroup} + + ${excludeGroups} @@ -437,6 +448,23 @@ file:///${session.executionRootDirectory}/maven-version-rules.xml + + org.jacoco + jacoco-maven-plugin + 0.8.2 + + + + jacoco-execs/ + + *.exec + + + + + ${project.build.directory}/jacoco.exec + + diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ActivityCorrelator.java b/src/main/java/com/microsoft/sqlserver/jdbc/ActivityCorrelator.java index 9fa157347..3507550eb 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ActivityCorrelator.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ActivityCorrelator.java @@ -18,25 +18,20 @@ final class ActivityCorrelator { private static Map activityIdTlsMap = new ConcurrentHashMap<>(); static void cleanupActivityId() { - // remove the ActivityId that belongs to this thread. - long uniqueThreadId = Thread.currentThread().getId(); - - if (activityIdTlsMap.containsKey(uniqueThreadId)) { - activityIdTlsMap.remove(uniqueThreadId); - } + // remove ActivityIds that belongs to this thread or no longer have an associated thread. + activityIdTlsMap.entrySet().removeIf(e -> null == e.getValue() || null == e.getValue().getThread() + || e.getValue().getThread() == Thread.currentThread() || !e.getValue().getThread().isAlive()); } // Get the current ActivityId in TLS static ActivityId getCurrent() { // get the value in TLS, not reference - long uniqueThreadId = Thread.currentThread().getId(); - - // Since the Id for each thread is unique, this assures that the below if statement is run only once per thread. - if (!activityIdTlsMap.containsKey(uniqueThreadId)) { - activityIdTlsMap.put(uniqueThreadId, new ActivityId()); + Thread thread = Thread.currentThread(); + if (!activityIdTlsMap.containsKey(thread.getId())) { + activityIdTlsMap.put(thread.getId(), new ActivityId(thread)); } - return activityIdTlsMap.get(uniqueThreadId); + return activityIdTlsMap.get(thread.getId()); } // Increment the Sequence number of the ActivityId in TLS @@ -55,7 +50,11 @@ static void setCurrentActivityIdSentFlag() { ActivityId activityId = getCurrent(); activityId.setSentFlag(); } - + + static Map getActivityIdTlsMap() { + return activityIdTlsMap; + } + /* * Prevent instantiation. */ @@ -65,15 +64,21 @@ private ActivityCorrelator() {} class ActivityId { private final UUID id; + private final Thread thread; private long sequence; private boolean isSentToServer; - ActivityId() { + ActivityId(Thread thread) { id = UUID.randomUUID(); + this.thread = thread; sequence = 0; isSentToServer = false; } + Thread getThread() { + return thread; + } + UUID getId() { return id; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 8b118af1a..c04782ace 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -3115,8 +3115,8 @@ void writeMessageHeader() throws SQLServerException { boolean includeTraceHeader = false; int totalHeaderLength = TDS.MESSAGE_HEADER_LENGTH; if (TDS.PKT_QUERY == tdsMessageType || TDS.PKT_RPC == tdsMessageType) { - if (con.isDenaliOrLater() && !ActivityCorrelator.getCurrent().isSentToServer() - && Util.IsActivityTraceOn()) { + if (con.isDenaliOrLater() && Util.isActivityTraceOn() + && !ActivityCorrelator.getCurrent().isSentToServer()) { includeTraceHeader = true; totalHeaderLength += TDS.TRACE_HEADER_LENGTH; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 633587a38..d71779ce4 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -888,7 +888,7 @@ final boolean isSessionUnAvailable() { final void setMaxFieldSize(int limit) throws SQLServerException { // assert limit >= 0; if (maxFieldSize != limit) { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } // If no limit on field size, set text size to max (2147483647), NOT default (0 --> 4K) @@ -918,7 +918,7 @@ final void initResettableValues() { final void setMaxRows(int limit) throws SQLServerException { // assert limit >= 0; if (maxRows != limit) { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } connectionCommand("SET ROWCOUNT " + limit, "setMaxRows"); @@ -2541,8 +2541,6 @@ void Prelogin(String serverName, int portNumber) throws SQLServerException { final byte[] preloginResponse = new byte[TDS.INITIAL_PACKET_SIZE]; String preloginErrorLogString = " Prelogin error: host " + serverName + " port " + portNumber; - ActivityId activityId = ActivityCorrelator.getNext(); - final byte[] actIdByteArray = Util.asGuidByteArray(activityId.getId()); final byte[] conIdByteArray = Util.asGuidByteArray(clientConnectionId); int offset; @@ -2558,18 +2556,23 @@ void Prelogin(String serverName, int portNumber) throws SQLServerException { System.arraycopy(conIdByteArray, 0, preloginRequest, offset, conIdByteArray.length); offset += conIdByteArray.length; - // copy ActivityId - System.arraycopy(actIdByteArray, 0, preloginRequest, offset, actIdByteArray.length); - offset += actIdByteArray.length; - - long seqNum = activityId.getSequence(); - Util.writeInt((int) seqNum, preloginRequest, offset); - offset += 4; + if (Util.isActivityTraceOn()) { + ActivityId activityId = ActivityCorrelator.getNext(); + final byte[] actIdByteArray = Util.asGuidByteArray(activityId.getId()); + System.arraycopy(actIdByteArray, 0, preloginRequest, offset, actIdByteArray.length); + offset += actIdByteArray.length; + long seqNum = activityId.getSequence(); + Util.writeInt((int) seqNum, preloginRequest, offset); + offset += 4; + + if (connectionlogger.isLoggable(Level.FINER)) { + connectionlogger.finer(toString() + " ActivityId " + activityId.toString()); + } + } if (connectionlogger.isLoggable(Level.FINER)) { connectionlogger.finer( toString() + " Requesting encryption level:" + TDS.getEncryptionLevel(requestedEncryptionLevel)); - connectionlogger.finer(toString() + " ActivityId " + activityId.toString()); } // Write the entire prelogin request @@ -2585,7 +2588,9 @@ void Prelogin(String serverName, int portNumber) throws SQLServerException { throw e; } - ActivityCorrelator.setCurrentActivityIdSentFlag(); // indicate current ActivityId is sent + if (Util.isActivityTraceOn()) { + ActivityCorrelator.setCurrentActivityIdSentFlag(); // indicate current ActivityId is sent + } // Read the entire prelogin response int responseLength = preloginResponse.length; @@ -3097,7 +3102,7 @@ public String nativeSQL(String sql) throws SQLServerException { public void setAutoCommit(boolean newAutoCommitMode) throws SQLServerException { if (loggerExternal.isLoggable(Level.FINER)) { loggerExternal.entering(getClassNameLogging(), "setAutoCommit", newAutoCommitMode); - if (Util.IsActivityTraceOn()) + if (Util.isActivityTraceOn()) loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } String commitPendingTransaction = ""; @@ -3139,7 +3144,7 @@ final byte[] getTransactionDescriptor() { @Override public void commit() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "commit"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -3152,7 +3157,7 @@ public void commit() throws SQLServerException { @Override public void rollback() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "rollback"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -3242,7 +3247,9 @@ private void clearConnectionResources() { // Clean-up queue etc. related to batching of prepared statement discard actions (sp_unprepare). cleanupPreparedStatementDiscardActions(); - ActivityCorrelator.cleanupActivityId(); + if (Util.isActivityTraceOn()) { + ActivityCorrelator.cleanupActivityId(); + } } // This function is used by the proxy for notifying the pool manager that this connection proxy is closed @@ -3261,12 +3268,13 @@ final void poolCloseEventNotify() throws SQLServerException { connectionCommand("IF @@TRANCOUNT > 0 ROLLBACK TRAN" /* +close connection */, "close connection"); } notifyPooledConnection(null); - ActivityCorrelator.cleanupActivityId(); + if (Util.isActivityTraceOn()) { + ActivityCorrelator.cleanupActivityId(); + } if (connectionlogger.isLoggable(Level.FINER)) { connectionlogger.finer(toString() + " Connection closed and returned to connection pool"); } } - } @Override @@ -3308,7 +3316,7 @@ public boolean isReadOnly() throws SQLServerException { @Override public void setCatalog(String catalog) throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "setCatalog", catalog); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -3335,7 +3343,7 @@ String getSCatalog() throws SQLServerException { public void setTransactionIsolation(int level) throws SQLServerException { if (loggerExternal.isLoggable(Level.FINER)) { loggerExternal.entering(getClassNameLogging(), "setTransactionIsolation", level); - if (Util.IsActivityTraceOn()) { + if (Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } } @@ -5275,7 +5283,7 @@ final private Savepoint setNamedSavepoint(String sName) throws SQLServerExceptio @Override public Savepoint setSavepoint(String sName) throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "setSavepoint", sName); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -5287,7 +5295,7 @@ public Savepoint setSavepoint(String sName) throws SQLServerException { @Override public Savepoint setSavepoint() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "setSavepoint"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -5299,7 +5307,7 @@ public Savepoint setSavepoint() throws SQLServerException { @Override public void rollback(Savepoint s) throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "rollback", s); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -5324,7 +5332,7 @@ public int getHoldability() throws SQLServerException { public void setHoldability(int holdability) throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "setHoldability", holdability); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkValidHoldability(holdability); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java index 2dbd1a475..de376a5e3 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java @@ -450,7 +450,7 @@ public boolean supportsSharding() throws SQLException { @Override public java.sql.ResultSet getCatalogs() throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -483,7 +483,7 @@ public String getCatalogTerm() throws SQLServerException { @Override public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, String table, String col) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -509,7 +509,7 @@ public java.sql.ResultSet getColumnPrivileges(String catalog, String schema, Str @Override public java.sql.ResultSet getTables(String catalog, String schema, String table, String types[]) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -621,7 +621,7 @@ private static String EscapeIDName(String inID) throws SQLServerException { @Override public java.sql.ResultSet getColumns(String catalog, String schema, String table, String col) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -764,7 +764,7 @@ public java.sql.ResultSet getClientInfoProperties() throws SQLException { @Override public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -800,7 +800,7 @@ public java.sql.ResultSet getBestRowIdentifier(String catalog, String schema, St @Override public java.sql.ResultSet getCrossReference(String cat1, String schem1, String tab1, String cat2, String schem2, String tab2) throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -930,7 +930,7 @@ private ResultSet executeSPFkeys(String[] procParams) throws SQLException, SQLTi @Override public java.sql.ResultSet getIndexInfo(String cat, String schema, String table, boolean unique, boolean approximate) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1106,7 +1106,7 @@ public String getNumericFunctions() throws SQLServerException { @Override public java.sql.ResultSet getPrimaryKeys(String cat, String schema, String table) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1129,7 +1129,7 @@ public java.sql.ResultSet getPrimaryKeys(String cat, String schema, @Override public java.sql.ResultSet getProcedureColumns(String catalog, String schema, String proc, String col) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1172,7 +1172,7 @@ public java.sql.ResultSet getProcedureColumns(String catalog, String schema, Str @Override public java.sql.ResultSet getProcedures(String catalog, String schema, String proc) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -1198,7 +1198,7 @@ public String getProcedureTerm() throws SQLServerException { @Override public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -1225,7 +1225,7 @@ public ResultSet getPseudoColumns(String catalog, String schemaPattern, String t @Override public java.sql.ResultSet getSchemas() throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1305,7 +1305,7 @@ private java.sql.ResultSet getSchemasInternal(String catalog, @Override public java.sql.ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } return getSchemasInternal(catalog, schemaPattern); @@ -1379,7 +1379,7 @@ public String getSystemFunctions() throws SQLServerException { @Override public java.sql.ResultSet getTablePrivileges(String catalog, String schema, String table) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1400,7 +1400,7 @@ public java.sql.ResultSet getTablePrivileges(String catalog, String schema, @Override public java.sql.ResultSet getTableTypes() throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1417,7 +1417,7 @@ public String getTimeDateFunctions() throws SQLServerException { @Override public java.sql.ResultSet getTypeInfo() throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1502,7 +1502,7 @@ public String getURL() throws SQLServerException { @Override public String getUserName() throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1524,7 +1524,7 @@ public String getUserName() throws SQLServerException, SQLTimeoutException { @Override public java.sql.ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLServerException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2156,7 +2156,7 @@ public boolean supportsBatchUpdates() throws SQLServerException { @Override public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2258,7 +2258,7 @@ public boolean supportsResultSetHoldability(int holdability) throws SQLServerExc @Override public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2289,7 +2289,7 @@ public ResultSet getAttributes(String catalog, String schemaPattern, String type @Override public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2303,7 +2303,7 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, @Override public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException, SQLTimeoutException { - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index 4f3edc2e9..dd6f2a30f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -567,7 +567,7 @@ String getClassNameLogging() { try { register(); } catch (SQLException e) { - if (drLogger.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (drLogger.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { drLogger.finer("Error registering driver: " + e); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java index 2390970ac..78717bf7a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerException.java @@ -156,21 +156,27 @@ static String getErrString(String errCode) { super(errText, errState, errNum); initCause(cause); logException(null, errText, true); - ActivityCorrelator.setCurrentActivityIdSentFlag(); // set the activityid flag so that we don't send the current - // ActivityId later. + if (Util.isActivityTraceOn()) { + // set the activityid flag so that we don't send the current ActivityId later. + ActivityCorrelator.setCurrentActivityIdSentFlag(); + } } SQLServerException(String errText, Throwable cause) { super(errText); initCause(cause); logException(null, errText, true); - ActivityCorrelator.setCurrentActivityIdSentFlag(); + if (Util.isActivityTraceOn()) { + ActivityCorrelator.setCurrentActivityIdSentFlag(); + } } SQLServerException(Object obj, String errText, String errState, int errNum, boolean bStack) { super(errText, errState, errNum); logException(obj, errText, bStack); - ActivityCorrelator.setCurrentActivityIdSentFlag(); + if (Util.isActivityTraceOn()) { + ActivityCorrelator.setCurrentActivityIdSentFlag(); + } } /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java index 341fd6681..5fea2bad0 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java @@ -437,7 +437,7 @@ private String buildParamTypeDefinitions(Parameter[] params, boolean renewDefini @Override public java.sql.ResultSet executeQuery() throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeQuery"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -462,7 +462,7 @@ final java.sql.ResultSet executeQueryInternal() throws SQLServerException, SQLTi @Override public int executeUpdate() throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeUpdate"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -484,7 +484,7 @@ public int executeUpdate() throws SQLServerException, SQLTimeoutException { public long executeLargeUpdate() throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeLargeUpdate"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -496,7 +496,7 @@ public long executeLargeUpdate() throws SQLServerException, SQLTimeoutException @Override public boolean execute() throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "execute"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -544,7 +544,7 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE // Note: similar logic in SQLServerStatement.doExecuteStatement setMaxRowsAndMaxFieldSize(); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -1938,7 +1938,7 @@ public final void clearBatch() throws SQLServerException { @Override public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeBatch"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2095,7 +2095,7 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL @Override public long[] executeLargeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeLargeBatch"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2701,7 +2701,7 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th // Make sure any previous maxRows limitation on the connection is removed. connection.setMaxRows(0); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } // Create the parameter array that we'll use for all the items in this batch. diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java index f17289f52..ca043a8bc 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java @@ -622,7 +622,7 @@ private void closeInternal() { @Override public void close() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "close"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } closeInternal(); @@ -970,7 +970,7 @@ private void updateCurrentRow(int rowsToMove) { @Override public boolean next() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "next"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } if (logger.isLoggable(java.util.logging.Level.FINER)) @@ -1296,7 +1296,7 @@ public boolean isLast() throws SQLException { @Override public void beforeFirst() throws SQLException { loggerExternal.entering(getClassNameLogging(), "beforeFirst"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } if (logger.isLoggable(java.util.logging.Level.FINER)) @@ -1327,7 +1327,7 @@ private void moveBeforeFirst() throws SQLServerException { @Override public void afterLast() throws SQLException { loggerExternal.entering(getClassNameLogging(), "afterLast"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -1551,7 +1551,7 @@ public int getRow() throws SQLException { @Override public boolean absolute(int row) throws SQLException { loggerExternal.entering(getClassNameLogging(), "absolute"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } if (logger.isLoggable(java.util.logging.Level.FINER)) @@ -4628,7 +4628,7 @@ public int getHoldability() throws SQLException { @Override public void insertRow() throws SQLException { loggerExternal.entering(getClassNameLogging(), "insertRow"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -4735,7 +4735,7 @@ private void doInsertRowRPC(TDSCommand command, String tableName) throws SQLServ @Override public void updateRow() throws SQLException { loggerExternal.entering(getClassNameLogging(), "updateRow"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } final class UpdateRowRPC extends TDSCommand { @@ -4820,7 +4820,7 @@ final boolean hasUpdatedColumns() { @Override public void deleteRow() throws SQLException { loggerExternal.entering(getClassNameLogging(), "deleteRow"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } final class DeleteRowRPC extends TDSCommand { @@ -4884,7 +4884,7 @@ private void doDeleteRowRPC(TDSCommand command) throws SQLServerException { @Override public void refreshRow() throws SQLException { loggerExternal.entering(getClassNameLogging(), "refreshRow"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -5322,21 +5322,9 @@ boolean onNBCRow(TDSReader tdsReader) throws SQLServerException { boolean onDone(TDSReader tdsReader) throws SQLServerException { ensureStartMark(); - int token = tdsReader.peekTokenType(); StreamDone doneToken = new StreamDone(); doneToken.setFromTDS(tdsReader); - int packetType = tdsReader.peekTokenType(); - if (-1 != packetType && TDS.TDS_DONEINPROC == token) { - switch (packetType) { - case TDS.TDS_ENV_CHG: - case TDS.TDS_ERR: - return true; - default: - break; - } - } - // Done with all the rows in this fetch buffer and done with parsing // unless it's a server cursor, in which case there is a RETSTAT and // another DONE token to follow. diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java index 262240bfd..e232b32e0 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java @@ -686,7 +686,7 @@ public void closeOnCompletion() throws SQLException { @Override public java.sql.ResultSet executeQuery(String sql) throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeQuery", sql); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -704,7 +704,7 @@ final SQLServerResultSet executeQueryInternal(String sql) throws SQLServerExcept @Override public int executeUpdate(String sql) throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeUpdate", sql); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -724,7 +724,7 @@ public int executeUpdate(String sql) throws SQLServerException, SQLTimeoutExcept public long executeLargeUpdate(String sql) throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeLargeUpdate", sql); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -737,7 +737,7 @@ public long executeLargeUpdate(String sql) throws SQLServerException, SQLTimeout @Override public boolean execute(String sql) throws SQLServerException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "execute", sql); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -834,7 +834,7 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException { // Note: similar logic in SQLServerPreparedStatement.doExecutePreparedStatement setMaxRowsAndMaxFieldSize(); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } if (isCursorable(executeMethod) && isSelect(sql)) { @@ -914,7 +914,7 @@ private void doExecuteStatementBatch(StmtBatchExecCmd execCmd) throws SQLServerE // Make sure any previous maxRows limitation on the connection is removed. connection.setMaxRows(0); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -1606,15 +1606,16 @@ boolean onInfo(TDSReader tdsReader) throws SQLServerException { clearLastResult(); } - // If there are no more results, then we're done. - // All we had to do was to close out the previous results. + // If there are no more results, then we're done. All we had to do was to close out the previous results. if (!moreResults) { return false; } // Figure out the next result. NextResult nextResult = new NextResult(); - TDSParser.parse(resultsReader(), nextResult); + + // Signal to not read all token other than TDS_MSG if reading only warnings + TDSParser.parse(resultsReader(), nextResult, !clearFlag); // Check for errors first. if (null != nextResult.getDatabaseError()) { @@ -1622,6 +1623,10 @@ boolean onInfo(TDSReader tdsReader) throws SQLServerException { nextResult.getDatabaseError(), false); } + // If we didn't clear current ResultSet, we wanted to read only warnings. Return back from here. + if (!clearFlag) + return false; + // Not an error. Is it a result set? else if (nextResult.isResultSet()) { resultSet = new SQLServerResultSet(this); @@ -1767,7 +1772,7 @@ public void clearBatch() throws SQLServerException { @Override public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeBatch"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -1844,7 +1849,7 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL public long[] executeLargeBatch() throws SQLServerException, BatchUpdateException, SQLTimeoutException { loggerExternal.entering(getClassNameLogging(), "executeLargeBatch"); - if (loggerExternal.isLoggable(Level.FINER) && Util.IsActivityTraceOn()) { + if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } checkClosed(); @@ -2030,7 +2035,7 @@ public final boolean execute(java.lang.String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException { if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) { loggerExternal.entering(getClassNameLogging(), "execute", new Object[] {sql, autoGeneratedKeys}); - if (Util.IsActivityTraceOn()) { + if (Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } } @@ -2080,7 +2085,7 @@ public final boolean execute(java.lang.String sql, public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLServerException, SQLTimeoutException { if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) { loggerExternal.entering(getClassNameLogging(), "executeUpdate", new Object[] {sql, autoGeneratedKeys}); - if (Util.IsActivityTraceOn()) { + if (Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } } @@ -2108,7 +2113,7 @@ public final long executeLargeUpdate(String sql, if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) { loggerExternal.entering(getClassNameLogging(), "executeLargeUpdate", new Object[] {sql, autoGeneratedKeys}); - if (Util.IsActivityTraceOn()) { + if (Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java index 1ff246805..4d70d41b5 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java @@ -30,9 +30,7 @@ final class Util { final static char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; final static String WSIDNotAvailable = ""; // default string when WSID is not available - final static String ActivityIdTraceProperty = "com.microsoft.sqlserver.jdbc.traceactivity"; - static boolean activityIdTraceOn = "on" - .equalsIgnoreCase(LogManager.getLogManager().getProperty(ActivityIdTraceProperty)); + final static String ACTIVITY_ID_TRACE_PROPERTY = "com.microsoft.sqlserver.jdbc.traceactivity"; // The JRE is identified by the string below so that the driver can make // any vendor or version specific decisions @@ -768,8 +766,10 @@ static final String readGUID(byte[] inputGUID) throws SQLServerException { return sb.toString(); } - static boolean IsActivityTraceOn() { - return activityIdTraceOn; + static boolean isActivityTraceOn() { + LogManager lm = LogManager.getLogManager(); + String activityTrace = lm.getProperty(ACTIVITY_ID_TRACE_PROPERTY); + return ("on".equalsIgnoreCase(activityTrace)); } /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java b/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java index 3cd436107..edf232336 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java @@ -26,7 +26,29 @@ static void parse(TDSReader tdsReader, String logContext) throws SQLServerExcept parse(tdsReader, new TDSTokenHandler(logContext)); } + /** + * Default parse method to parse all tokens in TDS stream. + * + * @param tdsReader + * @param tdsTokenHandler + * @throws SQLServerException + */ static void parse(TDSReader tdsReader, TDSTokenHandler tdsTokenHandler) throws SQLServerException { + parse(tdsReader, tdsTokenHandler, false); + } + + /** + * Underlying parse method to parse all tokens in TDS stream. Also accepts 'readOnlyWarningFlag' to parse only + * SQLWarnings received in TDS_MSG tokens. + * + * @param tdsReader + * @param tdsTokenHandler + * @param readOnlyWarningsFlag + * - true if only TDS_MSG tokens need to be parsed in TDS Stream. false - to parse all tokens in TDS Stream. + * @throws SQLServerException + */ + static void parse(TDSReader tdsReader, TDSTokenHandler tdsTokenHandler, + boolean readOnlyWarningsFlag) throws SQLServerException { final boolean isLogging = logger.isLoggable(Level.FINEST); // Process TDS tokens from the token stream until we're told to stop. @@ -41,7 +63,10 @@ static void parse(TDSReader tdsReader, TDSTokenHandler tdsTokenHandler) throws S logger.finest(tdsReader.toString() + ": " + tdsTokenHandler.logContext + ": Processing " + ((-1 == tdsTokenType) ? "EOF" : TDS.getTokenName(tdsTokenType))); } - + if (readOnlyWarningsFlag && TDS.TDS_MSG != tdsTokenType) { + parsing = false; + return; + } switch (tdsTokenType) { case TDS.TDS_SSPI: parsing = tdsTokenHandler.onSSPI(tdsReader); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java new file mode 100644 index 000000000..9af431ded --- /dev/null +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ActivityIDTest.java @@ -0,0 +1,168 @@ +package com.microsoft.sqlserver.jdbc; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.logging.LogManager; +import java.util.stream.IntStream; + +import javax.sql.PooledConnection; + +import org.junit.ComparisonFailure; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; + +import com.microsoft.sqlserver.testframework.AbstractTest; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + + +@RunWith(JUnitPlatform.class) +public class ActivityIDTest extends AbstractTest { + + @Test + public void testActivityID() throws Exception { + int numExecution = 20; + ExecutorService es = Executors.newFixedThreadPool(numExecution); + CountDownLatch latch = new CountDownLatch(numExecution); + es.execute(() -> { + IntStream.range(0, numExecution).forEach(i -> { + try (Connection c = getConnection(); Statement s = c.createStatement(); + ResultSet rs = s.executeQuery("SELECT @@VERSION AS 'SQL Server Version'")) { + while (rs.next()) { + rs.getString(1); + } + } catch (SQLException e) { + fail(e.toString()); + } + latch.countDown(); + }); + }); + latch.await(); + es.shutdown(); + assertEquals(0, ActivityCorrelator.getActivityIdTlsMap().size()); + } + + @Test + public void testActivityIDPooled() throws Exception { + int poolsize = 10; + int numPooledExecution = 200; + + HikariConfig config = new HikariConfig(); + config.setJdbcUrl(connectionString); + config.setMaximumPoolSize(poolsize); + ExecutorService es = Executors.newFixedThreadPool(poolsize); + CountDownLatch latchPoolOuterThread = new CountDownLatch(1); + Thread t = new Thread(new Runnable() { + CountDownLatch latchPool = new CountDownLatch(numPooledExecution); + + public void run() { + HikariDataSource ds = new HikariDataSource(config); + es.execute(() -> { + IntStream.range(0, numPooledExecution).forEach(i -> { + try (Connection c = ds.getConnection(); Statement s = c.createStatement(); + ResultSet rs = s.executeQuery("SELECT @@VERSION AS 'SQL Server Version'")) { + while (rs.next()) { + rs.getString(1); + } + } catch (SQLException e) { + fail(e.toString()); + } + latchPool.countDown(); + }); + }); + try { + latchPool.await(); + } catch (InterruptedException e) { + fail(e.toString()); + } finally { + if (null != ds) { + es.shutdown(); + ds.close(); + } + } + latchPoolOuterThread.countDown(); + } + }); + t.run(); + latchPoolOuterThread.await(); + + try { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + stmt.execute("SELECT @@VERSION AS 'SQL Server Version'"); + } + } catch (SQLException e) { + fail(e.toString()); + } + + try { + assertEquals(0, ActivityCorrelator.getActivityIdTlsMap().size()); + } catch (ComparisonFailure e) { + Set threadSet = Thread.getAllStackTraces().keySet(); + System.out.println("List of threads alive:"); + for (Thread thread : threadSet) { + System.out.println(thread.toString()); + } + System.out.println("List of entries in the ActivityID map:"); + System.out.println(ActivityCorrelator.getActivityIdTlsMap().toString()); + fail(e.toString()); + } + } + + @Test + public void testActivityIDPooledConnection() throws Exception { + int poolsize = 10; + int numPooledExecution = 200; + + PooledConnection pooledCon = ((SQLServerConnectionPoolDataSource) dsPool).getPooledConnection(); + ExecutorService es = Executors.newFixedThreadPool(poolsize); + try { + CountDownLatch latchPool = new CountDownLatch(numPooledExecution); + es.execute(() -> { + IntStream.range(0, numPooledExecution).forEach(i -> { + try (Connection c = pooledCon.getConnection(); Statement s = c.createStatement(); ResultSet rs = s + .executeQuery("SELECT @@VERSION AS 'SQL Server Version'")) {} catch (SQLException e) { + fail(e.toString()); + } + latchPool.countDown(); + }); + }); + latchPool.await(); + } finally { + es.shutdown(); + pooledCon.close(); + } + assertEquals(0, ActivityCorrelator.getActivityIdTlsMap().size()); + } + + @AfterAll + public static void teardown() throws Exception { + String activityIDTraceOff = Util.ACTIVITY_ID_TRACE_PROPERTY + "=off"; + try (InputStream is = new ByteArrayInputStream(activityIDTraceOff.getBytes());) { + LogManager lm = LogManager.getLogManager(); + lm.readConfiguration(is); + } + } + + @BeforeAll + public static void testSetup() throws Exception { + String activityIDTraceOn = Util.ACTIVITY_ID_TRACE_PROPERTY + "=on"; + try (InputStream is = new ByteArrayInputStream(activityIDTraceOn.getBytes());) { + LogManager lm = LogManager.getLogManager(); + lm.readConfiguration(is); + } + } +} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index e4ead7fd5..eb85026f3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedReader; import java.io.File; @@ -35,12 +34,10 @@ import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; -import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.Constants; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; import microsoft.sql.DateTimeOffset; @@ -74,14 +71,9 @@ public class AESetup extends AbstractTest { */ @BeforeAll public static void setUpConnection() throws TestAbortedException, Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"; readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString); Statement stmt = con.createStatement()) { dropCEK(stmt); dropCMK(stmt); } @@ -108,11 +100,7 @@ public static void setUpConnection() throws TestAbortedException, Exception { */ @AfterAll public static void dropAll() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { dropTables(stmt); dropCEK(stmt); dropCMK(stmt); @@ -131,7 +119,6 @@ private static void readFromFile(String inputFile, String lookupValue) throws IO filePath = TestUtils.getCurrentClassPath(); try { File f = new File(filePath + inputFile); - assumeTrue(f.exists(), TestResource.getResource("R_noKeyStore")); try (BufferedReader buffer = new BufferedReader(new FileReader(f))) { String readLine = ""; String[] linecontents; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index e39c228b7..f52cc3704 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -7,18 +7,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.math.BigDecimal; +import java.sql.Connection; import java.sql.Date; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; import java.util.LinkedList; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,7 +29,6 @@ import com.microsoft.sqlserver.jdbc.RandomData; import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.SQLServerStatement; @@ -34,7 +36,6 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; -import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; import microsoft.sql.DateTimeOffset; @@ -45,6 +46,9 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xSQLv12) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) public class CallableStatementTest extends AESetup { private static String multiStatementsProcedure = RandomUtil.getIdentifier("multiStatementsProcedure"); @@ -88,10 +92,6 @@ public class CallableStatementTest extends AESetup { */ @BeforeAll public static void initCallableStatementTest() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTables(); numericValues = createNumericValues(nullable); @@ -118,9 +118,6 @@ public static void initCallableStatementTest() throws Exception { @AfterAll public static void dropAll() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } dropTables(); dropProcedures(); } @@ -282,8 +279,7 @@ public void testOutputProcedure4() throws SQLException { } private static void dropProcedures() throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProcedure2), stmt); @@ -307,8 +303,7 @@ private static void dropProcedures() throws SQLException { } private static void dropTables() throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); @@ -336,8 +331,8 @@ private static void createTables() throws SQLException { + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL" + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -357,8 +352,8 @@ private static void createTables() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -468,8 +463,8 @@ private static void createTables() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -481,8 +476,8 @@ private static void createTables() throws SQLException { + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -496,8 +491,8 @@ private static void createTables() throws SQLException { + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -511,8 +506,8 @@ private static void createTables() throws SQLException { + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + Constants.CEK_NAME + ") NULL," + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { stmt.execute(sql); } catch (SQLException e) { fail(e.getMessage()); @@ -522,9 +517,8 @@ private static void createTables() throws SQLException { private static void populateTable4() throws SQLException { String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(table4) + " values( " + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, - stmtColEncSetting)) { + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + PreparedStatement pstmt = TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { // bit for (int i = 1; i <= 3; i++) { @@ -540,7 +534,7 @@ private static void populateTable3() throws SQLException { + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -648,7 +642,7 @@ private void createMultiInsertionSelection() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -667,7 +661,7 @@ private void createMultiInsertionSelection() throws SQLException { private void MultiInsertionSelection() throws SQLException { String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(multiStatementsProcedure) + " (?,?,?,?,?,?)}"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -721,7 +715,7 @@ private void createInputProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(inputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -743,7 +737,7 @@ private void createInputProcedure() throws SQLException { } private void testInputProcedure(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -786,7 +780,7 @@ private void createInputProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(inputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inputProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -804,7 +798,7 @@ private void createInputProcedure2() throws SQLException { private void testInputProcedure2(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -839,7 +833,7 @@ private void createOutputProcedure3() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure3); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -854,7 +848,7 @@ private void createOutputProcedure3() throws SQLException { private void testOutputProcedure3RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -884,7 +878,7 @@ private void testOutputProcedure3RandomOrder(String sql) throws SQLException { private void testOutputProcedure3Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -905,7 +899,7 @@ private void testOutputProcedure3Inorder(String sql) throws SQLException { private void testOutputProcedure3ReverseOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -929,7 +923,7 @@ private void createOutputProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -946,7 +940,7 @@ private void createOutputProcedure2() throws SQLException { private void testOutputProcedure2RandomOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -999,7 +993,7 @@ private void testOutputProcedure2RandomOrder(String sql, String[] values) throws private void testOutputProcedure2Inorder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1052,7 +1046,7 @@ private void testOutputProcedure2Inorder(String sql, String[] values) throws SQL private void testOutputProcedure2ReverseOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1109,7 +1103,7 @@ private void createOutputProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1126,7 +1120,7 @@ private void createOutputProcedure() throws SQLException { private void testOutputProcedureRandomOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1175,7 +1169,7 @@ private void testOutputProcedureRandomOrder(String sql, String[] values) throws private void testOutputProcedureInorder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1217,7 +1211,7 @@ private void testOutputProcedureInorder(String sql, String[] values) throws SQLE private void testOutputProcedureReverseOrder(String sql, String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1261,7 +1255,7 @@ private void createInOutProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(inoutProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(inoutProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1275,7 +1269,7 @@ private void createInOutProcedure() throws SQLException { private void testInOutProcedure(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1296,7 +1290,7 @@ private void createMixedProcedure() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1312,7 +1306,7 @@ private void createMixedProcedure() throws SQLException { private void testMixedProcedure(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1344,7 +1338,7 @@ private void createMixedProcedure2() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure2); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1360,7 +1354,7 @@ private void createMixedProcedure2() throws SQLException { private void testMixedProcedure2RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1395,7 +1389,7 @@ private void testMixedProcedure2RandomOrder(String sql) throws SQLException { private void testMixedProcedure2Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1420,7 +1414,7 @@ private void createMixedProcedure3() throws SQLException { + TestUtils.escapeSingleQuotes(mixedProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedure3); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1435,7 +1429,7 @@ private void createMixedProcedure3() throws SQLException { private void testMixedProcedure3RandomOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1470,7 +1464,7 @@ private void testMixedProcedure3RandomOrder(String sql) throws SQLException { private void testMixedProcedure3Inorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1492,7 +1486,7 @@ private void testMixedProcedure3Inorder(String sql) throws SQLException { private void testMixedProcedure3ReverseOrder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1518,7 +1512,7 @@ private void createMixedProcedureNumericPrcisionScale() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(mixedProcedureNumericPrcisionScale); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1535,7 +1529,7 @@ private void createMixedProcedureNumericPrcisionScale() throws SQLException { private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1566,7 +1560,7 @@ private void testMixedProcedureNumericPrcisionScaleInorder(String sql) throws SQ private void testMixedProcedureNumericPrcisionScaleParameterName(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1600,7 +1594,7 @@ private void createOutputProcedureChar() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureChar) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureChar); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1618,7 +1612,7 @@ private void createOutputProcedureChar() throws SQLException { private void testOutputProcedureCharInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1668,7 +1662,7 @@ private void testOutputProcedureCharInorder(String sql) throws SQLException { private void testOutputProcedureCharInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1725,7 +1719,7 @@ private void createOutputProcedureNumeric() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureNumeric); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -1746,7 +1740,7 @@ private void createOutputProcedureNumeric() throws SQLException { private void testOutputProcedureNumericInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -1835,7 +1829,7 @@ private void testOutputProcedureNumericInorder(String sql) throws SQLException { private void testcoerctionsOutputProcedureNumericInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2121,7 +2115,7 @@ private void createOutputProcedureBinary() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureBinary) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBinary); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2138,7 +2132,7 @@ private void createOutputProcedureBinary() throws SQLException { private void testOutputProcedureBinaryInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2186,7 +2180,7 @@ private void testOutputProcedureBinaryInorder(String sql) throws SQLException { private void testOutputProcedureBinaryInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2227,7 +2221,7 @@ private void testOutputProcedureBinaryInorderObject(String sql) throws SQLExcept private void testOutputProcedureBinaryInorderString(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2323,7 +2317,7 @@ protected static void createDateTableCallableStatement() throws SQLException { + ");"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); @@ -2362,7 +2356,7 @@ private static void populateDateNormalCase() throws SQLException { String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -2419,7 +2413,7 @@ private void createOutputProcedureDate() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureDate) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDate); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2442,7 +2436,7 @@ private void createOutputProcedureDate() throws SQLException { private void testOutputProcedureDateInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2493,7 +2487,7 @@ private void testOutputProcedureDateInorder(String sql) throws SQLException { private void testOutputProcedureDateInorderObject(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2547,7 +2541,7 @@ private void createOutputProcedureBatch() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedureBatch) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureBatch); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2567,7 +2561,7 @@ private void createOutputProcedureBatch() throws SQLException { private void testOutputProcedureBatchInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2598,7 +2592,7 @@ private void createOutputProcedure4() throws SQLException { + TestUtils.escapeSingleQuotes(outputProcedure4) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedure4); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2621,7 +2615,7 @@ private void createMixedProcedureDateScale() throws SQLException { + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(outputProcedureDateScale); - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); @@ -2640,7 +2634,7 @@ private void createMixedProcedureDateScale() throws SQLException { private void testMixedProcedureDateScaleInorder(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { @@ -2671,7 +2665,7 @@ private void testMixedProcedureDateScaleInorder(String sql) throws SQLException private void testMixedProcedureDateScaleWithParameterName(String sql) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils .getCallableStmt(con, sql, stmtColEncSetting)) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index 99a4da078..e7f2da284 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -12,6 +12,7 @@ import java.sql.Statement; import java.util.LinkedList; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -34,6 +35,9 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xSQLv12) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) public class JDBCEncryptionDecryptionTest extends AESetup { private boolean nullable = false; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 804d236a9..735029d27 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; @@ -16,6 +17,7 @@ import java.util.Date; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +38,9 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xSQLv12) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) public class PrecisionScaleTest extends AESetup { private static java.util.Date date = null; @@ -359,7 +364,7 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro } else { - throw new Exception(TestResource.getResource("R_resultsetNotInstance")); + fail(TestResource.getResource("R_resultsetNotInstance")); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index de5eff03d..1f8a97115 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -13,6 +13,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,9 @@ @RunWith(JUnitPlatform.class) +@Tag(Constants.xSQLv12) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) public class RegressionAlwaysEncryptedTest extends AESetup { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java index df3bf4df3..ac6ccb4c5 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/JDBC43Test.java @@ -4,12 +4,12 @@ */ package com.microsoft.sqlserver.jdbc; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - import java.sql.JDBCType; import java.sql.SQLException; import java.sql.ShardingKey; + import javax.sql.ConnectionPoolDataSource; + import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -24,7 +24,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class JDBC43Test extends AbstractTest { ShardingKey superShardingKey = null; ShardingKey shardingKey = null; @@ -39,7 +38,6 @@ public class JDBC43Test extends AbstractTest { */ @Test public void connectionBuilderTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); SQLServerDataSource ds = new SQLServerDataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -71,7 +69,6 @@ public void connectionBuilderTest() throws TestAbortedException, SQLException { */ @Test public void xaConnectionBuilderTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); SQLServerXADataSource ds = new SQLServerXADataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -102,7 +99,6 @@ public void xaConnectionBuilderTest() throws TestAbortedException, SQLException */ @Test public void connectionPoolDataSourceTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); ConnectionPoolDataSource ds = new SQLServerConnectionPoolDataSource(); try { superShardingKey = ds.createShardingKeyBuilder().subkey("EASTERN_REGION", JDBCType.VARCHAR).build(); @@ -131,8 +127,8 @@ public void connectionPoolDataSourceTest() throws TestAbortedException, SQLExcep * @since 1.9 */ @Test + @Tag("xJDBC42") public void setShardingKeyIfValidTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); try (SQLServerConnection connection43 = (SQLServerConnection43) getConnection()) { try { connection43.setShardingKeyIfValid(shardingKey, 10); @@ -155,8 +151,8 @@ public void setShardingKeyIfValidTest() throws TestAbortedException, SQLExceptio * @since 1.9 */ @Test + @Tag("xJDBC42") public void setShardingKeyTest() throws TestAbortedException, SQLException { - assumeTrue(TestUtils.supportJDBC43(connection)); try (SQLServerConnection connection43 = (SQLServerConnection43) getConnection()) { try { connection43.setShardingKey(shardingKey); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java index 337ab3154..48c8f1efd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java @@ -17,7 +17,6 @@ import java.util.logging.Logger; import java.util.stream.Stream; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -27,7 +26,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SQLServerDriverTest extends AbstractTest { String randomServer = RandomUtil.getIdentifier("Server"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java index 5e0548938..101cfb4b2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SSLCertificateValidation.java @@ -11,14 +11,12 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SSLCertificateValidation { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index 5b3ee675e..6a0444bc2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -49,7 +49,7 @@ protected Object[][] getContents() { {"R_createDropAlterTableFailed", "Create/drop/alter table with preparedStatement failed!"}, {"R_grantFailed", "grant table with preparedStatement failed!"}, {"R_connectionIsClosed", "The connection is closed."}, - {"R_ConnectionURLNull", "The connection URL is null." }, + {"R_ConnectionURLNull", "The connection URL is null."}, {"R_connectionIsNotClosed", "The connection is not closed."}, {"R_invalidExceptionMessage", "Invalid exception message"}, {"R_failedValidate", "failed to validate values in $0} "}, {"R_tableNotDropped", "table not dropped. "}, diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java index 4a44772ec..c97cc3022 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java @@ -10,6 +10,8 @@ import java.io.ByteArrayInputStream; import java.io.CharArrayReader; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.sql.CallableStatement; import java.sql.Connection; @@ -21,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.logging.LogManager; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.Constants; @@ -706,9 +709,15 @@ public static String escapeSingleQuotes(String name) { /** * Enables Activity Tracing + * + * @throws IOException + * @throws SecurityException */ - public static void setActivityTraceOn() { - Util.activityIdTraceOn = true; + public static void setActivityTraceOn() throws SecurityException, IOException { + String activityIDTraceOn = Util.ACTIVITY_ID_TRACE_PROPERTY + "=on"; + try (InputStream is = new ByteArrayInputStream(activityIDTraceOn.getBytes());) { + LogManager lm = LogManager.getLogManager(); + lm.readConfiguration(is); + } } - } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java index 74cbf0912..95b90c597 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TimeoutTest.java @@ -10,7 +10,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; @@ -29,10 +28,10 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class TimeoutTest extends AbstractTest { private static final int TIMEOUT_SECONDS = 2; private static final String WAIT_FOR_ONE_MINUTE_SQL = "WAITFOR DELAY '00:01:00'"; @@ -57,16 +56,16 @@ public void after() throws InterruptedException { } @Test + @Tag(Constants.xAzureSQLDW) public void testBasicQueryTimeout() { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_issueAzureDW")); assertThrows(SQLTimeoutException.class, () -> { runQuery(WAIT_FOR_ONE_MINUTE_SQL, TIMEOUT_SECONDS); }); } @Test + @Tag(Constants.xAzureSQLDW) public void testQueryTimeoutValid() { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_issueAzureDW")); long start = System.currentTimeMillis(); assertThrows(SQLTimeoutException.class, () -> { runQuery(WAIT_FOR_ONE_MINUTE_SQL, TIMEOUT_SECONDS); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java index 2caaf0b45..13c76c0f9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/UtilTest.java @@ -9,7 +9,6 @@ import java.sql.SQLException; import java.util.UUID; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -20,7 +19,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class UtilTest { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java index 4aa221785..4d9e35558 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -17,6 +18,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBStatement; import com.microsoft.sqlserver.testframework.DBTable; @@ -35,8 +37,10 @@ public class BulkCopyAllTypesTest extends AbstractTest { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testTVPResultSet() throws SQLException { if (isSqlAzureDW()) { + // TODO : Fix this test to run with Azure DW testBulkCopyResultSet(false, null, null); testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); } else { @@ -85,8 +89,7 @@ private void setupVariation() throws SQLException { } private void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java index 6fba3512a..953f3ac91 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -49,6 +50,7 @@ */ @RunWith(JUnitPlatform.class) @DisplayName("Test bulkCopy with CSV") +@Tag(Constants.xAzureSQLDW) public class BulkCopyCSVTest extends AbstractTest { static String inputFile = "BulkCopyCSVTestInput.csv"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java index 6a0ec4b1a..2505b79f1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyColumnMappingTest.java @@ -14,6 +14,7 @@ import java.text.MessageFormat; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -38,6 +39,7 @@ public class BulkCopyColumnMappingTest extends BulkCopyTestSetUp { @Test @DisplayName("BulkCopy:test no explicit column mapping") + @Tag(Constants.xAzureSQLDW) public void testNoExplicitCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable destTable = null; @@ -60,6 +62,7 @@ public void testNoExplicitCM() throws SQLException { @Test @DisplayName("BulkCopy:test explicit column mapping") + @Tag(Constants.xAzureSQLDW) public void testExplicitCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable destTable = null; @@ -146,6 +149,7 @@ public void testUnicodeCM() throws SQLException { @Test @DisplayName("BulkCopy:test repetitive column mapping") + @Tag(Constants.xAzureSQLDW) public void testRepetitiveCM() throws SQLException { try (DBConnection con = new DBConnection(connectionString); DBStatement stmt = con.createStatement()) { DBTable sourceTable1 = null; @@ -369,8 +373,9 @@ private void validateValuesRepetitiveCM(DBConnection con, DBTable sourceTable, try (DBStatement srcStmt = con.createStatement(); DBStatement dstStmt = con.createStatement(); DBResultSet srcResultSet = srcStmt.executeQuery("SELECT * FROM " + sourceTable.getEscapedTableName() + " ORDER BY" + sourceTable.getEscapedColumnName(0)); - DBResultSet dstResultSet = dstStmt.executeQuery("SELECT * FROM " - + destinationTable.getEscapedTableName() + " ORDER BY" + destinationTable.getEscapedColumnName(0))) { + DBResultSet dstResultSet = dstStmt + .executeQuery("SELECT * FROM " + destinationTable.getEscapedTableName() + " ORDER BY" + + destinationTable.getEscapedColumnName(0))) { ResultSetMetaData sourceMeta = ((ResultSet) srcResultSet.product()).getMetaData(); int totalColumns = sourceMeta.getColumnCount(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java index b4b485d14..2e3dd723c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyConnectionTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.junit.platform.runner.JUnitPlatform; @@ -41,6 +42,7 @@ public class BulkCopyConnectionTest extends BulkCopyTestSetUp { * @return */ @TestFactory + @Tag(Constants.xAzureSQLDW) public Stream generateBulkCopyConstructorTest() { List testData = createTestDatatestBulkCopyConstructor(); // had to avoid using lambdas as we need to test against java7 @@ -64,6 +66,7 @@ public void execute() { * @return */ @TestFactory + @Tag(Constants.xAzureSQLDW) public Stream generateBulkCopyOptionsTest() { List testData = createTestDatatestBulkCopyOption(); return testData.stream().map(new Function() { @@ -151,6 +154,7 @@ public void execute() throws SQLException { */ @Test @DisplayName("BulkCopy:test null SQLServerBulkCopyOptions") + @Tag(Constants.xAzureSQLDW) public void testEmptyBulkCopyOptions() { BulkCopyTestWrapper bulkWrapper = new BulkCopyTestWrapper(connectionString); bulkWrapper.setUsingConnection((0 == Constants.RANDOM.nextInt(2)) ? true : false, ds); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java index 1741c9c73..d2fc014d4 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyISQLServerBulkRecordTest.java @@ -14,6 +14,7 @@ import java.util.Set; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,6 +34,7 @@ */ @RunWith(JUnitPlatform.class) @DisplayName("Test ISQLServerBulkRecord") +@Tag(Constants.xAzureSQLDW) public class BulkCopyISQLServerBulkRecordTest extends AbstractTest { @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java index 1b6c18a24..3cac1ebeb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyResultSetCursorTest.java @@ -17,6 +17,7 @@ import java.util.TimeZone; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -27,10 +28,12 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class BulkCopyResultSetCursorTest extends AbstractTest { static BigDecimal[] expectedBigDecimals = {new BigDecimal("12345.12345"), new BigDecimal("125.123"), @@ -233,7 +236,7 @@ private static void createTables(Statement stmt) throws SQLException { */ @AfterAll public static void terminate() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { dropTables(stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java index d8ee803dd..c461b13c8 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyRowSetTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertEquals; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -16,7 +15,10 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.RandomData; @@ -25,15 +27,19 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; + +@RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class BulkCopyRowSetTest extends AbstractTest { - - private static String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); - + + private static String tableName = AbstractSQLGenerator + .escapeIdentifier(RandomUtil.getIdentifier("BulkCopyFloatTest")); + @Test public void testBulkCopyFloatRowSet() throws SQLException { - try (Connection con = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Connection con = getConnection(); Statement stmt = connection.createStatement()) { RowSetFactory rsf = RowSetProvider.newFactory(); CachedRowSet crs = rsf.createCachedRowSet(); RowSetMetaData rsmd = new RowSetMetaDataImpl(); @@ -42,32 +48,32 @@ public void testBulkCopyFloatRowSet() throws SQLException { rsmd.setColumnName(2, "c2"); rsmd.setColumnType(1, java.sql.Types.FLOAT); rsmd.setColumnType(2, java.sql.Types.FLOAT); - + Float floatData = RandomData.generateReal(false); - + crs.setMetaData(rsmd); crs.moveToInsertRow(); crs.updateFloat(1, floatData); crs.updateFloat(2, floatData); crs.insertRow(); crs.moveToCurrentRow(); - + try (SQLServerBulkCopy bcOperation = new SQLServerBulkCopy(con)) { bcOperation.setDestinationTableName(tableName); bcOperation.writeToServer(crs); } - - ResultSet rs = stmt.executeQuery("select * from " + tableName); - rs.next(); - assertEquals(floatData, (Float) rs.getFloat(1)); - assertEquals(floatData, (Float) rs.getFloat(2)); + + try (ResultSet rs = stmt.executeQuery("select * from " + tableName)) { + rs.next(); + assertEquals(floatData, (Float) rs.getFloat(1)); + assertEquals(floatData, (Float) rs.getFloat(2)); + } } } - + @BeforeAll public static void testSetup() throws TestAbortedException, Exception { - try (Connection connection = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql1 = "create table " + tableName + " (c1 float, c2 real)"; stmt.execute(sql1); } @@ -75,8 +81,7 @@ public static void testSetup() throws TestAbortedException, Exception { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = DriverManager.getConnection(connectionString); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableName, stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java index 2c716eeed..2ca740a18 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimeoutTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -36,6 +37,7 @@ public class BulkCopyTimeoutTest extends BulkCopyTestSetUp { */ @Test @DisplayName("BulkCopy:test zero timeout") + @Tag(Constants.xAzureSQLDW) public void testZeroTimeOut() throws SQLException { testBulkCopyWithTimeout(0); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java index 3a6f89002..1afee9ce0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/ISQLServerBulkRecordIssuesTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -35,6 +36,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) @@ -81,6 +83,7 @@ public void testVarchar() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSmalldatetime() throws Exception { variation = "testSmalldatetime"; BulkData bData = new BulkData(variation); @@ -109,6 +112,7 @@ public void testSmalldatetime() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSmalldatetimeOutofRange() throws Exception { variation = "testSmalldatetimeOutofRange"; BulkData bData = new BulkData(variation); @@ -229,7 +233,7 @@ public void testSendValidValueforBinaryColumnAsString() throws Exception { */ @BeforeAll public static void setupHere() throws SQLException, SecurityException, IOException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); } @@ -242,7 +246,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterEach public void afterEachTests() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java index 1978532f6..3e78c39fb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.math.BigDecimal; import java.sql.DatabaseMetaData; @@ -17,7 +16,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; @@ -25,6 +23,7 @@ import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBPreparedStatement; import com.microsoft.sqlserver.testframework.DBResultSet; @@ -34,8 +33,6 @@ @RunWith(JUnitPlatform.class) -@DisplayName("BVT Test") -@Tag("AzureDWTest") public class BvtTest extends AbstractTest { private static String driverNamePattern = "Microsoft JDBC Driver \\d.\\d for SQL Server"; static DBTable table1; @@ -47,7 +44,6 @@ public class BvtTest extends AbstractTest { * @throws SQLException */ @Test - @DisplayName("test connection") public void testConnection() throws SQLException { try (DBConnection conn = new DBConnection(connectionString)) {} } @@ -147,8 +143,8 @@ public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundExce * @throws ClassNotFoundException */ @Test + @Tag(Constants.xAzureSQLDW) public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY); DBResultSet rs = stmt.selectAll(table1)) { @@ -168,8 +164,8 @@ public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFou * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testStmtScrollSensitiveReadOnly() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY); DBResultSet rs = stmt.selectAll(table1)) { @@ -191,8 +187,8 @@ public void testStmtScrollSensitiveReadOnly() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testStmtForwardOnlyUpdateable() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE); DBResultSet rs = stmt.selectAll(table1)) { @@ -219,8 +215,8 @@ public void testStmtForwardOnlyUpdateable() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testStmtScrollSensitiveUpdatable() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE); DBResultSet rs = stmt.selectAll(table1)) { @@ -243,8 +239,8 @@ public void testStmtScrollSensitiveUpdatable() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testStmtSSScrollDynamicOptimisticCC() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString); DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC); DBResultSet rs = stmt.selectAll(table1)) { @@ -286,7 +282,8 @@ public void testCreatepreparedStatement() throws SQLException { String colName = table1.getEscapedColumnName(7); String value = table1.getRowData(7, 0).toString(); - String query = "SELECT * from " + table1.getEscapedTableName() + " where " + colName + " = ? "+ " ORDER BY " + table1.getEscapedColumnName(0); + String query = "SELECT * from " + table1.getEscapedTableName() + " where " + colName + " = ? " + " ORDER BY " + + table1.getEscapedColumnName(0); try (DBConnection conn = new DBConnection(connectionString); DBPreparedStatement pstmt = conn.prepareStatement(query)) { @@ -416,8 +413,8 @@ public void testResultSetAndCloseStmt() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetSelectMethod() throws SQLException { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); try (DBConnection conn = new DBConnection(connectionString + ";selectMethod=cursor;"); DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.selectAll(table1)) { rs.verify(table1); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java index d93fe8cc6..678736e31 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableMixedTest.java @@ -1,14 +1,13 @@ package com.microsoft.sqlserver.jdbc.callablestatement; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -17,9 +16,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class CallableMixedTest extends AbstractTest { @Test @@ -72,10 +73,8 @@ public void datatypestest() throws Exception { } } } finally { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(escapedTableName, stmt); - } catch (SQLException e) { - fail(e.getMessage()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java index 33a87dd74..fd74ec5db 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/callablestatement/CallableStatementTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -32,6 +33,7 @@ * Test CallableStatement */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class CallableStatementTest extends AbstractTest { private static String tableNameGUID = RandomUtil.getIdentifier("uniqueidentifier_Table"); private static String outputProcedureNameGUID = RandomUtil.getIdentifier("uniqueidentifier_SP"); @@ -46,7 +48,7 @@ public class CallableStatementTest extends AbstractTest { @BeforeAll public static void setupTest() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(setNullProcedureName), stmt); @@ -172,7 +174,7 @@ public void inputParamsTest() throws SQLException { */ @AfterAll public static void cleanup() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(outputProcedureNameGUID), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(setNullProcedureName), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java index 5d749ba78..08844bf06 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionDriverTest.java @@ -7,16 +7,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.sql.Connection; -import java.sql.DriverPropertyInfo; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.Statement; import java.text.MessageFormat; -import java.util.Properties; import java.util.UUID; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -37,7 +34,6 @@ import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource; import com.microsoft.sqlserver.jdbc.SQLServerDataSource; -import com.microsoft.sqlserver.jdbc.SQLServerDriver; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; @@ -46,7 +42,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class ConnectionDriverTest extends AbstractTest { // If no retry is done, the function should at least exit in 5 seconds static int threshHoldForNoRetryInMilliseconds = 5000; @@ -118,9 +113,9 @@ public void connectionErrorOccurred(ConnectionEvent event) { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testConnectionEvents() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); PooledConnection pooledConnection = mds.getPooledConnection(); @@ -152,9 +147,9 @@ public void testConnectionEvents() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testConnectionPoolGetTwice() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource(); mds.setURL(connectionString); PooledConnection pooledConnection = mds.getPooledConnection(); @@ -183,9 +178,9 @@ public void testConnectionPoolGetTwice() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testConnectionClosed() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - SQLServerDataSource mds = new SQLServerDataSource(); mds.setURL(connectionString); try (Connection con = mds.getConnection(); @@ -249,7 +244,7 @@ public void testNegativeTimeout() throws Exception { try (Connection conn = getConnection()) { try { conn.isValid(-42); - throw new Exception(TestResource.getResource("R_noExceptionNegativeTimeout")); + fail(TestResource.getResource("R_noExceptionNegativeTimeout")); } catch (SQLException e) { MessageFormat form = new MessageFormat(TestResource.getResource("R_invalidQueryTimeout")); Object[] msgArgs = {"-42"}; @@ -260,9 +255,9 @@ public void testNegativeTimeout() throws Exception { } @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testDeadConnection() throws SQLException { - assumeFalse(isSqlAzure(), TestResource.getResource("R_skipAzure")); - String tableName = RandomUtil.getIdentifier("ConnectionTestTable"); try (Connection conn = PrepUtil.getConnection(connectionString + ";responseBuffering=adaptive"); Statement stmt = conn.createStatement()) { @@ -289,8 +284,7 @@ public void testDeadConnection() throws SQLException { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); } finally { if (null != tableName) { - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil - .getConnection(connectionString + ";responseBuffering=adaptive"); + try (Connection conn = PrepUtil.getConnection(connectionString + ";responseBuffering=adaptive"); Statement stmt = conn.createStatement()) { stmt.execute("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); } @@ -306,7 +300,7 @@ public void testClientConnectionId() throws Exception { try { // Call getClientConnectionId on a closed connection, should raise exception conn.getClientConnectionId(); - throw new Exception(TestResource.getResource("R_noExceptionClosedConnection")); + fail(TestResource.getResource("R_noExceptionClosedConnection")); } catch (SQLException e) { assertEquals(e.getMessage(), TestResource.getResource("R_connectionIsClosed"), TestResource.getResource("R_wrongExceptionMessage")); @@ -314,7 +308,7 @@ public void testClientConnectionId() throws Exception { } // Wrong database, ClientConnectionId should be available in error message - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection(connectionString + ";databaseName=" + try (Connection conn = PrepUtil.getConnection(connectionString + ";databaseName=" + RandomUtil.getIdentifierForDB("DataBase") + Constants.SEMI_COLON)) { conn.close(); @@ -324,7 +318,7 @@ public void testClientConnectionId() throws Exception { } // Nonexist host, ClientConnectionId should not be available in error message - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";instanceName=" + RandomUtil.getIdentifier("Instance") + ";logintimeout=5;")) { conn.close(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java index 9f2e0fd89..07d548ed7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -27,7 +26,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class ConnectionWrapper43Test extends AbstractTest { static Connection connection = null; double javaVersion = Double.parseDouble(System.getProperty("java.specification.version")); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java index c9bffb8a4..6a4d814e3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DBMetadataTest.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -18,10 +19,12 @@ import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.DBTable; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class DBMetadataTest extends AbstractTest { @Test public void testDatabaseMetaData() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java index adc87936d..b315a2778 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/DriverVersionTest.java @@ -10,7 +10,6 @@ import java.util.Arrays; import java.util.Random; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -28,7 +27,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class DriverVersionTest extends AbstractTest { Random rand = new Random(); int major = rand.nextInt(256); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java index 646dbd602..fab794b2f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/NativeMSSQLDataSourceTest.java @@ -35,7 +35,6 @@ public class NativeMSSQLDataSourceTest extends AbstractTest { @Test - @Tag("AzureDWTest") public void testNativeMSSQLDataSource() throws SQLException { SQLServerXADataSource ds = new SQLServerXADataSource(); ds.setLastUpdateCount(true); @@ -43,7 +42,6 @@ public void testNativeMSSQLDataSource() throws SQLException { } @Test - @Tag("AzureDWTest") public void testSerialization() throws IOException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutput objectOutput = new ObjectOutputStream(outputStream)) { @@ -56,7 +54,6 @@ public void testSerialization() throws IOException { } @Test - @Tag("AzureDWTest") public void testDSNormal() throws ClassNotFoundException, IOException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); ds.setURL(connectionString); @@ -66,6 +63,8 @@ public void testDSNormal() throws ClassNotFoundException, IOException, SQLExcept } @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); System.setProperty("java.net.preferIPv6Addresses", Boolean.TRUE.toString()); @@ -79,7 +78,6 @@ public void testDSTSPassword() throws ClassNotFoundException, IOException, SQLEx } @Test - @Tag("AzureDWTest") public void testInterfaceWrapping() throws ClassNotFoundException, SQLException { SQLServerDataSource ds = new SQLServerDataSource(); assertEquals(true, ds.isWrapperFor(Class.forName(Constants.MSSQL_JDBC_PACKAGE + ".ISQLServerDataSource"))); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java index 03eeb5c83..6b8521175 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/PoolingTest.java @@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; @@ -33,6 +32,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -42,14 +42,15 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class PoolingTest extends AbstractTest { static String tempTableName = RandomUtil.getIdentifier("#poolingtest"); static String tableName = RandomUtil.getIdentifier("PoolingTestTable"); @Test + @Tag(Constants.xAzureSQLDB) + @Tag(Constants.xAzureSQLDW) + @Tag("xAzureSQLMI") public void testPooling() throws SQLException { - assumeTrue(!isSqlAzure(), TestResource.getResource("R_skipAzure")); SQLServerXADataSource XADataSource1 = new SQLServerXADataSource(); XADataSource1.setURL(connectionString); @@ -236,7 +237,7 @@ private static void connect(DataSource ds) throws SQLException { */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tempTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java index 46a65d587..a07fb1d89 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java @@ -7,12 +7,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.sql.CallableStatement; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -21,6 +23,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,12 +33,15 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** * A class for testing Request Boundary Methods. */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) public class RequestBoundaryMethodsTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("RequestBoundaryTable"); @@ -133,7 +139,7 @@ public void testModifiableConnectionProperties() throws SQLException { con.setCatalog("master"); } } finally { - try (SQLServerConnection con = getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropDatabaseIfExists(sCatalog2, stmt); } } @@ -146,7 +152,7 @@ public void testModifiableConnectionProperties() throws SQLException { */ @Test public void testWarnings() throws SQLException { - try (SQLServerConnection con = getConnection()) { + try (Connection con = getConnection()) { if (TestUtils.isJDBC43OrGreater(con)) { con.beginRequest(); generateWarning(con); @@ -175,7 +181,7 @@ public void testWarnings() throws SQLException { */ @Test public void testOpenTransactions() throws SQLException { - try (SQLServerConnection con = getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { if (TestUtils.isJDBC43OrGreater(con)) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col int)"); @@ -196,7 +202,7 @@ public void testOpenTransactions() throws SQLException { } } } catch (Exception e) { - e.printStackTrace(); + fail(e.getMessage()); } } @@ -207,7 +213,7 @@ public void testOpenTransactions() throws SQLException { */ @Test public void testStatements() throws SQLException { - try (SQLServerConnection con = getConnection();) { + try (Connection con = getConnection();) { if (TestUtils.isJDBC43OrGreater(con)) { try (Statement stmt1 = con.createStatement()) { con.beginRequest(); @@ -275,7 +281,7 @@ public void testStatements() throws SQLException { @Test public void testThreads() throws SQLException { class Variables { - volatile SQLServerConnection con = null; + volatile Connection con = null; volatile Statement stmt = null; volatile PreparedStatement pstmt = null; } @@ -346,8 +352,8 @@ public void run() { assertTrue(sharedVariables.pstmt.isClosed()); } } catch (InterruptedException e) { - e.printStackTrace(); Thread.currentThread().interrupt(); + fail(e.getMessage()); } finally { if (null != sharedVariables.stmt) { sharedVariables.stmt.close(); @@ -424,7 +430,7 @@ private void compareValuesAgainstConnection(SQLServerConnection con, boolean aut "useBulkCopyForBatchInsert" + description); } - private void generateWarning(SQLServerConnection con) throws SQLException { + private void generateWarning(Connection con) throws SQLException { con.setClientInfo("name", "value"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java index 6962a171f..83e91bc13 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/SSLProtocolTest.java @@ -12,7 +12,6 @@ import java.sql.DatabaseMetaData; import java.text.MessageFormat; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -28,7 +27,6 @@ * Tests new connection property sslProtocol */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class SSLProtocolTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java index 7e8ecc45f..1cb4346c3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -19,7 +19,6 @@ import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -98,18 +97,19 @@ public void testFOInstanceResolution2() throws SQLException { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testQueryTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";queryTimeout=" + (waitForDelaySeconds / 2) + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof java.sql.SQLTimeoutException)) { throw e; @@ -134,14 +134,15 @@ public void testQueryTimeout() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testCancelQueryTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection(connectionString + ";queryTimeout=" - + (waitForDelaySeconds / 2) + ";cancelQueryTimeout=" + waitForDelaySeconds + Constants.SEMI_COLON)) { + try (Connection conn = PrepUtil.getConnection(connectionString + ";queryTimeout=" + (waitForDelaySeconds / 2) + + ";cancelQueryTimeout=" + waitForDelaySeconds + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); @@ -154,7 +155,7 @@ public void testCancelQueryTimeout() throws Exception { TestResource.getResource("R_invalidExceptionMessage")); } - try (SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { stmt.execute("SELECT @@version"); } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); @@ -170,14 +171,14 @@ public void testCancelQueryTimeout() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testCancelQueryTimeoutOnStatement() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil - .getConnection(connectionString + Constants.SEMI_COLON)) { + try (Connection conn = PrepUtil.getConnection(connectionString + Constants.SEMI_COLON)) { try (SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { stmt.setQueryTimeout(waitForDelaySeconds / 2); @@ -208,18 +209,19 @@ public void testCancelQueryTimeoutOnStatement() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSocketTimeout() throws Exception { try (Connection conn = getConnection()) { dropWaitForDelayProcedure(conn); createWaitForDelayPreocedure(conn); } - try (SQLServerConnection conn = (SQLServerConnection) PrepUtil.getConnection( + try (Connection conn = PrepUtil.getConnection( connectionString + ";socketTimeout=" + (waitForDelaySeconds * 1000 / 2) + Constants.SEMI_COLON)) { try (Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { throw e; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java index ae296f71a..913f95899 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/WarningTest.java @@ -15,7 +15,6 @@ import java.util.List; import java.util.Properties; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -25,7 +24,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class WarningTest extends AbstractTest { @Test public void testWarnings() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java index 5012813fa..fbe3f195f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,12 +27,14 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** * Test class for testing DatabaseMetaData with foreign keys. */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class DatabaseMetaDataForeignKeyTest extends AbstractTest { private static String table1 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_table_1"); @@ -88,8 +91,7 @@ public static void setupVariation() throws SQLException { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index f7253fe56..dea51c33b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.BufferedInputStream; import java.io.File; @@ -54,7 +53,6 @@ public class DatabaseMetaDataTest extends AbstractTest { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testDatabaseMetaDataWrapper() throws SQLException { try (Connection con = getConnection()) { DatabaseMetaData databaseMetaData = con.getMetaData(); @@ -77,15 +75,12 @@ public void testDatabaseMetaDataWrapper() throws SQLException { * IOExcption */ @Test - @Tag("AzureDWTest") public void testDriverVersion() throws SQLException, IOException { String manifestFile = TestUtils.getCurrentClassPath() + "META-INF/MANIFEST.MF"; manifestFile = manifestFile.replace("test-classes", "classes"); File f = new File(manifestFile); - assumeTrue(f.exists(), TestResource.getResource("R_manifestNotFound")); - try (InputStream in = new BufferedInputStream(new FileInputStream(f))) { Manifest manifest = new Manifest(in); Attributes attributes = manifest.getMainAttributes(); @@ -118,7 +113,6 @@ public void testDriverVersion() throws SQLException, IOException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetURL() throws SQLException { try (Connection conn = getConnection()) { DatabaseMetaData databaseMetaData = conn.getMetaData(); @@ -136,6 +130,8 @@ public void testGetURL() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testDBUserLogin() throws SQLException { try (Connection conn = getConnection()) { DatabaseMetaData databaseMetaData = conn.getMetaData(); @@ -172,7 +168,6 @@ public void testDBUserLogin() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testDBSchema() throws SQLException { try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getSchemas()) { @@ -193,6 +188,8 @@ public void testDBSchema() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testDBSchemasForDashedCatalogName() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -245,6 +242,8 @@ public void testDBSchemasForDashedCatalogName() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { UUID id = UUID.randomUUID(); String testCatalog = "dash-catalog" + id; @@ -291,7 +290,6 @@ public void testDBSchemasForDashedCatalogNameWithPattern() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") /* * try (ResultSet rsCatalog = connection.getMetaData().getCatalogs(); ResultSet rs = connection.getMetaData() * .getTables(rsCatalog.getString("TABLE_CAT"), null, "%", new String[] {"TABLE"})) { @@ -331,7 +329,6 @@ public void testDBTables() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetDBColumn() throws SQLException { try (Connection conn = getConnection()) { @@ -380,6 +377,7 @@ public void testGetDBColumn() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testGetColumnPrivileges() throws SQLException { try (Connection conn = getConnection()) { @@ -421,7 +419,6 @@ public void testGetColumnPrivileges() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctionsWithWrongParams() throws SQLException { try (Connection conn = getConnection()) { conn.getMetaData().getFunctions("", null, "xp_%"); @@ -435,7 +432,6 @@ public void testGetFunctionsWithWrongParams() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctions() throws SQLException { try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getFunctions(null, null, "xp_%")) { @@ -461,7 +457,6 @@ public void testGetFunctions() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetFunctionColumns() throws SQLException { try (Connection conn = getConnection()) { @@ -499,6 +494,8 @@ public void testGetFunctionColumns() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testPreparedStatementMetadataCaching() throws SQLException { try (Connection connection = getConnection()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java index 413e29ded..30af0adbc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BigIntegerTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -17,12 +18,14 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /* * This test is for testing the setObject methods for the data type mappings in JDBC for java.math.BigInteger */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class BigIntegerTest extends AbstractTest { enum TestType { @@ -39,68 +42,65 @@ enum TestType { */ @Test public void testBigInteger() throws Exception { - try (Connection conn = getConnection()) { - try (Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - // Create the test table - TestUtils.dropTableIfExists(escapedTableName, stmt); + // Create the test table + TestUtils.dropTableIfExists(escapedTableName, stmt); - String query = "create table " + escapedTableName - + " (col1 varchar(100), col2 bigint, col3 real, col4 float, " - + "col5 numeric(38,0), col6 int, col7 smallint, col8 char(100), col9 varchar(max), " - + "id int IDENTITY primary key)"; - stmt.executeUpdate(query); - - try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + escapedTableName - + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) SELECT * FROM " + escapedTableName + " where id = ?")) { - - /* - * test conversion of BigInteger values greater than LONG.MAX_VALUE and lesser than LONG.MIN_VALUE - */ - - // A random value that is bigger than LONG.MAX_VALUE - BigInteger bigIntPos = new BigInteger("922337203685477580776767676"); - // A random value that is smaller than LONG.MIN_VALUE - BigInteger bigIntNeg = new BigInteger("-922337203685477580776767676"); - - // Test the setObject method for different types of BigInteger values - int row = 1; - testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHTYPE); - - testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(-10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHTYPE); - - // Test setObject method with SQL TYPE parameter - testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(1000), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.valueOf(-1000), row++, pstmt, - TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); - - // Test setNull - testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETNULL); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(escapedTableName, stmt); - } + String query = "create table " + escapedTableName + + " (col1 varchar(100), col2 bigint, col3 real, col4 float, " + + "col5 numeric(38,0), col6 int, col7 smallint, col8 char(100), col9 varchar(max), " + + "id int IDENTITY primary key)"; + stmt.executeUpdate(query); + + try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + escapedTableName + + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?) SELECT * FROM " + escapedTableName + " where id = ?")) { + + /* + * test conversion of BigInteger values greater than LONG.MAX_VALUE and lesser than LONG.MIN_VALUE + */ + + // A random value that is bigger than LONG.MAX_VALUE + BigInteger bigIntPos = new BigInteger("922337203685477580776767676"); + // A random value that is smaller than LONG.MIN_VALUE + BigInteger bigIntNeg = new BigInteger("-922337203685477580776767676"); + + // Test the setObject method for different types of BigInteger values + int row = 1; + testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHTYPE); + + testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(-10), row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHTYPE); + + // Test setObject method with SQL TYPE parameter + testSetObject(escapedTableName, BigInteger.valueOf(Long.MAX_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(Long.MIN_VALUE), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(1000), row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.valueOf(-1000), row++, pstmt, + TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, BigInteger.ZERO, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, bigIntPos, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETOBJECT_WITHOUTTYPE); + + // Test setNull + testSetObject(escapedTableName, bigIntNeg, row++, pstmt, TestType.SETNULL); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(escapedTableName, stmt); } } } - static void testSetObject(String tableName, BigInteger obj, int id, PreparedStatement pstmt, + private void testSetObject(String tableName, BigInteger obj, int id, PreparedStatement pstmt, TestType testType) throws SQLException { if (TestType.SETOBJECT_WITHTYPE == testType) { callSetObjectWithType(obj, pstmt); @@ -172,7 +172,7 @@ static void testSetObject(String tableName, BigInteger obj, int id, PreparedStat } } - static void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throws SQLException { pstmt.setObject(1, obj, java.sql.Types.VARCHAR); pstmt.setObject(2, obj, java.sql.Types.BIGINT); pstmt.setObject(3, obj, java.sql.Types.FLOAT); @@ -199,7 +199,7 @@ static void callSetObjectWithType(BigInteger obj, PreparedStatement pstmt) throw pstmt.setObject(9, obj, java.sql.Types.LONGVARCHAR); } - static void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) throws SQLException { /* * Cannot send a long value to a column of type int/smallint (even if the long value is small enough to fit in * those types) @@ -231,7 +231,7 @@ static void callSetObjectWithoutType(BigInteger obj, PreparedStatement pstmt) th pstmt.setObject(9, obj); } - static void callSetNull(BigInteger obj, PreparedStatement pstmt) throws SQLException { + private void callSetNull(BigInteger obj, PreparedStatement pstmt) throws SQLException { pstmt.setNull(1, java.sql.Types.VARCHAR); pstmt.setNull(2, java.sql.Types.BIGINT); pstmt.setNull(3, java.sql.Types.FLOAT); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java index 9a2eda3a1..28ee36df9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/BulkCopyWithSqlVariantTest.java @@ -14,6 +14,7 @@ import java.sql.Statement; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -31,6 +33,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class BulkCopyWithSqlVariantTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("sqlVariantTestSrcTable"); @@ -337,7 +340,6 @@ public void bulkCopyTestDate() throws SQLException { @Test public void bulkCopyTestTwoCols() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - String col1Value = "2015-05-05"; String col2Value = "126.1230"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -777,6 +779,7 @@ public void bulkCopyTestTime() throws SQLException { SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(con); bulkCopy.setDestinationTableName(AbstractSQLGenerator.escapeIdentifier(destTableName)); bulkCopy.writeToServer(rs); + bulkCopy.close(); } try (ResultSet rs = stmt @@ -852,8 +855,7 @@ public void bulkCopyTestVarChar8000() throws SQLException { } private void beforeEachSetup(String colType, Object colValue) throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTableName), stmt); stmt.executeUpdate( @@ -872,7 +874,7 @@ private void beforeEachSetup(String colType, Object colValue) throws SQLExceptio */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(tableName, stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(destTableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java index 323405599..53e8e83f3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DataTypesTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.math.BigDecimal; import java.sql.CallableStatement; @@ -18,15 +17,14 @@ import java.sql.Time; import java.sql.Timestamp; import java.text.DateFormatSymbols; -import java.text.MessageFormat; import java.time.Instant; import java.util.Calendar; import java.util.EnumSet; -import java.util.GregorianCalendar; import java.util.Locale; import java.util.SimpleTimeZone; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -41,6 +39,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; import microsoft.sql.DateTimeOffset; @@ -204,8 +203,6 @@ void verifyRSGetters(Connection conn) throws Exception { } void verifyRSUpdaters(Connection conn) throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); @@ -224,8 +221,6 @@ void verifyRSUpdaters(Connection conn) throws Exception { } void verifySetters(Connection conn) throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); stmt.executeUpdate("CREATE TABLE " + escapedTableName + " (col1 " + sqlTypeExpression @@ -1071,6 +1066,7 @@ public void testResultSetGetters() throws Exception { } @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetUpdaters() throws Exception { try (Connection conn = getConnection()) { for (TestValue value : TestValue.values()) @@ -1079,6 +1075,7 @@ public void testResultSetUpdaters() throws Exception { } @Test + @Tag(Constants.xAzureSQLDW) public void testSetters() throws Exception { try (Connection conn = PrepUtil.getConnection(connectionString + ";sendTimeAsDateTime=true")) { for (TestValue value : TestValue.values()) @@ -1153,12 +1150,10 @@ public void testSendTimestampAsTimeAsDatetime() throws Exception { * double-rounding of fractional seconds */ @Test + @Tag(Constants.xAzureSQLDW) public void testDoubleRounding() throws Exception { try (Connection conn = getConnection()) { - // create a table with a datetimeoffset column and insert a value in it - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - String sql; try (Statement stmt = conn.createStatement()) { // SQL Azure requires each table to have a clustered index, so change col1 to the primary key @@ -1230,9 +1225,6 @@ public void testWithJapaneseImperialCalendar() throws Exception { */ Locale japaneseImperialLocale = new Locale("ja", "JP", "JP"); Calendar japaneseImperialCalendar = Calendar.getInstance(japaneseImperialLocale); - MessageFormat cal = new MessageFormat(TestResource.getResource("R_noJRESupport")); - Object[] msgsArgs = {japaneseImperialLocale.toString()}; - assumeTrue(GregorianCalendar.class.isInstance(japaneseImperialCalendar), cal.format(msgsArgs)); Locale defaultLocale = Locale.getDefault(); Locale.setDefault(japaneseImperialLocale); @@ -1562,12 +1554,11 @@ public void testTimestampToDateTime() throws Exception { } @Test + @Tag(Constants.xAzureSQLDW) public void testUpdateMisc() throws Exception { try (SQLServerConnection conn = (SQLServerConnection) PrepUtil .getConnection(connectionString + ";sendTimeAsDatetime=true")) { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { TestUtils.dropTableIfExists(escapedTableName, stmt); @@ -1678,9 +1669,8 @@ public void testUpdateMisc() throws Exception { * last millisecond digit. */ @Test + @Tag(Constants.xAzureSQLDW) public void testDateTimeInsertUpdate() throws Exception { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_cursorAzureDW")); - try (Connection conn = getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) conn diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java index f341789e1..7071802c0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/DateAndTimeTypeTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.Date; @@ -18,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,11 +30,12 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class DateAndTimeTypeTest extends AbstractTest { private static final Date DATE_TO_TEST = new java.sql.Date(61494793200000L); @@ -194,10 +195,6 @@ private void createTVPs(String tvpName, String tvpType) throws SQLException { @BeforeEach public void testSetup() throws TestAbortedException, Exception { - try (DBConnection dbc = new DBConnection(connectionString)) { - assumeTrue(9 <= dbc.getServerVersion(), "Aborting test case as SQL Server version does not support TIME"); - } - // To get TIME & setTime working on Servers >= 2008, we must add 'sendTimeAsDatetime=false' // by default to the connection. See issue https://github.com/Microsoft/mssql-jdbc/issues/559 try (Connection connection = PrepUtil.getConnection(connectionString + ";sendTimeAsDatetime=false"); @@ -227,8 +224,7 @@ public void testSetup() throws TestAbortedException, Exception { @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString + ";sendTimeAsDatetime=false"); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index bf293d5db..0bb50f067 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,7 +27,6 @@ import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; @@ -34,6 +34,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -187,6 +188,7 @@ public void testFullGlobeWkb() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testPointWkt() throws SQLException { beforeEachSetup(); String geoWKT = "POINT(3 40 5 6)"; @@ -197,6 +199,7 @@ public void testPointWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testLineStringWkt() throws SQLException { beforeEachSetup(); String geoWKT = "LINESTRING(1 0, 0 1, -1 0)"; @@ -207,6 +210,7 @@ public void testLineStringWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testPolygonWkt() throws SQLException { beforeEachSetup(); String geoWKT = "POLYGON((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 1 2, 2 1, 1 1))"; @@ -217,6 +221,7 @@ public void testPolygonWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testMultiPointWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTIPOINT((2 3), (7 8 9.5))"; @@ -227,6 +232,7 @@ public void testMultiPointWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testMultiLineStringWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTILINESTRING((0 2, 1 1), (1 0, 1 1))"; @@ -237,6 +243,7 @@ public void testMultiLineStringWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testMultiPolygonWkt() throws SQLException { beforeEachSetup(); String geoWKT = "MULTIPOLYGON(((1 1, 1 2, 2 1, 1 1), (0 0, 0 3, 3 3, 3 0, 0 0 7)), ((9 9, 9 10, 10 9, 9 9)))"; @@ -247,6 +254,7 @@ public void testMultiPolygonWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testGeometryCollectionWkt() throws SQLException { String geoWKT; if (isDenaliOrLater) { @@ -266,6 +274,7 @@ public void testGeometryCollectionWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testCircularStringWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -278,6 +287,7 @@ public void testCircularStringWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testCompoundCurveWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -290,6 +300,7 @@ public void testCompoundCurveWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testCurvePolygonWkt() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -302,8 +313,9 @@ public void testCurvePolygonWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testFullGlobeWkt() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { if (isDenaliOrLater) { beforeEachSetup(); @@ -332,6 +344,7 @@ public void testFullGlobeWkt() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testIrregularCases() throws SQLException { beforeEachSetup(); @@ -445,6 +458,7 @@ public void testIllegalCases() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testAllTypes() throws SQLException { if (isDenaliOrLater) { beforeEachSetup(); @@ -477,7 +491,7 @@ public void testAllTypes() throws SQLException { Geography geogWKT; // Geometry - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)")) { @@ -596,6 +610,7 @@ public void testAllTypes() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testMixedAllTypes() throws SQLException { if (isDenaliOrLater) { beforeEachSetupSpatialDatatype(); @@ -631,7 +646,7 @@ public void testMixedAllTypes() throws SQLException { Geometry geomWKT; Geography geogWKT; - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) + " values (?, ?, ?, ?, ?)");) { @@ -752,6 +767,7 @@ public void testMixedAllTypes() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testDecimalRounding() throws SQLException { beforeEachSetup(); @@ -762,6 +778,7 @@ public void testDecimalRounding() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testParse() throws SQLException { beforeEachSetup(); @@ -770,7 +787,7 @@ public void testParse() throws SQLException { Geometry geomWKT = Geometry.parse(geoWKT); Geography geogWKT = Geography.parse(geoWKT); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -802,6 +819,7 @@ public void testParse() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testPoint() throws SQLException { beforeEachSetup(); @@ -810,7 +828,7 @@ public void testPoint() throws SQLException { Geometry geomWKT = Geometry.point(1, 2, 0); Geography geogWKT = Geography.point(2, 1, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -841,6 +859,7 @@ public void testPoint() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testSTAsText() throws SQLException { beforeEachSetup(); @@ -850,7 +869,7 @@ public void testSTAsText() throws SQLException { Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0); Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -879,6 +898,7 @@ public void testSTAsText() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testSTAsBinary() throws SQLException { beforeEachSetup(); @@ -901,10 +921,12 @@ public void testSTAsBinary() throws SQLException { assertEquals(geogWKB, geogWKB2); } + @Test + @Tag(Constants.xAzureSQLDW) public void testCheckGeomMetaData() throws SQLException { beforeEachSetup(); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement( "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " (c1) VALUES (?)")) { ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); @@ -925,10 +947,11 @@ public void testCheckGeomMetaData() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testCheckGeogMetaData() throws SQLException { beforeEachSetup(); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement( "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(geogTableName) + " (c1) VALUES (?)")) { ParameterMetaData paramMetaData = pstmt.getParameterMetaData(); @@ -965,6 +988,7 @@ public void testGetXGetY() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testNull() throws SQLException { if (isDenaliOrLater) { beforeEachSetupSpatialDatatype(); @@ -992,7 +1016,7 @@ public void testNull() throws SQLException { Geometry geomWKT; Geography geogWKT; - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) @@ -1034,13 +1058,14 @@ public void testNull() throws SQLException { } @Test + @Tag(Constants.xAzureSQLDW) public void testWrongtype() throws SQLException { beforeEachSetup(); Geometry geomWKT = Geometry.point(1, 2, 0); Geography geogWKT = Geography.point(2, 1, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -1077,7 +1102,7 @@ public void testWrongtype() throws SQLException { } private void beforeEachSetup() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geomTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geogTableName), stmt); stmt.executeUpdate( @@ -1088,7 +1113,7 @@ private void beforeEachSetup() throws SQLException { } private void beforeEachSetupSpatialDatatype() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName), stmt); stmt.executeUpdate("Create table " + AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName) + " (c1 geometry," + "c2 geography," + "c3 nvarchar(512)," + "c4 decimal(28,4)," + "c5 int)"); @@ -1103,7 +1128,7 @@ private void testWkt(String geoWKT, String geoWKTSS) throws SQLException { Geometry geomWKT = Geometry.STGeomFromText(geoWKT, 0); Geography geogWKT = Geography.STGeomFromText(geoWKT, 4326); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) con.prepareStatement( "insert into " + AbstractSQLGenerator.escapeIdentifier(geomTableName) + " values (?)");) { @@ -1154,21 +1179,15 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti geogTableName = RandomUtil.getIdentifier("geographyTestTable"); spatialDatatypeTableName = RandomUtil.getIdentifier("spatialDatatypeTestTable"); - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("select SERVERPROPERTY ( 'ProductVersion' )")) { - rs.next(); + int version = Integer.parseInt(rs.getString(1).substring(0, 2)); - try { - int version = Integer.parseInt(rs.getString(1).substring(0, 2)); - - // if major version is greater than or equal to 11, it's SQL Server 2012 or above. - if (version >= 11) { - isDenaliOrLater = true; - } - } catch (Exception e) { - // Do nothing. + // if major version is greater than or equal to 11, it's SQL Server 2012 or above. + if (version >= 11) { + isDenaliOrLater = true; } } } @@ -1180,7 +1199,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterAll public static void afterAll() throws SQLException { - try (Connection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geomTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(geogTableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(spatialDatatypeTableName), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java index d1615fb7e..3186a03e0 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLVariantResultSetTest.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.sql.CallableStatement; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -18,13 +19,13 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomData; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; @@ -32,6 +33,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -52,8 +54,9 @@ public class SQLVariantResultSetTest extends AbstractTest { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readInt() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 2; createAndPopulateTable("int", value); @@ -72,8 +75,9 @@ public void readInt() throws SQLException, SecurityException, IOException { * */ @Test + @Tag(Constants.xAzureSQLDW) public void readMoney() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; createAndPopulateTable("Money", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -90,8 +94,9 @@ public void readMoney() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readSmallMoney() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Double value = 123.12; createAndPopulateTable("smallmoney", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -108,8 +113,9 @@ public void readSmallMoney() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readGUID() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "1AE740A2-2272-4B0F-8086-3DDAC595BC11"; createAndPopulateTable("uniqueidentifier", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -126,8 +132,9 @@ public void readGUID() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readDate() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08'"; createAndPopulateTable("date", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -144,8 +151,9 @@ public void readDate() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'12:26:27.123345'"; createAndPopulateTable("time(3)", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -162,8 +170,9 @@ public void readTime() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readDateTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; createAndPopulateTable("datetime", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -180,8 +189,9 @@ public void readDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readSmallDateTime() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "'2015-05-08 12:26:24'"; createAndPopulateTable("smalldatetime", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -198,6 +208,7 @@ public void readSmallDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readVarChar8000() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 8000; i++) { @@ -205,7 +216,7 @@ public void readVarChar8000() throws SQLException { } String value = "'" + buffer.toString() + "'"; createAndPopulateTable("VARCHAR(8000)", value); - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName))) { rs.next(); @@ -219,8 +230,9 @@ public void readVarChar8000() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readFloat() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { float value = 5; createAndPopulateTable("float", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -237,8 +249,9 @@ public void readFloat() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readBigInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { long value = 5; createAndPopulateTable("bigint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -255,8 +268,9 @@ public void readBigInt() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readSmallInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value = 5; createAndPopulateTable("smallint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -273,8 +287,9 @@ public void readSmallInt() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readTinyInt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value = 5; createAndPopulateTable("tinyint", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -291,8 +306,9 @@ public void readTinyInt() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readBit() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 50000; createAndPopulateTable("bit", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -309,8 +325,9 @@ public void readBit() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readReal() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { float value = 5; createAndPopulateTable("Real", value); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -327,8 +344,9 @@ public void readReal() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readNChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "a"; createAndPopulateTable("nchar(5)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -347,8 +365,9 @@ public void readNChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readNVarChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "nvarchar"; createAndPopulateTable("nvarchar(10)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -367,8 +386,9 @@ public void readNVarChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(20)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -387,8 +407,9 @@ public void readBinary20() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readVarBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("varbinary(20)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -407,8 +428,9 @@ public void readVarBinary20() throws SQLException, SecurityException, IOExceptio * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readBinary512() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(512)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -427,8 +449,9 @@ public void readBinary512() throws SQLException, SecurityException, IOException * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readBinary8000() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -447,8 +470,9 @@ public void readBinary8000() throws SQLException, SecurityException, IOException * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readvarBinary8000() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("varbinary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -467,8 +491,9 @@ public void readvarBinary8000() throws SQLException, SecurityException, IOExcept * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void readSQLVariantProperty() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "hi"; createAndPopulateTable("binary(8000)", "'" + value + "'"); try (SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery( @@ -487,12 +512,13 @@ public void readSQLVariantProperty() throws SQLException, SecurityException, IOE * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void insertVarChar8001() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 8001; i++) { buffer.append("a"); } - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -514,6 +540,7 @@ public void insertVarChar8001() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readNvarChar4000() throws SQLException { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < 4000; i++) { @@ -521,7 +548,7 @@ public void readNvarChar4000() throws SQLException { } String value = "'" + buffer.toString() + "'"; createAndPopulateTable("NVARCHAR(4000)", value); - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { try (SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName))) { rs.next(); @@ -538,8 +565,9 @@ public void readNvarChar4000() throws SQLException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void UpdateInt() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { int value = 2; int updatedValue = 3; @@ -567,8 +595,9 @@ public void UpdateInt() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void UpdateNChar() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { String value = "a"; String updatedValue = "b"; @@ -598,8 +627,9 @@ public void UpdateNChar() throws SQLException, SecurityException, IOException { * @throws IOException */ @Test + @Tag(Constants.xAzureSQLDW) public void updateBinary20() throws SQLException, SecurityException, IOException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { String value = "hi"; String updatedValue = "bye"; @@ -626,8 +656,9 @@ public void updateBinary20() throws SQLException, SecurityException, IOException * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void insertTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant, col2 int)"); @@ -662,8 +693,9 @@ public void insertTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void insertTestNull() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -688,8 +720,9 @@ public void insertTestNull() throws SQLException { * @throws ParseException */ @Test + @Tag(Constants.xAzureSQLDW) public void insertSetObject() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -714,8 +747,9 @@ public void insertSetObject() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementOutputIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int value = 5; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( @@ -744,8 +778,9 @@ public void callableStatementOutputIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementOutputDateTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "2015-05-08"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -775,8 +810,9 @@ public void callableStatementOutputDateTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementOutputTimeTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String value = "12:26:27.123345"; String returnValue = "12:26:27"; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -806,8 +842,9 @@ public void callableStatementOutputTimeTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementOutputBinaryTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { byte[] binary20 = RandomData.generateBinaryTypes("20", false, false); byte[] secondBinary20 = RandomData.generateBinaryTypes("20", false, false); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -842,8 +879,9 @@ public void callableStatementOutputBinaryTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementInputOutputIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; int col2Value = 2; TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); @@ -873,8 +911,9 @@ public void callableStatementInputOutputIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementInputOutputReturnIntTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { int col1Value = 5; int col2Value = 2; int returnValue = 12; @@ -907,8 +946,9 @@ public void callableStatementInputOutputReturnIntTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void callableStatementInputOutputReturnStringTest() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String col1Value = "aa"; String col2Value = "bb"; int returnValue = 12; @@ -943,8 +983,9 @@ public void callableStatementInputOutputReturnStringTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void readSeveralRows() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { short value1 = 5; int value2 = 10; String value3 = "hi"; @@ -972,7 +1013,7 @@ public void readSeveralRows() throws SQLException { */ @Test public void readVarcharInteger() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { Object expected[] = {"abc", 42}; int index = 0; try (SQLServerResultSet rs = (SQLServerResultSet) stmt @@ -991,7 +1032,7 @@ public void readVarcharInteger() throws SQLException { */ @Test public void testUnsupportedDatatype() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt.executeQuery( "select cast(cast('2017-08-16 17:31:09.995 +07:00' as datetimeoffset) as sql_variant)")) { rs.next(); @@ -1012,7 +1053,7 @@ public void testUnsupportedDatatype() throws SQLException { */ @Test public void testTimeClassAsSqlVariant() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement(); + try (Connection con = getConnection(); Statement stmt = con.createStatement(); SQLServerResultSet rs = (SQLServerResultSet) stmt .executeQuery("select cast(cast('17:31:09.995' as time(3)) as sql_variant)")) { rs.next(); @@ -1038,7 +1079,7 @@ private boolean parseByte(byte[] expectedData, byte[] retrieved) { * @throws SQLException */ private void createAndPopulateTable(String columnType, Object value) throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate( "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 sql_variant)"); @@ -1067,7 +1108,7 @@ public static void setupHere() throws SQLException, SecurityException, IOExcepti */ @AfterAll public static void afterAll() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(inputProc), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java index 69465311b..8d5007c88 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SparseTest.java @@ -1,21 +1,21 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) @@ -24,36 +24,34 @@ public class SparseTest extends AbstractTest { final static String escapedTableName = AbstractSQLGenerator.escapeIdentifier(tableName); @Test + @Tag(Constants.xAzureSQLDW) public void testSparse() throws Exception { - try (Connection conn = getConnection()) { - assumeTrue(!isSqlAzureDW(), TestResource.getResource("R_skipAzure")); - try (Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - // Create the test table - TestUtils.dropTableIfExists(escapedTableName, stmt); + // Create the test table + TestUtils.dropTableIfExists(escapedTableName, stmt); + + StringBuilder bd = new StringBuilder(); + bd.append("create table " + escapedTableName + " (col1 int, col2 varbinary(max)"); + for (int i = 3; i <= 1024; i++) { + bd.append(", col" + i + " varchar(20) SPARSE NULL"); + } + bd.append(")"); + String query = bd.toString(); + + stmt.executeUpdate(query); - StringBuilder bd = new StringBuilder(); - bd.append("create table " + escapedTableName + " (col1 int, col2 varbinary(max)"); - for (int i = 3; i <= 1024; i++) { - bd.append(", col" + i + " varchar(20) SPARSE NULL"); - } - bd.append(")"); - String query = bd.toString(); - - stmt.executeUpdate(query); - - stmt.executeUpdate("insert into " + escapedTableName + " (col1, col2, col1023)values(1, 0x45, 'yo')"); - - try (ResultSet rs = stmt.executeQuery("Select * from " + escapedTableName)) { - rs.next(); - assertEquals("yo", rs.getString("col1023")); - assertEquals(1, rs.getInt("col1")); - assertEquals(0x45, rs.getBytes("col2")[0]); - } - } finally { - try (Statement stmt = conn.createStatement()) { - TestUtils.dropTableIfExists(escapedTableName, stmt); - } + stmt.executeUpdate("insert into " + escapedTableName + " (col1, col2, col1023)values(1, 0x45, 'yo')"); + + try (ResultSet rs = stmt.executeQuery("Select * from " + escapedTableName)) { + rs.next(); + assertEquals("yo", rs.getString("col1023")); + assertEquals(1, rs.getInt("col1")); + assertEquals(0x45, rs.getBytes("col2")[0]); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(escapedTableName, stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java index 3f9676dc1..24200d5eb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/TVPWithSqlVariantTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,11 +32,13 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; import com.microsoft.sqlserver.testframework.sqlType.SqlDate; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPWithSqlVariantTest extends AbstractTest { private static SQLServerConnection conn = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java index e3eec336f..eaa534d59 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ErrorStateTest.java @@ -42,7 +42,10 @@ public void testSQLStateLength2() throws Exception { stmt.execute("RAISERROR (13002, -1, " + state + ", N'Testing error');"); } catch (SQLException e) { assert (e.getSQLState().length() == 5); - assert (e.getSQLState().equalsIgnoreCase("S00" + state)); + if (isSqlAzureDW()) { + assert (e.getSQLState().equalsIgnoreCase("S0001")); + } else + assert (e.getSQLState().equalsIgnoreCase("S00" + state)); } } @@ -53,7 +56,10 @@ public void testSQLStateLength3() throws Exception { stmt.execute("RAISERROR (13003, -1, " + state + ", N'Testing error');"); } catch (SQLException e) { assert (e.getSQLState().length() == 5); - assert (e.getSQLState().equalsIgnoreCase("S0" + state)); + if (isSqlAzureDW()) { + assert (e.getSQLState().equalsIgnoreCase("S0001")); + } else + assert (e.getSQLState().equalsIgnoreCase("S0" + state)); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java index e9079509f..a7c02f451 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/exception/ExceptionTest.java @@ -4,23 +4,26 @@ */ package com.microsoft.sqlserver.jdbc.exception; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.UnsupportedEncodingException; import java.net.SocketTimeoutException; import java.sql.Connection; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.MessageFormat; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; @@ -45,9 +48,10 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { try { new SQLServerBulkCSVFileRecord(filePath + inputFile, "invalid_encoding", true); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { - throw e; + fail(e.getMessage()); } assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); @@ -67,9 +71,9 @@ public void testBulkCSVFileRecordExceptionCause() throws Exception { * */ @Test + @Tag(Constants.xAzureSQLDW) public void testSocketTimeoutExceptionCause() throws Exception { - try (SQLServerConnection conn = (SQLServerConnection) getConnection(); - Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName), stmt); createWaitForDelayPreocedure(conn); } @@ -78,10 +82,10 @@ public void testSocketTimeoutExceptionCause() throws Exception { connectionString + ";socketTimeout=" + (waitForDelaySeconds * 1000 / 2) + Constants.SEMI_COLON); Statement stmt = conn.createStatement()) { stmt.execute("exec " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName)); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { if (!(e instanceof SQLException)) { - throw e; + fail(e.getMessage()); } assertTrue(null != e.getCause(), TestResource.getResource("R_causeShouldNotBeNull")); @@ -91,16 +95,60 @@ public void testSocketTimeoutExceptionCause() throws Exception { } } - private void createWaitForDelayPreocedure(SQLServerConnection conn) throws SQLException { + @Test + public void testResultSetErrorSearch() throws Exception { + String tableName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("ISSUE659TABLE")); + String procName = AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("ISSUE659PROC")); + String expectedException = "Error occured during the insert"; + int outputValue = 5; + String createTableSql = "CREATE TABLE " + tableName + "(FIELD1 VARCHAR (255) NOT NULL);"; + String createProcSql = "CREATE PROCEDURE " + procName + + " AS BEGIN TRANSACTION\n BEGIN TRY SET NOCOUNT ON; INSERT INTO " + tableName + " (FIELD1) OUTPUT " + + outputValue + " VALUES ('test'); INSERT INTO" + tableName + + " (FIELD1) VALUES (NULL); COMMIT TRANSACTION; END TRY BEGIN CATCH DECLARE @errorMessage NVARCHAR(4000) = ERROR_MESSAGE(); ROLLBACK TRANSACTION; RAISERROR('" + + expectedException + ": %s', 16, 1, @errorMessage); END CATCH;"; + String execProcSql = "EXECUTE " + procName; + + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + stmt.execute(createTableSql); + stmt.execute(createProcSql); + stmt.execute(execProcSql); + try (ResultSet rs = stmt.getResultSet()) { + // First result set + while (rs.next()) { + assertEquals(outputValue, rs.getInt(1)); + } + } catch (SQLException e) { + // First result set should not throw an exception. + fail(TestResource.getResource("R_unexpectedException")); + } + try { + // Second result set, contains the exception. + assertTrue(stmt.getMoreResults()); + fail(TestResource.getResource("R_expectedFailPassed")); + } catch (SQLException e) { + assertTrue(e.getMessage().contains(expectedException), + TestResource.getResource("R_expectedExceptionNotThrown") + e.getMessage()); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(tableName, stmt); + TestUtils.dropProcedureIfExists(procName, stmt); + } + } + } + + private void createWaitForDelayPreocedure(Connection conn) throws SQLException { String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName) + " AS" + " BEGIN" + " WAITFOR DELAY '00:00:" + waitForDelaySeconds + "';" + " END"; - conn.createStatement().execute(sql); + try (Statement stmt = conn.createStatement()) { + stmt.execute(sql); + } } @AfterAll public static void cleanup() throws SQLException { - try (SQLServerConnection conn = (SQLServerConnection) getConnection(); - Statement stmt = conn.createStatement()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(waitForDelaySPName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java deleted file mode 100644 index 50b2d212d..000000000 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsEnvTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ -package com.microsoft.sqlserver.jdbc.fips; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import java.security.Provider; -import java.security.Security; -import java.util.Enumeration; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import com.microsoft.sqlserver.jdbc.TestResource; -import com.microsoft.sqlserver.jdbc.TestUtils; -import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.Constants; - - -/** - * Class which will useful for checking if FIPS env. set or not. - * - * @since 6.1.2 - */ -@RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") -public class FipsEnvTest extends AbstractTest { - - protected static Logger logger = Logger.getLogger("FipsEnvTest"); - - protected static Properties p = null; - - protected static final String ORACLE_JVM = "ORACLE_JVM"; - - protected static final String IBM_JVM = "IBM_JVM"; - - protected static final String SAP_JVM = "SAP_JVM"; - - protected static String currentJVM = ORACLE_JVM; - - /** - * Before class init method. - */ - @BeforeAll - public static void populateProperties() { - p = System.getProperties(); - - if (p.getProperty("java.vendor").startsWith("IBM")) { - currentJVM = IBM_JVM; - } - - if (p.getProperty("java.vendor").startsWith("SAP")) { - currentJVM = SAP_JVM; - } - } - - /** - * Test FIPS in Oracle Env. - * - * @since 6.1.2 - */ - @Test - public void testFIPSOnOracle() throws Exception { - assumeTrue(ORACLE_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + ORACLE_JVM); - - assumeTrue("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), - TestResource.getResource("R_fipsPropertyNotSet")); - - assertTrue(isFIPS("SunJSSE"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat("NSSFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("SunJSSE"), TestResource.getResource("R_shouldBeEnabled")), () -> - * assertTrue(isFIPS("SunPKCS11-NSS"), "Testing"))); - * assumingThat("BCFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("SunJSSE"), TestResource.getResource("R_shouldBeEnabled")), () -> - * assertTrue(isFIPS("BCFIPS"), "Testing"))); - * assumingThat("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), ()-> assertTrue(isFIPS("SunJSSE"), - * TestResource.getResource("R_shouldBeEnabled"))); - */ - } - - /** - * Test FIPS in IBM Env. If JVM is not IBM test will not fail. It will simply skipped. - * - * @since 6.1.2 - */ - @Test - public void testFIPSOnIBM() throws Exception { - assumeTrue(IBM_JVM.equals(currentJVM), TestResource.getResource("R_wrongEnv") + IBM_JVM); - - assumeTrue("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), - TestResource.getResource("R_fipsPropertyNotSet")); - - assertTrue(isFIPS("IBMJCEFIP"), "FIPS " + TestResource.getResource("R_shouldBeEnabled")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat("NSSFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> assertAll("All FIPS", () -> - * assertTrue(isFIPS("IBMJCEFIP"), "FIPS should be Enabled."), () -> assertTrue(isFIPS("SunPKCS11-NSS"), - * "Testing"))); assumingThat("BCFIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), () -> - * assertAll("All FIPS", () -> assertTrue(isFIPS("IBMJCEFIPS"), "FIPS should be Enabled."), () -> - * assertTrue(isFIPS("BCFIPS"), "Testing"))); - * assumingThat("FIPS".equals(TestUtils.getConfiguredProperty("FIPS_ENV")), ()-> - * assertTrue(isFIPS("IBMJCEFIPS"), "FIPS Should be enabled")); - */ - } - - /** - * In case of FIPs enabled this test method will call {@link #isFIPS(String)} with appropriate FIPS provider. May be - * useful only for JDK 1.8 - */ - @Test - @Disabled - public void testFIPSEnv() { - assumeTrue(Constants.FIPS.equals(TestUtils.getConfiguredProperty(Constants.FIPS_ENV)), - TestResource.getResource("R_fipsPropertyNotSet")); - - // As JDK 1.7 is not supporting lambda for time being commenting. - /* - * assumingThat(System.getProperty("java.vendor").startsWith("IBM"), () -> assertTrue(isFIPS("IBMJCEFIP"), - * "FIPS should be Enabled.")); assumingThat(System.getProperty("java.vendor").startsWith("Oracle"), () -> - * assertTrue(isFIPS("SunJSSE"), "FIPS should be Enabled.")); - */ - } - - /** - * Just simple method to check if JVM is configured for FIPS or not. CAUTION: We observed that - * SSLContext.getDefault().getProvider fails because it could not find any algorithm. - * - * @param provider - * FIPS Provider - * @return boolean - * @throws Exception - */ - public static boolean isFIPS(String provider) throws Exception { - Provider jsse = Security.getProvider(provider); - if (logger.isLoggable(Level.FINE)) { - logger.fine(jsse.toString()); - logger.fine(jsse.getInfo()); - } - return jsse != null && jsse.getInfo().contains("FIPS"); - } - - @Test - @Disabled - public void printJVMInfo() { - Enumeration keys = p.keys(); - - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - String value = (String) p.get(key); - - if (logger.isLoggable(Level.FINE)) { - logger.fine(key + ": " + value); - } - } - } - -} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java index 2f4d49d3e..8fe0c3906 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/fips/FipsTest.java @@ -11,7 +11,6 @@ import java.util.Properties; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -28,7 +27,6 @@ * Test class for testing FIPS property settings. */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class FipsTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java index c283b9d53..4670f4242 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/osgi/DataFactoryTest.java @@ -56,7 +56,8 @@ public ServiceReference getServiceReference(String clazz) { } @Override - public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) { + public ServiceRegistration registerService(String[] classes, Object service, + @SuppressWarnings("rawtypes") Dictionary properties) { MockServiceRegistration reg = new MockServiceRegistration(properties); sr = reg.getReference(); if (service instanceof DataSourceFactory) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java index 0db893ac4..39164dade 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataTest.java @@ -13,6 +13,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -21,6 +22,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) @@ -33,15 +35,15 @@ public class ParameterMetaDataTest extends AbstractTest { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testParameterMetaDataWrapper() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - + try (Statement stmt = connection.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int identity(1,1) primary key)"); try { String query = "SELECT * from " + AbstractSQLGenerator.escapeIdentifier(tableName) + " where col1 = ?"; - try (PreparedStatement pstmt = con.prepareStatement(query)) { + try (PreparedStatement pstmt = connection.prepareStatement(query)) { ParameterMetaData parameterMetaData = pstmt.getParameterMetaData(); assertTrue(parameterMetaData.isWrapperFor(ParameterMetaData.class)); assertSame(parameterMetaData, parameterMetaData.unwrap(ParameterMetaData.class)); @@ -59,9 +61,7 @@ public void testParameterMetaDataWrapper() throws SQLException { */ @Test public void testSQLServerExceptionNotWrapped() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt = connection.prepareStatement("invalid query :)");) { - + try (PreparedStatement pstmt = connection.prepareStatement("invalid query :)");) { pstmt.getParameterMetaData(); } catch (SQLException e) { assertTrue(!e.getMessage().contains("com.microsoft.sqlserver.jdbc.SQLException"), @@ -75,8 +75,9 @@ public void testSQLServerExceptionNotWrapped() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testNameWithBraces() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ([c1_varchar(max)] varchar(max))"); @@ -84,7 +85,7 @@ public void testNameWithBraces() throws SQLException { String query = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ([c1_varchar(max)]) values (?)"; - try (PreparedStatement pstmt = con.prepareStatement(query)) { + try (PreparedStatement pstmt = connection.prepareStatement(query)) { pstmt.getParameterMetaData(); } } finally { @@ -99,6 +100,7 @@ public void testNameWithBraces() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testParameterMetaData() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -135,6 +137,7 @@ public void testParameterMetaData() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testParameterMetaDataProc() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String query = "exec sp_help (" + AbstractSQLGenerator.escapeIdentifier(tableName) + ")"; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java index bfe9b1f62..ef15b9710 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/parametermetadata/ParameterMetaDataWhiteSpaceTest.java @@ -14,18 +14,20 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class ParameterMetaDataWhiteSpaceTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("ParameterMetaDataWhiteSpaceTest"); @@ -36,15 +38,13 @@ public static void BeforeTests() throws SQLException { @AfterAll public static void dropTables() throws SQLException { - try (SQLServerConnection connection = (SQLServerConnection) getConnection(); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } private static void createCharTable() throws SQLException { - try (SQLServerConnection connection = (SQLServerConnection) getConnection(); - Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (c1 int)"); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java index da0f92d69..17889fa9a 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithBulkCopyTest.java @@ -2,8 +2,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.Geography; import com.microsoft.sqlserver.jdbc.Geometry; @@ -49,7 +48,6 @@ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class BatchExecutionWithBulkCopyTest extends AbstractTest { static String tableName = RandomUtil.getIdentifier("BulkCopyParseTest"); @@ -571,7 +569,7 @@ public void testIllegalNumberOfArgNoColumnList() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { assertEquals(TestResource.getResource("R_incorrectColumnNum"), e.getMessage()); } @@ -593,7 +591,7 @@ public void testIllegalNumberOfArgNoColumnList() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { if (isSqlAzureDW()) { assertEquals(TestResource.getResource("R_incorrectColumnNumInsertDW"), e.getMessage()); @@ -623,7 +621,7 @@ public void testNonParameterizedQuery() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { if (isSqlAzureDW()) { assertTrue(e.getMessage().contains(TestResource.getResource("R_incorrectSyntaxTableDW"))); @@ -647,15 +645,15 @@ public void testNonParameterizedQuery() throws Exception { pstmt.addBatch(); pstmt.executeBatch(); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (BatchUpdateException e) { assertEquals(TestResource.getResource("R_incorrectColumnNum"), e.getMessage()); } } @Test + @Tag(Constants.xAzureSQLDW) public void testNonSupportedColumns() throws Exception { - assumeFalse(isSqlAzureDW(), TestResource.getResource("R_spatialDWNotSupported")); String valid = "insert into " + AbstractSQLGenerator.escapeIdentifier(unsupportedTableName) + " values (?, ?, ?, ?)"; @@ -696,33 +694,29 @@ public void testNonSupportedColumns() throws Exception { } @BeforeEach - public void testSetup() throws TestAbortedException, Exception { - try (Connection connection = PrepUtil.getConnection(connectionString + ";useBulkCopyForBatchInsert=true;")) { - try (Statement stmt = (SQLServerStatement) connection.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " " + "(" - + "c1 bigint, " + "c2 binary(5), " + "c3 bit, " + "c4 char, " + "c5 date, " + "c6 datetime, " - + "c7 datetime2, " + "c8 datetimeoffset, " + "c9 decimal, " + "c10 float, " + "c11 int, " - + "c12 money, " + "c13 nchar, " + "c14 numeric, " + "c15 nvarchar(20), " + "c16 real, " - + "c17 smalldatetime, " + "c18 smallint, " + "c19 smallmoney, " + "c20 time, " + "c21 tinyint, " - + "c22 varbinary(5), " + "c23 varchar(20) " + ")"; - - stmt.execute(sql1); - } + public void testSetup() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " " + "(" + "c1 bigint, " + + "c2 binary(5), " + "c3 bit, " + "c4 char, " + "c5 date, " + "c6 datetime, " + "c7 datetime2, " + + "c8 datetimeoffset, " + "c9 decimal, " + "c10 float, " + "c11 int, " + "c12 money, " + + "c13 nchar, " + "c14 numeric, " + "c15 nvarchar(20), " + "c16 real, " + "c17 smalldatetime, " + + "c18 smallint, " + "c19 smallmoney, " + "c20 time, " + "c21 tinyint, " + "c22 varbinary(5), " + + "c23 varchar(20) " + ")"; + + stmt.execute(sql1); } } @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString)) { - try (Statement stmt = (SQLServerStatement) connection.createStatement()) { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameBulk), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(unsupportedTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(squareBracketTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(doubleQuoteTableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(schemaTableName), stmt); - } + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableNameBulk), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(unsupportedTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(squareBracketTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(doubleQuoteTableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(schemaTableName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java index 005311584..b66434b8b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/BatchExecutionWithNullTest.java @@ -5,12 +5,12 @@ package com.microsoft.sqlserver.jdbc.preparedStatement; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.sql.Types; import org.junit.jupiter.api.AfterAll; @@ -22,17 +22,16 @@ import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") +@Tag(Constants.xAzureSQLDW) public class BatchExecutionWithNullTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("batchNull"); @@ -44,8 +43,7 @@ public class BatchExecutionWithNullTest extends AbstractTest { * * @throws SQLException */ - @Test - public void testAddBatch2() throws SQLException { + public void testAddBatch2(Connection conn) throws SQLException { // try { String sPrepStmt = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (id, name) values (?, ?)"; @@ -53,7 +51,7 @@ public void testAddBatch2() throws SQLException { int key = 42; // this is the minimum sequence, I've found to trigger the error\ - try (Connection conn = getConnection(); PreparedStatement pstmt = conn.prepareStatement(sPrepStmt)) { + try (PreparedStatement pstmt = conn.prepareStatement(sPrepStmt)) { pstmt.setInt(1, key++); pstmt.setNull(2, Types.VARCHAR); pstmt.addBatch(); @@ -82,47 +80,52 @@ public void testAddBatch2() throws SQLException { assertTrue(updateCountlen == 5, TestResource.getResource("R_addBatchFailed")); } - String sPrepStmt1 = "select count(*) from " + AbstractSQLGenerator.escapeIdentifier(tableName); - try (PreparedStatement pstmt1 = connection.prepareStatement(sPrepStmt1); ResultSet rs = pstmt1.executeQuery()) { + String sPrepStmt1 = "select count(*) from " + AbstractSQLGenerator.escapeIdentifier(tableName); + try (PreparedStatement pstmt1 = conn.prepareStatement(sPrepStmt1); ResultSet rs = pstmt1.executeQuery()) { rs.next(); assertTrue(rs.getInt(1) == 5, TestResource.getResource("R_insertBatchFailed")); - pstmt1.close(); } } /** - * Tests the same as addBatch2, only with AE on the connection string + * Tests with AE enabled on the connection * * @throws SQLException */ @Test + @Tag(Constants.xSQLv12) public void testAddbatch2AEOnConnection() throws SQLException { try (Connection connection = PrepUtil.getConnection(connectionString + ";columnEncryptionSetting=Enabled;")) { - testAddBatch2(); + testAddBatch2(connection); } } + /** + * Tests the same as testAddbatch2AEOnConnection, with AE disabled + * + * @throws SQLException + */ + @Test + public void testAddbatch2() throws SQLException { + testAddBatch2(getConnection()); + } + @BeforeEach + @Tag(Constants.xSQLv12) public void testSetup() throws TestAbortedException, Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); String sql1 = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (id integer not null, name varchar(255), constraint " + AbstractSQLGenerator.escapeIdentifier(primaryKeyConstraintName) + " primary key (id))"; stmt.execute(sql1); - stmt.close(); } } @AfterAll public static void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); SQLServerStatement stmt = (SQLServerStatement) conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java index 8a0dee24c..208681e16 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/RegressionTest.java @@ -51,7 +51,7 @@ public class RegressionTest extends AbstractTest { */ @BeforeAll public static void setupTest() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } @@ -62,12 +62,10 @@ public static void setupTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createViewTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create view " + AbstractSQLGenerator.escapeIdentifier(tableName) + " as select 1 a"); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create view " + AbstractSQLGenerator.escapeIdentifier(tableName) + " as select 1 a"); + PreparedStatement pstmt2 = connection .prepareStatement("drop view " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -83,12 +81,10 @@ public void createViewTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createSchemaTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con - .prepareStatement("create schema " + AbstractSQLGenerator.escapeIdentifier(schemaName)); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create schema " + AbstractSQLGenerator.escapeIdentifier(schemaName)); + PreparedStatement pstmt2 = connection .prepareStatement("drop schema " + AbstractSQLGenerator.escapeIdentifier(schemaName))) { pstmt1.execute(); pstmt2.execute(); @@ -104,12 +100,10 @@ public void createSchemaTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void createTableTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -125,14 +119,12 @@ public void createTableTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void alterTableTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con.prepareStatement( + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection.prepareStatement( "ALTER TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ADD column_name char;"); - PreparedStatement pstmt3 = con + PreparedStatement pstmt3 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -149,16 +141,14 @@ public void alterTableTest() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void grantTest() throws SQLException { - try (Connection con = getConnection(); - PreparedStatement pstmt1 = con.prepareStatement( - "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); - PreparedStatement pstmt2 = con.prepareStatement( + try (PreparedStatement pstmt1 = connection + .prepareStatement("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + PreparedStatement pstmt2 = connection.prepareStatement( "grant select on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " to public"); - PreparedStatement pstmt3 = con.prepareStatement( + PreparedStatement pstmt3 = connection.prepareStatement( "revoke select on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " from public"); - PreparedStatement pstmt4 = con + PreparedStatement pstmt4 = connection .prepareStatement("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName))) { pstmt1.execute(); pstmt2.execute(); @@ -176,11 +166,13 @@ public void grantTest() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void batchWithLargeStringTest() throws Exception { batchWithLargeStringTestInternal("BatchInsert"); } @Test + @Tag(Constants.xAzureSQLDW) public void batchWithLargeStringTestUseBulkCopyAPI() throws Exception { batchWithLargeStringTestInternal("BulkCopy"); } @@ -286,6 +278,7 @@ private void batchWithLargeStringTestInternal(String mode) throws Exception { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void addBatchWithLargeStringTest() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName2), stmt); @@ -374,8 +367,7 @@ public void addBatchWithLargeStringTest() throws SQLException { @Test public void testQueryParamsWithHyphen() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("SELECT 1 WHERE -1=-1 AND 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("SELECT 1 WHERE -1=-1 AND 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -386,8 +378,7 @@ public void testQueryParamsWithHyphen() throws Exception { @Test public void testQueryParamsWithComment() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("/**COMMENT**/ SELECT 1 WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("/**COMMENT**/ SELECT 1 WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -398,8 +389,7 @@ public void testQueryParamsWithComment() throws Exception { @Test public void testQueryParamsWithLineComment() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("--comment\nSELECT 1 WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("--comment\nSELECT 1 WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) @@ -410,8 +400,7 @@ public void testQueryParamsWithLineComment() throws Exception { @Test public void testQueryParamsWithBackSlash() throws Exception { - try (Connection con = getConnection(); - PreparedStatement st1 = con.prepareStatement("SELECT 1, '/''' AS str WHERE 1=?")) { + try (PreparedStatement st1 = connection.prepareStatement("SELECT 1, '/''' AS str WHERE 1=?")) { st1.setInt(1, 1); try (ResultSet rs = st1.executeQuery()) { while (rs.next()) { @@ -429,7 +418,7 @@ public void testQueryParamsWithBackSlash() throws Exception { */ @AfterAll public static void cleanup() throws SQLException { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName2), stmt); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java index cc0e7713b..a292fce50 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/preparedStatement/SetObjectTest.java @@ -14,23 +14,26 @@ import java.sql.Timestamp; import java.time.OffsetDateTime; import java.time.OffsetTime; + +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; import com.microsoft.sqlserver.jdbc.SQLServerConnection; -import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import microsoft.sql.DateTimeOffset; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class SetObjectTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("SetObjectTestTable"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java index 2296941e0..00897f566 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/DataClassificationTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -19,9 +20,13 @@ import com.microsoft.sqlserver.jdbc.dataclassification.SensitivityProperty; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xSQLv12) +@Tag(Constants.xSQLv14) public class DataClassificationTest extends AbstractTest { private static final String tableName = RandomUtil.getIdentifier("DataClassification"); @@ -33,7 +38,7 @@ public class DataClassificationTest extends AbstractTest { @Test public void testDataClassificationMetadata() throws Exception { // Run this test only with newer SQL Servers (version>=2018) that support Data Classification - try (Connection con = getConnection(); Statement stmt = connection.createStatement();) { + try (Statement stmt = connection.createStatement();) { if (TestUtils.serverSupportsDataClassification(stmt)) { createTable(connection, stmt); runTestsForServer(stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java index bdfd7ac7b..80ee49b1f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/resultset/ResultSetTest.java @@ -19,6 +19,7 @@ import java.sql.NClob; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.SQLWarning; import java.sql.SQLXML; import java.sql.Statement; import java.time.LocalDate; @@ -39,6 +40,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) @@ -53,6 +55,7 @@ public class ResultSetTest extends AbstractTest { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testJdbc41ResultSetMethods() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ( " + "col1 int, " @@ -246,7 +249,7 @@ public void testJdbc41ResultSetMethods() throws SQLException { assertFalse(rs.next()); } } finally { - stmt.executeUpdate("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } } @@ -257,7 +260,6 @@ public void testJdbc41ResultSetMethods() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetObjectAsLocalDateTime() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { TimeZone prevTimeZone = TimeZone.getDefault(); @@ -301,6 +303,7 @@ public void testGetObjectAsLocalDateTime() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testGetObjectAsOffsetDateTime() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { final String testValue = "2018-01-02T11:22:33.123456700+12:34"; @@ -335,7 +338,6 @@ public void testGetObjectAsOffsetDateTime() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testResultSetWrapper() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -361,7 +363,6 @@ public void testResultSetWrapper() throws SQLException { * @throws SQLException */ @Test - @Tag("AzureDWTest") public void testGetterOnNull() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select null")) { @@ -376,6 +377,7 @@ public void testGetterOnNull() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testGetSetHoldability() throws SQLException { int[] holdabilityOptions = {ResultSet.HOLD_CURSORS_OVER_COMMIT, ResultSet.CLOSE_CURSORS_AT_COMMIT}; @@ -401,6 +403,7 @@ public void testGetSetHoldability() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetMethods() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { @@ -510,4 +513,79 @@ public void testResultSetMethods() throws SQLException { } } } + + @Test + public void testMultipleResultSets() throws SQLException { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { + stmt.execute( + "CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (c1 int IDENTITY, c2 int)"); + String SQL = "exec sp_help 'dbo." + TestUtils.escapeSingleQuotes(tableName) + "'"; + + boolean results = stmt.execute(SQL); + int rsCount = 0; + int warningCount = 0; + + // Loop through the available result sets. + while (results) { + try (ResultSet rs = stmt.getResultSet()) { + rsCount++; + int i = 1; + String firstColumnValue = null; + while (rs.next()) { + switch (rsCount) { + case 1: + firstColumnValue = rs.getString("Name"); + assert (firstColumnValue.equals(tableName)); + break; + case 2: + firstColumnValue = rs.getString("Column_name"); + assert (firstColumnValue.equalsIgnoreCase("c" + i++)); + break; + case 3: + firstColumnValue = rs.getString("Identity"); + assert (firstColumnValue.equalsIgnoreCase("c1")); + break; + case 4: + firstColumnValue = rs.getString("RowGuidCol"); + assert (firstColumnValue.equalsIgnoreCase("No rowguidcol column defined.")); + break; + case 5: + firstColumnValue = rs.getString("Data_located_on_filegroup"); + assert (firstColumnValue.equalsIgnoreCase("PRIMARY")); + break; + } + } + } + + SQLWarning warnings = stmt.getWarnings(); + while (null != warnings) { + warningCount++; + warnings = warnings.getNextWarning(); + } + results = stmt.getMoreResults(); + } + assert (!stmt.getMoreResults() && -1 == stmt.getUpdateCount()); + assert (rsCount == 5); + assert (warningCount == 26); + + /* + * Testing Scenario: There are no more results when the following is true ............ + * ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1)) + */ + stmt.execute("INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values (12345)"); + assert (stmt.getUpdateCount() == 1); + assert (!stmt.getMoreResults()); + + try (ResultSet rs = stmt + .executeQuery("SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName))) { + // Calling getMoreResults() consumes and closes the current ResultSet + assert (!stmt.getMoreResults() && -1 == stmt.getUpdateCount()); + assert (rs.isClosed()); + } + } finally { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + } + } + } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java index dc9371a8b..4064ad1d1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ssl/trustmanager/CustomTrustManagerTest.java @@ -11,18 +11,15 @@ import java.sql.Connection; import java.sql.SQLException; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.testframework.AbstractTest; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class CustomTrustManagerTest extends AbstractTest { /** @@ -48,7 +45,7 @@ public void testWithPermissiveX509TrustManager() throws Exception { public void testWithTrustManagerConstructorArg() throws Exception { String url = connectionString + ";trustManagerClass=" + TrustManagerWithConstructorArg.class.getName() + ";trustManagerConstructorArg=dummyString;" + ";encrypt=true;"; - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(url)) { + try (Connection con = PrepUtil.getConnection(url)) { assertTrue(con != null); } } @@ -61,7 +58,7 @@ public void testWithTrustManagerConstructorArg() throws Exception { @Test public void testWithInvalidTrustManager() throws Exception { String url = connectionString + ";trustManagerClass=" + InvalidTrustManager.class.getName() + ";encrypt=true;"; - try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(url)) { + try (Connection con = PrepUtil.getConnection(url)) { fail(); } catch (SQLException e) { assertTrue(e.getMessage().contains( diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java index 4d3eeb0f6..854c80557 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPAllTypesTest.java @@ -11,6 +11,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.DBStatement; import com.microsoft.sqlserver.testframework.DBTable; @@ -32,6 +34,7 @@ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPAllTypesTest extends AbstractTest { private static String tvpName; @@ -212,7 +215,7 @@ private void setupVariation(boolean setSelectMethod, Statement stmt) throws SQLE } private void terminateVariation() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); TestUtils.dropTableIfExists(tableSrc.getEscapedTableName(), stmt); TestUtils.dropTableIfExists(tableDest.getEscapedTableName(), stmt); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java index a1a1cf57e..5199d647d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPIssuesTest.java @@ -4,17 +4,20 @@ */ package com.microsoft.sqlserver.jdbc.tvp; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,10 +29,12 @@ import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; -import com.microsoft.sqlserver.testframework.AbstractTest;; +import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPIssuesTest extends AbstractTest { private static String tvp_varcharMax = RandomUtil.getIdentifier("TVPIssuesTest_varcharMax_TVP"); @@ -56,7 +61,7 @@ public void tryTVPRSvarcharMax4000Issue() throws Exception { pstmt.setStructured(1, tvp_varcharMax, rs); pstmt.execute(); - testCharDestTable(); + testCharDestTable(st); } } @@ -67,22 +72,22 @@ public void tryTVPRSvarcharMax4000Issue() throws Exception { */ @Test public void testExceptionWithInvalidStoredProcedureName() throws Exception { - SQLServerStatement st = (SQLServerStatement) connection.createStatement(); - ResultSet rs = st.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable_varcharMax)); - - dropProcedure(); - - final String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + "(?)}"; - - try (SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql)) { - Cstmt.setObject(1, rs); - throw new Exception(TestResource.getResource("R_expectedExceptionNotThrown")); - } catch (Exception e) { - if (e instanceof SQLException) { - assertTrue(e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound")), - TestResource.getResource("R_invalidErrorMessage") + e.getMessage()); - } else { - throw e; + try (Statement stmt = connection.createStatement(); ResultSet rs = stmt + .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(srcTable_varcharMax))) { + + dropProcedure(stmt); + String sql = "{call " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + "(?)}"; + + try (SQLServerCallableStatement Cstmt = (SQLServerCallableStatement) connection.prepareCall(sql)) { + Cstmt.setObject(1, rs); + fail(TestResource.getResource("R_expectedExceptionNotThrown")); + } catch (Exception e) { + if (e instanceof SQLException) { + assertTrue(e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound")), + TestResource.getResource("R_invalidErrorMessage") + e.getMessage()); + } else { + fail(e.getMessage()); + } } } } @@ -104,12 +109,12 @@ public void tryTVPPrecisionmissedissue315() throws Exception { pstmt.setStructured(1, tvp_time_6, rs); pstmt.execute(); - testTime6DestTable(); + testTime6DestTable(stmt); } } - private void testCharDestTable() throws SQLException, IOException { - try (ResultSet rs = connection.createStatement() + private void testCharDestTable(Statement stmt) throws SQLException, IOException { + try (ResultSet rs = stmt .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax))) { while (rs.next()) { assertEquals(rs.getString(1).length(), 4001, TestResource.getResource("R_lengthTruncated")); @@ -117,8 +122,8 @@ private void testCharDestTable() throws SQLException, IOException { } } - private void testTime6DestTable() throws SQLException, IOException { - try (ResultSet rs = connection.createStatement() + private void testTime6DestTable(Statement stmt) throws SQLException, IOException { + try (ResultSet rs = stmt .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(desTable_time_6))) { while (rs.next()) { assertEquals(rs.getString(1), expectedTime6value, TestResource.getResource("R_timeValueTruncated")); @@ -130,7 +135,7 @@ private void testTime6DestTable() throws SQLException, IOException { public static void beforeAll() throws SQLException { try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - dropProcedure(); + dropProcedure(stmt); stmt.executeUpdate("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvp_varcharMax) + "') " + " drop type " @@ -164,10 +169,10 @@ public static void beforeAll() throws SQLException { + " as table (c1 time(6) null)"; stmt.executeUpdate(TVPCreateCmd); - createProcedure(); + createProcedure(stmt); populateCharSrcTable(); - populateTime6SrcTable(); + populateTime6SrcTable(stmt); } } @@ -180,42 +185,35 @@ private static void populateCharSrcTable() throws SQLException { } String value = sb.toString(); - try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql)) { - + try (PreparedStatement pstmt = connection.prepareStatement(sql)) { pstmt.setString(1, value); pstmt.execute(); } } - private static void populateTime6SrcTable() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(srcTable_time_6) - + " values ('2017-05-12 " + expectedTime6value + "')"; - connection.createStatement().execute(sql); - } + private static void populateTime6SrcTable(Statement stmt) throws SQLException { + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(srcTable_time_6) + " values ('2017-05-12 " + + expectedTime6value + "')"; + stmt.execute(sql); } - private static void dropProcedure() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(spName_varcharMax), stmt); - } + private static void dropProcedure(Statement stmt) throws SQLException { + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(spName_varcharMax), stmt); } - private static void createProcedure() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + " @InputData " - + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax) + " READONLY " + " AS " + " BEGIN " - + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax) - + " SELECT * FROM @InputData" + " END"; + private static void createProcedure(Statement stmt) throws SQLException { + String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(spName_varcharMax) + " @InputData " + + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax) + " READONLY " + " AS " + " BEGIN " + + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable_varcharMax) + + " SELECT * FROM @InputData" + " END"; - stmt.execute(sql); - } + stmt.execute(sql); } @AfterAll public static void terminateVariation() throws SQLException { - dropProcedure(); - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { + dropProcedure(stmt); stmt.executeUpdate("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvp_varcharMax) + "') " + " drop type " + AbstractSQLGenerator.escapeIdentifier(tvp_varcharMax)); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java index 57d261507..e3d7165bd 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPNumericTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -21,9 +22,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPNumericTest extends AbstractTest { static SQLServerDataTable tvp = null; @@ -129,5 +132,4 @@ public void terminateVariation() throws SQLException { tvp.clear(); } } - } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java index 37ad348f8..55986c83b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPResultSetCursorTest.java @@ -4,6 +4,7 @@ */ package com.microsoft.sqlserver.jdbc.tvp; +import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; @@ -17,6 +18,7 @@ import java.util.TimeZone; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -28,10 +30,12 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPResultSetCursorTest extends AbstractTest { static BigDecimal[] expectedBigDecimals = {new BigDecimal("12345.12345"), new BigDecimal("125.123"), @@ -80,7 +84,6 @@ private void serverCursorsTest(int resultSetType, int resultSetConcurrency) thro "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) + " select * from ? ;")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } } @@ -113,7 +116,6 @@ public void testSelectMethodSetToCursor() throws SQLException { "INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) + " select * from ? ;")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } } @@ -147,9 +149,7 @@ public void testSelectMethodSetToCursorWithSP() throws SQLException { SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn .prepareCall("{call " + AbstractSQLGenerator.escapeIdentifier(procedureName) + "(?)}")) { pstmt.setStructured(1, AbstractSQLGenerator.escapeIdentifier(tvpName), rs); - pstmt.execute(); - verifyDestinationTableData(expectedBigDecimals.length); } finally { dropProcedure(); @@ -188,7 +188,7 @@ public void testInvalidTVPName() throws SQLException { pstmt.execute(); } catch (SQLException e) { if (!e.getMessage().contains(TestResource.getResource("R_dataTypeNotFound"))) { - throw e; + fail(e.getMessage()); } } } @@ -221,14 +221,12 @@ public void testInvalidStoredProcedureName() throws SQLException { SQLServerCallableStatement pstmt = (SQLServerCallableStatement) conn.prepareCall( "{call invalid" + AbstractSQLGenerator.escapeIdentifier(procedureName) + "(?)}")) { pstmt.setStructured(1, tvpName, rs); - pstmt.execute(); } catch (SQLException e) { if (!e.getMessage().contains(TestResource.getResource("R_StoredProcedureNotFound"))) { - throw e; + fail(e.getMessage()); } } finally { - dropProcedure(); } } @@ -350,14 +348,14 @@ private static void populateSourceTable() throws SQLException { } private static void dropTables() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(srcTable), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(desTable), stmt); } } private static void createTables() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(srcTable) + " (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000), id int not null identity);"; stmt.execute(sql); @@ -369,7 +367,7 @@ private static void createTables() throws SQLException { } private static void createTVPS() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String TVPCreateCmd = "CREATE TYPE " + AbstractSQLGenerator.escapeIdentifier(tvpName) + " as table (c1 decimal(10,5) null, c2 nchar(50) null, c3 datetime2(7) null, c4 char(7000) null)"; stmt.execute(TVPCreateCmd); @@ -377,7 +375,7 @@ private static void createTVPS() throws SQLException { } private static void dropTVPS() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.execute("IF EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name = '" + TestUtils.escapeSingleQuotes(tvpName) + "') " + " drop type " + AbstractSQLGenerator.escapeIdentifier(tvpName)); @@ -385,13 +383,13 @@ private static void dropTVPS() throws SQLException { } private static void dropProcedure() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procedureName), stmt); } } private static void createProcedure() throws SQLException { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procedureName) + " @InputData " + AbstractSQLGenerator.escapeIdentifier(tvpName) + " READONLY " + " AS " + " BEGIN " + " INSERT INTO " + AbstractSQLGenerator.escapeIdentifier(desTable) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java index a4bf77ba9..4b17113f6 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPSchemaTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,9 +27,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPSchemaTest extends AbstractTest { static SQLServerDataTable tvp = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java index de8440918..73b89ff76 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/TVPTypesTest.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -28,9 +29,11 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class TVPTypesTest extends AbstractTest { static SQLServerDataTable tvp = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java index 8d21f523e..4593a368c 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SQLServerErrorTest.java @@ -14,6 +14,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -24,6 +25,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) @@ -31,6 +33,7 @@ public class SQLServerErrorTest extends AbstractTest { static int loginTimeOutInSeconds = 10; @Test + @Tag(Constants.xAzureSQLDW) public void testLoginFailedError() { SQLServerDataSource ds = new SQLServerDataSource(); ds.setURL(connectionString); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java index 22b7c2056..1ed15bf25 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/SavepointTest.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import java.text.MessageFormat; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -20,6 +21,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerSavepoint; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -34,6 +36,7 @@ public class SavepointTest extends AbstractTest { * Testing SavePoint with name. */ @Test + @Tag(Constants.xAzureSQLDW) public void testSavePointName() throws SQLException { try (Connection connection = getConnection()) { @@ -63,6 +66,7 @@ public void testSavePointName() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testSavePointId() throws SQLException { try (Connection connection = getConnection()) { @@ -92,6 +96,7 @@ public void testSavePointId() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) public void testSavePointIsNamed() throws SQLException { try (Connection connection = getConnection()) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java index 1aa6dbe30..9aa21dad7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/UTF8SupportTest.java @@ -9,7 +9,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.nio.charset.StandardCharsets; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -18,6 +17,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -26,15 +26,18 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.PrepUtil; +import com.microsoft.sqlserver.testframework.Constants; /** * A class for testing the UTF8 support changes. */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) +@Tag(Constants.xAzureSQLDB) +@Tag(Constants.xSQLv12) +@Tag(Constants.xSQLv14) public class UTF8SupportTest extends AbstractTest { - private static Connection connection; private static String databaseName; private static String tableName; @@ -107,7 +110,6 @@ public void testVarchar() throws SQLException { @BeforeAll public static void setUp() throws ClassNotFoundException, SQLException { - connection = PrepUtil.getConnection(getConnectionString()); if (TestUtils.serverSupportsUTF8(connection)) { databaseName = RandomUtil.getIdentifier("UTF8Database"); tableName = RandomUtil.getIdentifier("UTF8Table"); @@ -123,9 +125,6 @@ public static void cleanUp() throws SQLException { TestUtils.dropDatabaseIfExists(databaseName, stmt); } } - if (null != connection) { - connection.close(); - } } private static void createDatabaseWithUTF8Collation() throws SQLException { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java index f151f3922..fc258b9e1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsStreamingTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -30,6 +31,7 @@ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class LobsStreamingTest extends AbstractTest { private static String tableName = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java index 7d8df1c5f..341271fe2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/lobs/LobsTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.function.Executable; @@ -58,6 +59,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class LobsTest extends AbstractTest { static String tableName; static String escapedTableName; @@ -79,7 +81,7 @@ public static void init() throws SQLException { @TestFactory public Collection executeDynamicTests() { List> classes = new ArrayList>( - Arrays.asList(Blob.class, Clob.class, DBBinaryStream.class, DBCharacterStream.class)); + Arrays.asList(Blob.class, Clob.class, NClob.class, DBBinaryStream.class, DBCharacterStream.class)); List isResultSetTypes = new ArrayList<>(Arrays.asList(true, false)); Collection dynamicTests = new ArrayList<>(); @@ -161,7 +163,7 @@ private void testInvalidLobs(Class lobClass, boolean isResultSet) throws SQLE } catch (SQLException e) { boolean verified = false; - if (lobClass == Clob.class) + if (lobClass == Clob.class || lobClass == NClob.class) streamLength = ((DBInvalidUtil.InvalidClob) lob).length; else if (lobClass == Blob.class) streamLength = ((DBInvalidUtil.InvalidBlob) lob).length; @@ -178,8 +180,8 @@ else if (lobClass == Blob.class) } // Case 2: CharacterStream or Clob.getCharacterStream threw IOException - if (lobClass == DBCharacterStream.class - || (lobClass == Clob.class && ((DBInvalidUtil.InvalidClob) lob).stream != null)) { + if (lobClass == DBCharacterStream.class || ((lobClass == Clob.class || lobClass == NClob.class) + && ((DBInvalidUtil.InvalidClob) lob).stream != null)) { try (DBInvalidUtil.InvalidCharacterStream stream = lobClass == DBCharacterStream.class ? ((DBInvalidUtil.InvalidCharacterStream) lob) : ((DBInvalidUtil.InvalidClob) lob).stream) { if (stream.threwException) { @@ -668,6 +670,8 @@ else if (lob instanceof DBBinaryStream) ps.setBinaryStream(index, (InputStream) lob, length); else if (lob instanceof Clob) ps.setClob(index, (Clob) lob); + else if (lob instanceof NClob) + ps.setNClob(index, (NClob) lob); else ps.setBlob(index, (Blob) lob); assertEquals(ps.executeUpdate(), 1, TestResource.getResource("R_incorrectUpdateCount")); @@ -680,6 +684,8 @@ private void updateResultSet(ResultSet rs, Object lob, int index, int length) th rs.updateBinaryStream(index, (InputStream) lob, length); } else if (lob instanceof Clob) { rs.updateClob(index, (Clob) lob); + } else if (lob instanceof NClob) { + rs.updateNClob(index, (NClob) lob); } else { rs.updateBlob(index, (Blob) lob); } @@ -701,7 +707,7 @@ private Object createLob(Class lobClass) { return new DBInvalidUtil().new InvalidCharacterStream(new String(data), streamLength < -1); else if (lobClass == DBBinaryStream.class) return new DBInvalidUtil().new InvalidBinaryStream(data, streamLength < -1); - if (lobClass == Clob.class) { + if (lobClass == Clob.class || lobClass == NClob.class) { SqlType type = TestUtils.find(String.class); Object expected = type.createdata(String.class, data); return new DBInvalidUtil().new InvalidClob(expected, false); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java index 4bbaff397..c8f5b3aa2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/serial/DTOSerialTest.java @@ -14,6 +14,7 @@ import java.util.Date; import java.util.TimeZone; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -23,6 +24,7 @@ import com.microsoft.sqlserver.jdbc.SQLServerResultSet; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import microsoft.sql.DateTimeOffset; @@ -33,6 +35,7 @@ public class DTOSerialTest extends AbstractTest { private static String dateString; @Test + @Tag(Constants.xAzureSQLDW) public void testDSerial() throws Exception { sdf.setTimeZone(TimeZone.getTimeZone("Z")); dateString = sdf.format(new Date()); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java index ae577a255..eeee5a7f1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecuteWithErrorsTest.java @@ -8,7 +8,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.reflect.Field; import java.sql.BatchUpdateException; @@ -31,6 +30,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -38,7 +38,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class BatchExecuteWithErrorsTest extends AbstractTest { public static final Logger log = Logger.getLogger("BatchExecuteWithErrors"); @@ -73,18 +72,20 @@ public void Repro47239UseBulkCopyAPI() throws Exception { } /** - * Tests large methods, supported in 42 + * Tests large methods * * @throws Exception */ @Test @DisplayName("Regression test for using 'large' methods") + @Tag(Constants.xAzureSQLDW) public void Repro47239large() throws Exception { Repro47239largeInternal("BatchInsert"); } @Test @DisplayName("Regression test for using 'large' methods using bulk copy API") + @Tag(Constants.xAzureSQLDW) public void Repro47239largeUseBulkCopyAPI() throws Exception { Repro47239largeInternal("BulkCopy"); } @@ -93,8 +94,7 @@ private void Repro47239Internal(String mode) throws Exception { try (Connection con = getConnection()) { if (isSqlAzure()) { // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have - // not - // "with log" option + // not "with log" option warning = "RAISERROR ('raiserror level 4',4,1)"; error = "RAISERROR ('raiserror level 11',11,1)"; // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to @@ -120,20 +120,209 @@ private void Repro47239Internal(String mode) throws Exception { int[] expectedUpdateCounts; String actualExceptionText; - try (Connection conn = getConnection()) { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + if (mode.equalsIgnoreCase("bulkcopy")) { modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); } - try (Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1))"); + + // Regular Statement batch update + expectedUpdateCounts = new int[] {1, -2, 1, -2, 1, -2}; + try (Statement batchStmt = conn.createStatement()) { + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + batchStmt.addBatch(insertStmt); + batchStmt.addBatch(warning); + try { + actualUpdateCounts = batchStmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + if (log.isLoggable(Level.FINE)) { + log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); + } + } finally { + batchStmt.close(); + } + } + if (log.isLoggable(Level.FINE)) { + log.fine("UpdateCounts:"); + } + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_testInterleaved")); + + expectedUpdateCounts = new int[] {-3, 1, 1, 1}; + stmt.addBatch(error); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + try { + actualUpdateCounts = stmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + } + log.fine("UpdateCounts:"); + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_errorFollowInserts")); + // 50280 + expectedUpdateCounts = new int[] {1, -3}; + stmt.addBatch(insertStmt); + stmt.addBatch(error16); + try { + actualUpdateCounts = stmt.executeBatch(); + actualExceptionText = ""; + } catch (BatchUpdateException bue) { + actualUpdateCounts = bue.getUpdateCounts(); + actualExceptionText = bue.getMessage(); + } + for (int updateCount : actualUpdateCounts) { + log.fine("" + updateCount + ","); + } + + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), + TestResource.getResource("R_errorFollow50280")); + + // Test "soft" errors + conn.setAutoCommit(false); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + try { + stmt.executeBatch(); + // Soft error test: executeBatch unexpectedly succeeded + assertEquals(true, false, TestResource.getResource("R_shouldThrowException")); + } catch (BatchUpdateException bue) { + assertEquals("A result set was generated for update.", bue.getMessage(), + TestResource.getResource("R_unexpectedExceptionContent")); + assertEquals(Arrays.equals(bue.getUpdateCounts(), new int[] {-3, 1, -3, 1}), true, + TestResource.getResource("R_incorrectUpdateCount")); + } + conn.rollback(); + stmt.addBatch(dateConversionError); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); + try { + stmt.executeBatch(); + } catch (BatchUpdateException bue) { + if (isSqlAzureDW()) { + assertThat(bue.getMessage(), + containsString(TestResource.getResource("R_syntaxErrorDateConvertDW"))); + } else { + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); + } + } catch (SQLException e) { + assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); + } + conn.setAutoCommit(true); + + // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to + // cut the current connection by a statement inside a SQL batch. + // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the + // database, + // this simulation cannot be written entirely in TSQL (because it needs a new connection), + // and thus it cannot be put into a TSQL batch and it is useless here. + // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) + // errors" + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // test coverage. + if (!isSqlAzure()) { + // Test Severe (connection-closing) errors + stmt.addBatch(error); + stmt.addBatch(insertStmt); + stmt.addBatch(warning); + stmt.addBatch(select); + stmt.addBatch(insertStmt); + stmt.addBatch(severe); + stmt.addBatch(insertStmt); + stmt.addBatch(insertStmt); try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (Exception ignored) {} - stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1))"); + stmt.executeBatch(); + // Test fatal errors batch execution succeeded (should have failed) + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); + } catch (BatchUpdateException bue) { + // Test fatal errors returned BatchUpdateException rather than SQLException + assertEquals(false, true, TestResource.getResource("R_unexpectedException") + bue.getMessage()); + + } catch (SQLException e) { + actualExceptionText = e.getMessage(); + + if (actualExceptionText.endsWith("reset")) { + assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), + TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); + } else { + assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), + TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); + } + } + } + } finally { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + } + } + } + + private void Repro47239largeInternal(String mode) throws Exception { + // the DBConnection for detecting whether the server is SQL Azure or SQL Server. + try (Connection con = getConnection()) { + if (isSqlAzure()) { + // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have + // not + // "with log" option + warning = "RAISERROR ('raiserror level 4',4,1)"; + error = "RAISERROR ('raiserror level 11',11,1)"; + // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to + // cut the current connection by a statement inside a SQL batch. + // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the + // database, + // this simulation cannot be written entirely in TSQL (because it needs a new connection), + // and thus it cannot be put into a TSQL batch and it is useless here. + // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) + // errors" + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // test coverage. + severe = "--Not executed when testing against SQL Azure"; // this is a dummy statement that never being + // executed on SQL Azure + } else { + warning = "RAISERROR ('raiserror level 4',4,1) WITH LOG"; + error = "RAISERROR ('raiserror level 11',11,1) WITH LOG"; + severe = "RAISERROR ('raiserror level 20',20,1) WITH LOG"; + } + con.close(); + long[] actualUpdateCounts; + long[] expectedUpdateCounts; + String actualExceptionText; + + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + + if (mode.equalsIgnoreCase("bulkcopy")) { + modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); + } + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + stmt.executeLargeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1) primary key)"); // Regular Statement batch update - expectedUpdateCounts = new int[] {1, -2, 1, -2, 1, -2}; + expectedUpdateCounts = new long[] {1, -2, 1, -2, 1, -2}; try (Statement batchStmt = conn.createStatement()) { batchStmt.addBatch(insertStmt); batchStmt.addBatch(warning); @@ -142,62 +331,58 @@ private void Repro47239Internal(String mode) throws Exception { batchStmt.addBatch(insertStmt); batchStmt.addBatch(warning); try { - actualUpdateCounts = batchStmt.executeBatch(); + actualUpdateCounts = batchStmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); - if (log.isLoggable(Level.FINE)) { - log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); - } - } finally { - batchStmt.close(); + log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); } } - if (log.isLoggable(Level.FINE)) { - log.fine("UpdateCounts:"); - } - for (int updateCount : actualUpdateCounts) { + + log.fine("UpdateCounts:"); + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_testInterleaved")); - expectedUpdateCounts = new int[] {-3, 1, 1, 1}; + expectedUpdateCounts = new long[] {-3, 1, 1, 1}; stmt.addBatch(error); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - actualUpdateCounts = stmt.executeBatch(); + actualUpdateCounts = stmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); } log.fine("UpdateCounts:"); - for (int updateCount : actualUpdateCounts) { + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollowInserts")); + // 50280 - expectedUpdateCounts = new int[] {1, -3}; + expectedUpdateCounts = new long[] {1, -3}; stmt.addBatch(insertStmt); stmt.addBatch(error16); try { - actualUpdateCounts = stmt.executeBatch(); + actualUpdateCounts = stmt.executeLargeBatch(); actualExceptionText = ""; } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getUpdateCounts(); + actualUpdateCounts = bue.getLargeUpdateCounts(); actualExceptionText = bue.getMessage(); } - for (int updateCount : actualUpdateCounts) { + for (long updateCount : actualUpdateCounts) { log.fine("" + updateCount + ","); } - log.fine(""); + assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), TestResource.getResource("R_errorFollow50280")); @@ -208,13 +393,15 @@ private void Repro47239Internal(String mode) throws Exception { stmt.addBatch(select); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); - // Soft error test: executeBatch unexpectedly succeeded - assertEquals(true, false, TestResource.getResource("R_shouldThrowException")); + stmt.executeLargeBatch(); + // Soft error test: executeLargeBatch unexpectedly succeeded + assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { + // Soft error test: wrong error message in BatchUpdateException assertEquals("A result set was generated for update.", bue.getMessage(), TestResource.getResource("R_unexpectedExceptionContent")); - assertEquals(Arrays.equals(bue.getUpdateCounts(), new int[] {-3, 1, -3, 1}), true, + // Soft error test: wrong update counts in BatchUpdateException + assertEquals(Arrays.equals(bue.getLargeUpdateCounts(), new long[] {-3, 1, -3, 1}), true, TestResource.getResource("R_incorrectUpdateCount")); } conn.rollback(); @@ -225,23 +412,11 @@ private void Repro47239Internal(String mode) throws Exception { stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); + stmt.executeLargeBatch(); } catch (BatchUpdateException bue) { - if (isSqlAzureDW()) { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvertDW"))); - } else { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); - } - // CTestLog.CompareStartsWith(bue.getMessage(), "Syntax error converting date", "Transaction - // rollback with conversion error threw wrong - // BatchUpdateException"); + assertThat(bue.getMessage(), containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); } catch (SQLException e) { assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); - // CTestLog.CompareStartsWith(e.getMessage(), "Conversion failed when converting date", "Transaction - // rollback with conversion error threw - // wrong SQLException"); } conn.setAutoCommit(true); @@ -254,27 +429,26 @@ private void Repro47239Internal(String mode) throws Exception { // and thus it cannot be put into a TSQL batch and it is useless here. // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best + // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have + // best // test coverage. if (!isSqlAzure()) { // Test Severe (connection-closing) errors stmt.addBatch(error); stmt.addBatch(insertStmt); stmt.addBatch(warning); - // TODO Removed until ResultSet refactoring task (45832) is complete. - // stmt.addBatch(select); // error: select not permitted in batch + stmt.addBatch(insertStmt); stmt.addBatch(severe); stmt.addBatch(insertStmt); stmt.addBatch(insertStmt); try { - stmt.executeBatch(); + stmt.executeLargeBatch(); // Test fatal errors batch execution succeeded (should have failed) assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); } catch (BatchUpdateException bue) { // Test fatal errors returned BatchUpdateException rather than SQLException assertEquals(false, true, TestResource.getResource("R_unexpectedException") + bue.getMessage()); - } catch (SQLException e) { actualExceptionText = e.getMessage(); @@ -286,213 +460,13 @@ private void Repro47239Internal(String mode) throws Exception { assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), TestResource.getResource("R_unexpectedExceptionContent") + ": " + actualExceptionText); - } - } - } - } - } finally { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { - stmt.executeUpdate("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); - } - } - } - private void Repro47239largeInternal(String mode) throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - // the DBConnection for detecting whether the server is SQL Azure or SQL Server. - try (Connection con = getConnection()) { - if (isSqlAzure()) { - // SQL Azure will throw exception for "raiserror WITH LOG", so the following RAISERROR statements have - // not - // "with log" option - warning = "RAISERROR ('raiserror level 4',4,1)"; - error = "RAISERROR ('raiserror level 11',11,1)"; - // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to - // cut the current connection by a statement inside a SQL batch. - // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the - // database, - // this simulation cannot be written entirely in TSQL (because it needs a new connection), - // and thus it cannot be put into a TSQL batch and it is useless here. - // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) - // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have best - // test coverage. - severe = "--Not executed when testing against SQL Azure"; // this is a dummy statement that never being - // executed on SQL Azure - } else { - warning = "RAISERROR ('raiserror level 4',4,1) WITH LOG"; - error = "RAISERROR ('raiserror level 11',11,1) WITH LOG"; - severe = "RAISERROR ('raiserror level 20',20,1) WITH LOG"; - } - con.close(); - - long[] actualUpdateCounts; - long[] expectedUpdateCounts; - String actualExceptionText; - - try (Connection conn = getConnection()) { - if (mode.equalsIgnoreCase("bulkcopy")) { - modifyConnectionForBulkCopyAPI((SQLServerConnection) conn); - } - try (Statement stmt = conn.createStatement()) { - - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (Exception ignored) {} - try { - stmt.executeLargeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " (c1_int int, c2_varchar varchar(20), c3_date datetime, c4_int int identity(1,1) primary key)"); - } catch (Exception ignored) {} - // Regular Statement batch update - expectedUpdateCounts = new long[] {1, -2, 1, -2, 1, -2}; - try (Statement batchStmt = conn.createStatement()) { - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - batchStmt.addBatch(insertStmt); - batchStmt.addBatch(warning); - try { - actualUpdateCounts = batchStmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - log.fine("BatchUpdateException occurred. Message:" + actualExceptionText); - } - } - - log.fine("UpdateCounts:"); - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_testInterleaved")); - - expectedUpdateCounts = new long[] {-3, 1, 1, 1}; - stmt.addBatch(error); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - actualUpdateCounts = stmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - } - log.fine("UpdateCounts:"); - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_errorFollowInserts")); - - // 50280 - expectedUpdateCounts = new long[] {1, -3}; - stmt.addBatch(insertStmt); - stmt.addBatch(error16); - try { - actualUpdateCounts = stmt.executeLargeBatch(); - actualExceptionText = ""; - } catch (BatchUpdateException bue) { - actualUpdateCounts = bue.getLargeUpdateCounts(); - actualExceptionText = bue.getMessage(); - } - for (long updateCount : actualUpdateCounts) { - log.fine("" + updateCount + ","); - } - log.fine(""); - assertTrue(Arrays.equals(actualUpdateCounts, expectedUpdateCounts), - TestResource.getResource("R_errorFollow50280")); - - // Test "soft" errors - conn.setAutoCommit(false); - stmt.addBatch(select); - stmt.addBatch(insertStmt); - stmt.addBatch(select); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - // Soft error test: executeLargeBatch unexpectedly succeeded - assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); - } catch (BatchUpdateException bue) { - // Soft error test: wrong error message in BatchUpdateException - assertEquals("A result set was generated for update.", bue.getMessage(), - TestResource.getResource("R_unexpectedExceptionContent")); - // Soft error test: wrong update counts in BatchUpdateException - assertEquals(Arrays.equals(bue.getLargeUpdateCounts(), new long[] {-3, 1, -3, 1}), true, - TestResource.getResource("R_incorrectUpdateCount")); - } - conn.rollback(); - - // Defect 128801: Rollback (with conversion error) should throw SQLException - stmt.addBatch(dateConversionError); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - } catch (BatchUpdateException bue) { - assertThat(bue.getMessage(), - containsString(TestResource.getResource("R_syntaxErrorDateConvert"))); - } catch (SQLException e) { - assertThat(e.getMessage(), containsString(TestResource.getResource("R_dateConvertError"))); - } - - conn.setAutoCommit(true); - - // On SQL Azure, raising FATAL error by RAISERROR() is not supported and there is no way to - // cut the current connection by a statement inside a SQL batch. - // Details: Although one can simulate a fatal error (that cuts the connections) by dropping the - // database, - // this simulation cannot be written entirely in TSQL (because it needs a new connection), - // and thus it cannot be put into a TSQL batch and it is useless here. - // So we have to skip the last scenario of this test case, i.e. "Test Severe (connection-closing) - // errors" - // It is worthwhile to still execute the first 5 test scenarios of this test case, in order to have - // best - // test coverage. - if (!isSqlAzure()) { - // Test Severe (connection-closing) errors - stmt.addBatch(error); - stmt.addBatch(insertStmt); - stmt.addBatch(warning); - - stmt.addBatch(insertStmt); - stmt.addBatch(severe); - stmt.addBatch(insertStmt); - stmt.addBatch(insertStmt); - try { - stmt.executeLargeBatch(); - // Test fatal errors batch execution succeeded (should have failed) - assertEquals(false, true, TestResource.getResource("R_shouldThrowException")); - } catch (BatchUpdateException bue) { - // Test fatal errors returned BatchUpdateException rather than SQLException - assertEquals(false, true, - TestResource.getResource("R_unexpectedException") + bue.getMessage()); - } catch (SQLException e) { - actualExceptionText = e.getMessage(); - - if (actualExceptionText.endsWith("reset")) { - assertTrue(actualExceptionText.equalsIgnoreCase("Connection reset"), - TestResource.getResource("R_unexpectedExceptionContent") + ": " - + actualExceptionText); - } else { - assertTrue(actualExceptionText.equalsIgnoreCase("raiserror level 20"), - TestResource.getResource("R_unexpectedExceptionContent") + ": " - + actualExceptionText); - - } } } - - try { - stmt.executeLargeUpdate("drop table " + AbstractSQLGenerator.escapeIdentifier(tableName)); - } catch (Exception ignored) {} + } + } finally { + try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index d3de5182e..80cf42af7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.reflect.Field; import java.sql.Connection; @@ -17,6 +16,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -29,7 +29,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.DBConnection; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -38,6 +38,8 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xSQLv12) +@Tag(Constants.xAzureSQLDW) public class BatchExecutionTest extends AbstractTest { static String ctstable1; @@ -233,17 +235,12 @@ public static void testSetup() throws TestAbortedException, Exception { ctstable1 = RandomUtil.getIdentifier("ctstable1"); ctstable2 = RandomUtil.getIdentifier("ctstable2"); - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTable(); createTable(); } private static void dropTable() throws SQLException { - try (Connection connection = PrepUtil.getConnection(connectionString + ";columnEncryptionSetting=Enabled;"); - Statement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(ctstable2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(ctstable1), stmt); } @@ -251,10 +248,6 @@ private static void dropTable() throws SQLException { @AfterAll public static void terminateVariation() throws Exception { - try (DBConnection con = new DBConnection(connectionString)) { - assumeTrue(13 <= con.getServerVersion(), TestResource.getResource("R_Incompat_SQLServerVersion")); - } - dropTable(); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java index 62e300227..22cce7aaf 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchTriggerTest.java @@ -7,20 +7,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; @@ -33,6 +32,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class BatchTriggerTest extends AbstractTest { static String tableName; @@ -46,7 +46,7 @@ public class BatchTriggerTest extends AbstractTest { */ @Test public void statementTest() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { stmt.addBatch(insertQuery); stmt.executeBatch(); fail(TestResource.getResource("R_expectedExceptionNotThrown")); @@ -62,14 +62,11 @@ public void statementTest() throws SQLException { */ @Test public void preparedStatementTest() throws SQLException { - try (Connection connection = getConnection(); - PreparedStatement pstmt = connection.prepareStatement(insertQuery)) { - + try (PreparedStatement pstmt = connection.prepareStatement(insertQuery)) { pstmt.addBatch(); pstmt.executeBatch(); fail(TestResource.getResource("R_expectedExceptionNotThrown")); } catch (Exception e) { - assertTrue(e.getMessage().equalsIgnoreCase(TestResource.getResource("R_customErrorMessage"))); } } @@ -81,7 +78,7 @@ public void preparedStatementTest() throws SQLException { * @throws SQLException */ private static void createTrigger(String triggerName) throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { String sql = "create trigger " + triggerName + " on " + AbstractSQLGenerator.escapeIdentifier(tableName) + " for insert " + "as " + "begin " + "if (select col1 from " + AbstractSQLGenerator.escapeIdentifier(tableName) + ") > 10 " + "begin " + "return " + "end " @@ -96,12 +93,10 @@ private static void createTrigger(String triggerName) throws SQLException { * * @throws SQLException */ - private static void createTable() throws SQLException { - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " ( col1 int, col2 varchar(50), col3 varchar(10), col4 int)"; - stmt.execute(sql); - } + private static void createTable(Statement stmt) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " ( col1 int, col2 varchar(50), col3 varchar(10), col4 int)"; + stmt.execute(sql); } /** @@ -117,11 +112,10 @@ public static void testSetup() throws TestAbortedException, Exception { insertQuery = "insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1, col2, col3, col4) values (1, '22-08-2017 17:30:00.000', 'R4760', 31)"; - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTriggerIfExists(triggerName, stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - createTable(); + createTable(stmt); createTrigger(AbstractSQLGenerator.escapeIdentifier(triggerName)); } } @@ -133,8 +127,7 @@ public static void testSetup() throws TestAbortedException, Exception { */ @AfterAll public static void terminateVariation() throws SQLException { - try (Connection connection = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) connection.createStatement()) { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.execute("IF EXISTS (\r\n" + " SELECT *\r\n" + " FROM sys.objects\r\n" + " WHERE [type] = 'TR' AND [name] = '" + TestUtils.escapeSingleQuotes(triggerName) + "'\r\n" diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java index 8d8586ddb..2d5eaaedc 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/CallableMixedTest.java @@ -7,12 +7,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.CallableStatement; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -22,6 +21,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -29,6 +29,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class CallableMixedTest extends AbstractTest { String tableName = RandomUtil.getIdentifier("TFOO3"); String procName = RandomUtil.getIdentifier("SPFOO3"); @@ -39,10 +40,8 @@ public class CallableMixedTest extends AbstractTest { * @throws SQLException */ @Test - @DisplayName("Test CallableMix") public void datatypesTest() throws SQLException { - try (Connection connection = getConnection(); Statement statement = connection.createStatement();) { - + try (Statement statement = connection.createStatement();) { statement.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (c1_int int primary key, col2 int)"); statement diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java index ceff67cbc..f9dd6a63f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/LimitEscapeTest.java @@ -15,13 +15,14 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.Vector; import java.util.logging.Logger; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +32,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -38,6 +40,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class LimitEscapeTest extends AbstractTest { public static final Logger log = Logger.getLogger("LimitEscape"); private static Vector offsetQuery = new Vector<>(); @@ -270,7 +273,6 @@ public static void createAndPopulateTables(Connection conn) throws Exception { * @throws Exception */ @Test - @DisplayName("initAndVerifyQueries") public void initAndVerifyQueries() throws Exception { Query qry; try (Connection conn = getConnection()) { @@ -836,7 +838,6 @@ public void initAndVerifyQueries() throws Exception { * @throws Exception */ @Test - @DisplayName("verifyOffsetException") public void verifyOffsetException() throws Exception { offsetQuery.addElement("select * from " + AbstractSQLGenerator.escapeIdentifier(TestUtils.escapeSingleQuotes(table1)) + " {limit 2 offset 1}"); @@ -892,8 +893,8 @@ public void verifyOffsetException() throws Exception { */ @BeforeAll public static void beforeAll() { - try (Connection conn = getConnection()) { - createAndPopulateTables(conn); + try { + createAndPopulateTables(connection); } catch (Exception e) { fail(e.getMessage()); } @@ -905,15 +906,13 @@ public static void beforeAll() { * @throws Exception */ @AfterAll - public static void afterAll() throws Exception { - try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { + public static void afterAll() throws SQLException { + try (Statement stmt = connection.createStatement()) { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); - } catch (Exception ex) { - fail(ex.toString()); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java index c55e09462..f2995c373 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/MergeTest.java @@ -5,14 +5,13 @@ package com.microsoft.sqlserver.jdbc.unit.statement; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; -import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,6 +30,7 @@ * Testing merge queries */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class MergeTest extends AbstractTest { static String cricketTeams = RandomUtil.getIdentifier("CricketTeams"); static String cricketTeamsUpdated = RandomUtil.getIdentifier("cricketTeamsUpdated"); @@ -68,7 +68,6 @@ public class MergeTest extends AbstractTest { * @throws Exception */ @Test - @DisplayName("Merge Test") public void runTest() throws Exception { try (DBConnection conn = new DBConnection(connectionString)) { if (conn.getServerVersion() >= 10) { @@ -90,15 +89,10 @@ public void runTest() throws Exception { * @throws Exception */ @AfterAll - public static void afterAll() throws Exception { - - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeams), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeamsUpdated), stmt); - } catch (Exception ex) { - fail(ex.toString()); - } + public static void afterAll() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeams), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(cricketTeamsUpdated), stmt); } } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java index c4127b2b5..08f0aaf43 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/NamedParamMultiPartTest.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -23,6 +24,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; /** @@ -30,6 +32,7 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class NamedParamMultiPartTest extends AbstractTest { private static final String dataPut = RandomUtil.getIdentifier("dataPut"); static String procedureName; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java index 0bb0b2785..6cdabe976 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PQImpsTest.java @@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import java.sql.Connection; import java.sql.ParameterMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -17,12 +18,12 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; @@ -36,10 +37,11 @@ * */ @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class PQImpsTest extends AbstractTest { private static final int SQL_SERVER_2012_VERSION = 11; - private static SQLServerConnection connection = null; + private static Connection connection = null; private static Statement stmt = null; private static PreparedStatement pstmt = null; private static ResultSet rs = null; @@ -64,7 +66,7 @@ public class PQImpsTest extends AbstractTest { */ @BeforeAll public static void BeforeTests() throws SQLException { - connection = (SQLServerConnection) getConnection(); + connection = getConnection(); stmt = connection.createStatement(); version = getSQLServerVersion(); createMultipleTypesTable(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java index bdea0a210..ced1473e1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PoolableTest.java @@ -15,7 +15,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -33,7 +32,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class PoolableTest extends AbstractTest { /** diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java index bd3ab38c1..20ebbc2b2 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/PreparedStatementTest.java @@ -22,6 +22,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -67,6 +68,8 @@ private int executeSQLReturnFirstInt(SQLServerConnection conn, String sql) throw * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testBatchedUnprepare() throws SQLException { SQLServerConnection conOuter = null; @@ -145,6 +148,8 @@ public void testBatchedUnprepare() throws SQLException { * @throws SQLException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testStatementPooling() throws Exception { testStatementPoolingInternal("batchInsert"); } @@ -159,6 +164,8 @@ public void testStatementPooling() throws Exception { * @throws IllegalArgumentException */ @Test + @Tag(Constants.xAzureSQLDW) + @Tag(Constants.xAzureSQLDB) public void testStatementPoolingUseBulkCopyAPI() throws Exception { testStatementPoolingInternal("BulkCopy"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java index 2b140e109..86b64fd37 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/RegressionTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.unit.statement; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.sql.Connection; import java.sql.JDBCType; @@ -16,22 +15,25 @@ import java.sql.Types; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerConnection; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class RegressionTest extends AbstractTest { - private static String tableName; + + private static String tableName = RandomUtil.getIdentifier("ServerCursorPStmt"); private static String procName = RandomUtil.getIdentifier("ServerCursorProc"); /** @@ -41,15 +43,13 @@ public class RegressionTest extends AbstractTest { */ @Test public void testServerCursorPStmt() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // expected values int numRowsInResult = 1; String col3Value = "India"; String col3Lookup = "IN"; - tableName = RandomUtil.getIdentifier("ServerCursorPStmt"); - stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int primary key, col2 varchar(3), col3 varchar(128))"); stmt.executeUpdate( @@ -109,7 +109,7 @@ public void testServerCursorPStmt() throws SQLException { */ @Test public void testSelectIntoUpdateCount() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection()) { + try (Connection con = getConnection()) { // Azure does not do SELECT INTO if (!isSqlAzure()) { @@ -148,15 +148,11 @@ public void testSelectIntoUpdateCount() throws SQLException { */ @Test public void testUpdateQuery() throws SQLException { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String sql; JDBCType[] targets = {JDBCType.INTEGER, JDBCType.SMALLINT}; int rows = 3; - tableName = RandomUtil.getIdentifier("[updateQuery]"); - + tableName = RandomUtil.getIdentifier("updateQuery"); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (" + "c1 int null," + "PK int NOT NULL PRIMARY KEY" + ")"); @@ -208,14 +204,10 @@ public void testUpdateQuery() throws SQLException { */ @Test public void testXmlQuery() throws SQLException { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - try (Connection connection = getConnection(); Statement stmt = connection.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); - createTable(stmt); - tableName = RandomUtil.getIdentifier("try_SQLXML_Table"); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + createTable(stmt); String sql = "UPDATE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " SET [c2] = ?, [c3] = ?"; try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement(sql)) { @@ -235,7 +227,7 @@ public void testXmlQuery() throws SQLException { pstmt.setObject(2, null, Types.SQLXML); pstmt.executeUpdate(); } finally { - TestUtils.dropTableIfExists(tableName, stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } } @@ -250,8 +242,8 @@ private void createTable(Statement stmt) throws SQLException { @AfterAll public static void terminate() throws SQLException { - try (SQLServerConnection con = (SQLServerConnection) getConnection(); Statement stmt = con.createStatement()) { - TestUtils.dropTableIfExists(tableName, stmt); + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java index e8dcb6dff..5bb33a51d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementCancellationTest.java @@ -10,6 +10,7 @@ import java.sql.SQLException; import java.sql.Statement; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -17,9 +18,11 @@ import com.microsoft.sqlserver.jdbc.SQLServerDataSource; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; @RunWith(JUnitPlatform.class) +@Tag(Constants.xAzureSQLDW) public class StatementCancellationTest extends AbstractTest { private static final long DELAY_WAIT_MILLISECONDS = 10000; private static final long CANCEL_WAIT_MILLISECONDS = 5000; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java index 1bbc668b2..cc7bf0cf9 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java @@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.StringReader; import java.math.BigDecimal; @@ -33,7 +32,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -49,6 +47,7 @@ import com.microsoft.sqlserver.jdbc.TestUtils; import com.microsoft.sqlserver.testframework.AbstractSQLGenerator; import com.microsoft.sqlserver.testframework.AbstractTest; +import com.microsoft.sqlserver.testframework.Constants; import com.microsoft.sqlserver.testframework.DBConnection; import com.microsoft.sqlserver.testframework.PrepUtil; @@ -63,6 +62,7 @@ public class StatementTest extends AbstractTest { public static final Logger log = Logger.getLogger("StatementTest"); @Nested + @Tag(Constants.xAzureSQLDW) public class TCAttentionHandling { private static final int NUM_TABLE_ROWS = 1000; private static final int MIN_TABLE_ROWS = 100; @@ -77,9 +77,7 @@ public void init() throws Exception { try (Connection con = getConnection()) { con.setAutoCommit(false); try (Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (SQLException e) {} + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 INT, col2 VARCHAR(" + TEST_STRING.length() + "))"); for (int i = 0; i < NUM_TABLE_ROWS; i++) @@ -92,10 +90,8 @@ public void init() throws Exception { @AfterEach public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - } catch (SQLException e) {} + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); } } @@ -106,7 +102,6 @@ public void terminate() throws Exception { */ @Test public void testCancelBeforeExecute() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.cancel(); try (ResultSet rs = stmt @@ -114,7 +109,6 @@ public void testCancelBeforeExecute() throws Exception { int numSelectedRows = 0; while (rs.next()) ++numSelectedRows; - // Wrong number of rows returned assertEquals(NUM_TABLE_ROWS, numSelectedRows, TestResource.getResource("R_valueNotMatch")); } @@ -214,9 +208,6 @@ public void testQueryTimeout() throws Exception { */ @Test public void testCancelLongResponse() throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - try (Connection con = getConnection(); Statement stmt = con .createStatement(SQLServerResultSet.TYPE_SS_DIRECT_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) { ((SQLServerStatement) stmt).setResponseBuffering("adaptive"); @@ -252,8 +243,7 @@ public void testCancelLongResponse() throws Exception { assertEquals(false, true, TestResource.getResource("R_expectedExceptionNotThrown")); } catch (SQLException e) { - assertEquals(TestResource.getResource("R_queryCancelled"), - TestResource.getResource("R_unexpectedException")); + assertEquals(TestResource.getResource("R_queryCancelled"), e.getMessage()); } assertEquals(false, NUM_TABLE_ROWS * NUM_TABLE_ROWS == numSelectedRows, @@ -878,7 +868,6 @@ public void testCloseOnCompletion() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCStatement { private final String table1Name = RandomUtil.getIdentifier("TCStatement1"); private final String table2Name = RandomUtil.getIdentifier("TCStatement2"); @@ -938,7 +927,7 @@ public void testCloseOnCompletion() throws Exception { * @throws Exception */ @Test - public void testConsecutiveQueries() throws Exception { + public void testConsecutiveQueries() throws SQLException { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // enable isCloseOnCompletion try { @@ -947,12 +936,8 @@ public void testConsecutiveQueries() throws Exception { throw new SQLException(TestResource.getResource("R_unexpectedException") + ": ", e); } - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1Name), stmt); - } catch (SQLException e) {} - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); - } catch (SQLException e) {} + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1Name), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(table1Name) + " (col1 INT)"); stmt.executeUpdate("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(table2Name) + " (col1 INT)"); @@ -964,48 +949,8 @@ public void testConsecutiveQueries() throws Exception { } } - /** - * TestJDBCVersion.value < 42 getLargeMaxRows / setLargeMaxRows should throw exception for version before - * sqljdbc42 - * - * @throws Exception - */ @Test - public void testLargeMaxRowsJDBC41() throws Exception { - assumeTrue("JDBC41".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - - try (Connection con = getConnection(); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - - // testing exception for getLargeMaxRows method - try { - stmt.getLargeMaxRows(); - throw new SQLException(TestResource.getResource("R_unexpectedException")); - } catch (Exception e) { - fail(e.getMessage()); - } - - // testing exception for setLargeMaxRows method - try { - stmt.setLargeMaxRows(2015); - throw new SQLException(TestResource.getResource("R_unexpectedException")); - } catch (Exception e) { - fail(e.getMessage()); - } - } - } - - /** - * testLargeMaxRows on JDBCVersion = 42 or later - * - * @throws Exception - */ - @Test - public void testLargeMaxRowsJDBC42() throws Exception { - assumeTrue("JDBC42".equals(TestUtils.getConfiguredProperty("JDBC_Version")), - TestResource.getResource("R_incompatJDBC")); - + public void testLargeMaxRows() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { // Default value should return zero @@ -1026,10 +971,10 @@ public void testLargeMaxRowsJDBC42() throws Exception { stmt.setLargeMaxRows(newValue); throw new SQLException("setLargeMaxRows(): Long values should not be set"); } catch (Exception e) { - assertEquals( - ("calling setLargeMaxRows failed : java.lang.UnsupportedOperationException: " - + "The supported maximum row count for a result set is Integer.MAX_VALUE or less."), - (e.getMessage()), TestResource.getResource("R_unexpectedException")); + assertTrue( + e.getMessage().contains( + "The supported maximum row count for a result set is Integer.MAX_VALUE or less."), + TestResource.getResource("R_unexpectedException")); } // Set a negative value. If negative is accepted, throw exception @@ -1037,10 +982,10 @@ public void testLargeMaxRowsJDBC42() throws Exception { stmt.setLargeMaxRows(-2012L); throw new SQLException("setLargeMaxRows(): Negative value not allowed"); } catch (Exception e) { - assertEquals( - "calling setLargeMaxRows failed : com.microsoft.sqlserver.jdbc.SQLServerException: " - + "The maximum row count -2,012 for a result set must be non-negative.", - e.getMessage(), TestResource.getResource("R_unexpectedException")); + assertTrue( + e.getMessage() + .contains("The maximum row count -2,012 for a result set must be non-negative."), + TestResource.getResource("R_unexpectedException")); } } } @@ -1066,6 +1011,7 @@ public class TCStatementCallable { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testJdbc41CallableStatementMethods() throws Exception { // Prepare database setup @@ -1224,6 +1170,7 @@ public class TCStatementParam { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testStatementOutParamGetsTwice() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { @@ -1272,6 +1219,7 @@ public void testStatementOutParamGetsTwice() throws Exception { } @Test + @Tag(Constants.xAzureSQLDW) public void testStatementOutManyParamGetsTwiceRandomOrder() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procName) @@ -1305,6 +1253,7 @@ public void testStatementOutManyParamGetsTwiceRandomOrder() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testStatementOutParamGetsTwiceInOut() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { stmt.executeUpdate("CREATE PROCEDURE " + AbstractSQLGenerator.escapeIdentifier(procName) @@ -1334,6 +1283,7 @@ public void testStatementOutParamGetsTwiceInOut() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetParams() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1369,6 +1319,7 @@ public void testResultSetParams() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetNullParams() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1433,6 +1384,7 @@ public void testFailedToResumeTransaction() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testResultSetErrors() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) { @@ -1463,19 +1415,19 @@ public void testResultSetErrors() throws Exception { * Verify proper handling of row errors in ResultSets. */ @Test - @Disabled - // TODO: We are commenting this out due to random AppVeyor failures. We will investigate later. + @Tag(Constants.xAzureSQLDW) public void testRowError() throws Exception { try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + " (col1 int)"); + stmt.executeUpdate("create table " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " (ROWID int IDENTITY, col1 int)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(0)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(1)"); stmt.executeUpdate("insert into " + AbstractSQLGenerator.escapeIdentifier(tableName) + " values(2)"); stmt.execute( "create procedure " + AbstractSQLGenerator.escapeIdentifier(procName) + " @col1Value int AS " + " BEGIN " + " SELECT col1 FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " WITH (UPDLOCK) WHERE (col1 = @col1Value) " + " END"); + + " WITH (UPDLOCK) WHERE (col1 = @col1Value) ORDER BY ROWID" + " END"); // For the test, lock each row in the table, one by one, for update // on one connection and, on another connection, verify that the @@ -1515,8 +1467,9 @@ public void testRowError() throws Exception { try (Statement stmt2 = testConn2.createStatement()) { stmt2.executeUpdate("SET LOCK_TIMEOUT 0"); - try (CallableStatement cstmt2 = testConn2.prepareCall("SELECT col1 FROM " - + AbstractSQLGenerator.escapeIdentifier(tableName) + " WITH (UPDLOCK)")) { + try (CallableStatement cstmt2 = testConn2.prepareCall( + "SELECT col1 FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + + " WITH (UPDLOCK) ORDER BY ROWID")) { // Verify that the result set can be closed after // the lock timeout error @@ -1527,10 +1480,7 @@ public void testRowError() throws Exception { // indicated row and continues to report that exception on subsequent // accesses to that row. try (ResultSet rs = cstmt2.executeQuery()) { - for (int i = 0; i < row; i++) - assertEquals(true, rs.next(), "Query returned wrong number of rows."); - - for (int i = 0; i < 2; i++) { + for (int i = 0; i < row; i++) { try { rs.next(); assertEquals(false, true, "lock timeout" @@ -1556,14 +1506,10 @@ public void testRowError() throws Exception { } @AfterEach - public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement()) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); - } catch (SQLException e) { - fail(e.getMessage()); - } + public void terminate() throws SQLException { + try (Statement stmt = connection.createStatement()) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(procName), stmt); } } } @@ -1607,6 +1553,7 @@ public void terminate() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testNBCROWNullsForLOBs() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1640,6 +1587,7 @@ public void testNBCROWNullsForLOBs() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSparseColumnSetValues() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1679,6 +1627,7 @@ public void testSparseColumnSetValues() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSparseColumnSetIndex() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1717,6 +1666,7 @@ public void testSparseColumnSetIndex() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testSparseColumnSetForException() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1754,6 +1704,7 @@ public void testSparseColumnSetForException() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testNBCRowForAllNulls() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1802,6 +1753,7 @@ public void testNBCRowForAllNulls() throws Exception { * @throws Exception */ @Test + @Tag(Constants.xAzureSQLDW) public void testNBCROWWithRandomAccess() throws Exception { try (DBConnection dbconn = new DBConnection(connectionString)) { if (dbconn.getServerVersion() <= 9.0) { @@ -1907,7 +1859,6 @@ public void testNBCROWWithRandomAccess() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCStatementIsClosed { @Test public void testActiveStatement() throws Exception { @@ -1971,7 +1922,6 @@ public void testClosedConnection() throws Exception { } @Nested - @Tag("AzureDWTest") public class TCResultSetIsClosed { /** @@ -2076,6 +2026,7 @@ public void testClosedConnection() throws Exception { } @Nested + @Tag(Constants.xAzureSQLDW) public class TCUpdateCountWithTriggers { private static final int NUM_ROWS = 3; @@ -2211,20 +2162,17 @@ public void testStatementInsertExecInsert() throws Exception { } @AfterEach - public void terminate() throws Exception { - try (Connection con = getConnection(); Statement stmt = con.createStatement();) { - try { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); - TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(sprocName), stmt); - } catch (SQLException e) { - fail(e.getMessage()); - } + public void terminate() throws SQLException { + try (Statement stmt = connection.createStatement();) { + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(tableName), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2Name), stmt); + TestUtils.dropProcedureIfExists(AbstractSQLGenerator.escapeIdentifier(sprocName), stmt); } } } @Nested + @Tag(Constants.xAzureSQLDW) public class TCUpdateCountAfterRaiseError { private final String tableName = RandomUtil.getIdentifier("TCUpdateCountAfterRaiseError"); private final String triggerName = tableName + "Trigger"; @@ -2434,6 +2382,7 @@ public void terminate() throws Exception { } @Nested + @Tag(Constants.xAzureSQLDW) public class TCNocount { private final String tableName = RandomUtil.getIdentifier("TCNoCount"); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java index d877c21c0..92d324b66 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/WrapperTest.java @@ -13,7 +13,6 @@ import java.sql.Statement; import java.text.MessageFormat; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -31,7 +30,6 @@ * */ @RunWith(JUnitPlatform.class) -@Tag("AzureDWTest") public class WrapperTest extends AbstractTest { /** @@ -120,7 +118,7 @@ public void wrapTest() throws Exception { */ @Test public void unWrapFailureTest() throws Exception { - try (Connection con = getConnection(); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + try (Connection con = getConnection(); Statement stmt = con.createStatement()) { String str = "java.lang.String"; boolean isWrapper = stmt.isWrapperFor(Class.forName(str)); stmt.unwrap(Class.forName(str)); diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index b50ff560e..184f31bb8 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -10,7 +10,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.FileHandler; import java.util.logging.Handler; @@ -59,7 +58,6 @@ public abstract class AbstractTest { protected static Connection connectionAzure = null; protected static String connectionString = null; - protected static Properties info = new Properties(); private static boolean _determinedSqlAzureOrSqlServer = false; private static boolean _isSqlAzure = false; @@ -78,28 +76,20 @@ public static void setup() throws Exception { applicationClientID = getConfiguredProperty("applicationClientID"); applicationKey = getConfiguredProperty("applicationKey"); keyIDs = getConfiguredProperty("keyID", "").split(Constants.SEMI_COLON); - connectionString = getConfiguredProperty(Constants.MSSQL_JDBC_TEST_CONNECTION_PROPERTIES); + ds = updateDataSource(new SQLServerDataSource()); dsXA = updateDataSource(new SQLServerXADataSource()); dsPool = updateDataSource(new SQLServerConnectionPoolDataSource()); - jksPaths = getConfiguredProperty("jksPaths", "").split(Constants.SEMI_COLON); - javaKeyAliases = getConfiguredProperty("javaKeyAliases", "").split(Constants.SEMI_COLON); - windowsKeyPath = getConfiguredProperty("windowsKeyPath"); - - // info.setProperty("ColumnEncryptionSetting", "Enabled"); // May be we - // can use parameterized way to change this value - if (!jksPaths[0].isEmpty()) { - info.setProperty("keyStoreAuthentication", Constants.JAVA_KEY_STORE_PASSWORD); - info.setProperty("keyStoreLocation", jksPaths[0]); - info.setProperty("keyStoreSecret", Constants.JKS_SECRET_STRING); - } - try { Assertions.assertNotNull(connectionString, TestResource.getResource("R_ConnectionStringNull")); Class.forName(Constants.MSSQL_JDBC_PACKAGE + ".SQLServerDriver"); - connection = PrepUtil.getConnection(connectionString, info); + if (!SQLServerDriver.isRegistered()) + SQLServerDriver.register(); + if (null == connection || connection.isClosed()) { + connection = getConnection(); + } isSqlAzureOrAzureDW(connection); } catch (Exception e) { throw e; @@ -219,21 +209,14 @@ protected static SQLServerConnection getConnection() throws SQLException { @AfterAll public static void teardown() throws Exception { try { - if (connection != null && !connection.isClosed()) { + if (null != connection && !connection.isClosed()) { connection.close(); } - } catch (Exception e) { - connection.close(); } finally { connection = null; } } - @BeforeAll - public static void registerDriver() throws Exception { - SQLServerDriver.register(); - } - /** * Read variable from property files if found null try to read from env. * diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java index 3fbba2ad3..eb2868550 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java @@ -11,6 +11,25 @@ public class Constants { + /** + * Use below tags for tests to exclude them from test group: + * + *
+     * xSQLv12 - - - - - - For tests not compatible with SQL Server 2008 R2 - 2014
+     * xSQLv14 - - - - - - For tests not compatible with SQL Server 2008 R2 - 2017
+     * xSQLv15 - - - - - - For tests not compatible with SQL Server 2008 R2 - 2019
+     * xAzureSQLDB - - - - For tests not compatible with Azure SQL Database
+     * xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse
+     * xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance
+     * 
+ */ + public static final String xSQLv12 = "xSQLv12"; + public static final String xSQLv14 = "xSQLv14"; + public static final String xSQLv15 = "xSQLv15"; + public static final String xAzureSQLDB = "xAzureSQLDB"; + public static final String xAzureSQLDW = "xAzureSQLDW"; + public static final String xAzureSQLMI = "xAzureSQLMI"; + public static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); public static final Logger LOGGER = Logger.getLogger("AbstractTest"); public static final String JKS_SECRET_STRING = "changeit"; diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java b/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java index ef779e597..ce270e3d3 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBConnection.java @@ -252,7 +252,7 @@ public double getServerVersion() throws Exception { serverversion = 16; } } catch (Exception e) { - throw new Exception("Unable to get dbms major version", e); + fail("Unable to get dbms major version", e); } } return serverversion; diff --git a/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java b/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java index 21afe445f..fd1ea5868 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/DBInvalidUtil.java @@ -15,7 +15,6 @@ import java.sql.Blob; import java.sql.Clob; import java.sql.SQLException; -import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Logger; import com.microsoft.sqlserver.jdbc.TestUtils.DBBinaryStream; @@ -67,8 +66,8 @@ public long length() throws SQLException { long ret = actualLength; long actual = ret; if (invalidLength == -1) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -189,8 +188,8 @@ public int read(char[] cbuf, int off, int len) throws IOException { int ret = super.read(cbuf, off, len); int actual = ret; if (!returnValid) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -247,8 +246,8 @@ public long length() throws SQLException { long ret = actualLength; long actual = ret; if (invalidLength == -1) { - int choose = ThreadLocalRandom.current().nextInt(5); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(5); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // more than ret @@ -342,7 +341,7 @@ public InputStream getBinaryStream(long pos, long length) throws SQLException { */ public class InvalidBinaryStream extends DBBinaryStream { final int diff = 5; - private boolean _returnValid = false; // Perfom invalid actions at most once + private boolean _returnValid = false; // Perform invalid actions at most once /** * Constructor @@ -360,8 +359,8 @@ public int read(byte[] bytes, int off, int len) { int ret = super.read(bytes, off, len); int actual = ret; if (!_returnValid) { - int choose = ThreadLocalRandom.current().nextInt(4); - int randomInt = 1 + ThreadLocalRandom.current().nextInt(diff); + int choose = Constants.RANDOM.nextInt(4); + int randomInt = 1 + Constants.RANDOM.nextInt(diff); switch (choose) { case 0: // greater than ret actual = ret + randomInt;