Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add ability to perform JUnit testing against Azure DW #903

Merged
merged 22 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.platform.version>1.3.1</junit.platform.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<testGroup></testGroup>
</properties>

<dependencies>
Expand Down Expand Up @@ -197,6 +198,7 @@
<properties>
<excludeTags>${skipTestTag}</excludeTags>
</properties>
<groups>${testGroup}</groups>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -266,6 +268,7 @@
<properties>
<excludeTags>${skipTestTag}</excludeTags>
</properties>
<groups>${testGroup}</groups>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected Object[][] getContents() {
{"R_errorFollowInserts", "Test error followed by inserts"},
{"R_errorFollow50280", "Test insert followed by non-fatal error (50280)"},
{"R_syntaxErrorDateConvert", "Syntax error converting date"},
{"R_syntaxErrorDateConvertDW", "Conversion failed when converting date and/or time from character string."},
{"R_dateConvertError", "Conversion failed when converting date"},
{"R_incompatJDBC", "Aborting test case as JDBC version is not compatible."},
{"R_unexpectedException", "Unexpected exception occurred"}, {"R_addBatchFailed", "addBatch failed"},
Expand Down
89 changes: 87 additions & 2 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URI;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -24,6 +25,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.sqlType.SqlBigInt;
import com.microsoft.sqlserver.testframework.sqlType.SqlBinary;
import com.microsoft.sqlserver.testframework.sqlType.SqlBit;
Expand Down Expand Up @@ -64,9 +66,17 @@ public class TestUtils {
// 'SQL' represents SQL Server, while 'SQLAzure' represents SQL Azure.
public static final String SERVER_TYPE_SQL_SERVER = "SQL";
public static final String SERVER_TYPE_SQL_AZURE = "SQLAzure";

// private static SqlType types = null;
private static ArrayList<SqlType> types = null;

private final static int ENGINE_EDITION_FOR_SQL_AZURE = 5;
private final static int ENGINE_EDITION_FOR_SQL_AZURE_DW = 6;

// whether we determined if the target server is SQL Azure
private static boolean _determinedSqlAzureOrSqlServer = false;
private static boolean _isSqlAzure = false;
private static boolean _isSqlAzureDW = false;

/**
* Returns serverType
*
Expand Down Expand Up @@ -666,4 +676,79 @@ public static boolean supportJDBC43(Connection con) throws SQLException {
public static String escapeSingleQuotes(String name) {
return name.replace("'", "''");
}
}

/**
* Returns if connected to SQL Azure
* @param con
* connection to server
* @return boolean
* @throws SQLException
*/
public static boolean isSqlAzure(Connection con) throws SQLException {
if (_determinedSqlAzureOrSqlServer) {
return _isSqlAzure;
}

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
throw new SQLException(e.toString());
}

boolean ownsCon = false;

if (null == con) {
con = DriverManager.getConnection(AbstractTest.getConnectionString());
ownsCon = true;
}

try (ResultSet rs = con.createStatement().executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') as INT)")) {
rs.next();
int engineEdition = rs.getInt(1);
_determinedSqlAzureOrSqlServer = true;
_isSqlAzure = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE || engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_DW);
if (ownsCon) {
con.close();
}
return _isSqlAzure;
}
}

/**
* Returns if connected to SQL Azure DW
* @param con
* connection to server
* @return boolean
* @throws SQLException
*/
public static boolean isSqlAzureDW(Connection con) throws SQLException {
if (_determinedSqlAzureOrSqlServer) {
return _isSqlAzureDW;
}

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
throw new SQLException(e.toString());
}

boolean ownsCon = false;

if (null == con) {
con = DriverManager.getConnection(AbstractTest.getConnectionString());
ownsCon = true;
}

try (ResultSet rs = con.createStatement().executeQuery("SELECT CAST(SERVERPROPERTY('EngineEdition') as INT)")) {
rs.next();
int engineEdition = rs.getInt(1);
_determinedSqlAzureOrSqlServer = true;
_isSqlAzure = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE || engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_DW);
_isSqlAzureDW = (engineEdition == ENGINE_EDITION_FOR_SQL_AZURE_DW);
if (ownsCon) {
con.close();
}
return _isSqlAzureDW;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ public class BulkCopyAllTypesTest extends AbstractTest {
*/
@Test
public void testTVPResultSet() throws SQLException {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(true, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
if (TestUtils.isSqlAzureDW(connection)) {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
} else {
testBulkCopyResultSet(false, null, null);
testBulkCopyResultSet(true, null, null);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
testBulkCopyResultSet(false, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
}
}

private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetType,
Expand Down
19 changes: 13 additions & 6 deletions src/test/java/com/microsoft/sqlserver/jdbc/bvt/BvtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -15,26 +16,27 @@
import java.util.regex.Pattern;

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.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractTest;
import com.microsoft.sqlserver.testframework.DBConnection;
import com.microsoft.sqlserver.testframework.DBStatement;
import com.microsoft.sqlserver.testframework.DBTable;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.testframework.DBPreparedStatement;
import com.microsoft.sqlserver.testframework.DBResultSet;
import com.microsoft.sqlserver.testframework.DBResultSetTypes;


@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;
Expand Down Expand Up @@ -147,6 +149,7 @@ public void testStmtForwardOnlyReadOnly() throws SQLException, ClassNotFoundExce
*/
@Test
public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFoundException {
assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_INSENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -167,6 +170,7 @@ public void testStmtScrollInsensitiveReadOnly() throws SQLException, ClassNotFou
*/
@Test
public void testStmtScrollSensitiveReadOnly() throws SQLException {
assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_READ_ONLY);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -189,6 +193,7 @@ public void testStmtScrollSensitiveReadOnly() throws SQLException {
*/
@Test
public void testStmtForwardOnlyUpdateable() throws SQLException {
assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_FORWARD_ONLY_CONCUR_UPDATABLE);
DBResultSet rs = stmt.selectAll(table1)) {
Expand Down Expand Up @@ -216,6 +221,7 @@ public void testStmtForwardOnlyUpdateable() throws SQLException {
*/
@Test
public void testStmtScrollSensitiveUpdatable() throws SQLException {
assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_SCROLL_SENSITIVE_CONCUR_UPDATABLE);
DBResultSet rs = stmt.selectAll(table1)) {
Expand All @@ -239,7 +245,7 @@ public void testStmtScrollSensitiveUpdatable() throws SQLException {
*/
@Test
public void testStmtSSScrollDynamicOptimisticCC() throws SQLException {

assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString);
DBStatement stmt = conn.createStatement(DBResultSetTypes.TYPE_DYNAMIC_CONCUR_OPTIMISTIC);
DBResultSet rs = stmt.selectAll(table1)) {
Expand Down Expand Up @@ -412,6 +418,7 @@ public void testResultSetAndCloseStmt() throws SQLException {
*/
@Test
public void testResultSetSelectMethod() throws SQLException {
assumeFalse(TestUtils.isSqlAzureDW(null), "Cursor support is not implemented for Azure DW.");
try (DBConnection conn = new DBConnection(connectionString + ";selectMethod=cursor;");
DBStatement stmt = conn.createStatement(); DBResultSet rs = stmt.selectAll(table1)) {
rs.verify(table1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
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;


@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;
Expand Down Expand Up @@ -165,7 +166,7 @@ public void connectionErrorOccurred(ConnectionEvent event) {
*/
@Test
public void testConnectionEvents() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
assumeTrue(!TestUtils.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));

SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
Expand Down Expand Up @@ -197,7 +198,7 @@ public void testConnectionEvents() throws SQLException {

@Test
public void testConnectionPoolGetTwice() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
assumeTrue(!TestUtils.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));

SQLServerConnectionPoolDataSource mds = new SQLServerConnectionPoolDataSource();
Expand All @@ -211,7 +212,7 @@ public void testConnectionPoolGetTwice() throws SQLException {
try (Connection con = pooledConnection.getConnection();
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) {
// raise a non severe exception and make sure that the connection is not closed.
stmt.executeUpdate("RAISERROR ('foo', 3,1) WITH LOG");
stmt.executeUpdate("RAISERROR ('foo', 3,1)");
// not a serious error there should not be any errors.
assertTrue(!myE.errorOccurred, TestResource.getResource("R_errorCalled"));
// check to make sure that connection is not closed.
Expand All @@ -225,7 +226,7 @@ public void testConnectionPoolGetTwice() throws SQLException {

@Test
public void testConnectionClosed() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
assumeTrue(!TestUtils.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));

SQLServerDataSource mds = new SQLServerDataSource();
Expand Down Expand Up @@ -304,7 +305,7 @@ public void testNegativeTimeout() throws Exception {

@Test
public void testDeadConnection() throws SQLException {
assumeTrue(!DBConnection.isSqlAzure(DriverManager.getConnection(connectionString)),
assumeTrue(!TestUtils.isSqlAzure(DriverManager.getConnection(connectionString)),
TestResource.getResource("R_skipAzure"));

String tableName = RandomUtil.getIdentifier("ConnectionTestTable");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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;
Expand All @@ -27,6 +28,7 @@
*
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class ConnectionWrapper43Test extends AbstractTest {
static Connection connection = null;
double javaVersion = Double.parseDouble(System.getProperty("java.specification.version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -27,6 +28,7 @@
*
*/
@RunWith(JUnitPlatform.class)
@Tag("AzureDWTest")
public class DriverVersionTest extends AbstractTest {
Random rand = new Random();
int major = rand.nextInt(256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand All @@ -29,17 +30,18 @@
import com.microsoft.sqlserver.testframework.AbstractTest;


@RunWith(JUnitPlatform.class)
public class NativeMSSQLDataSourceTest extends AbstractTest {

@Test
@Tag("AzureDWTest")
public void testNativeMSSQLDataSource() throws SQLException {
SQLServerXADataSource ds = new SQLServerXADataSource();
ds.setLastUpdateCount(true);
assertTrue(ds.getLastUpdateCount());
}

@Test
@Tag("AzureDWTest")
public void testSerialization() throws IOException {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutput objectOutput = new ObjectOutputStream(outputStream)) {
Expand All @@ -52,6 +54,7 @@ public void testSerialization() throws IOException {
}

@Test
@Tag("AzureDWTest")
public void testDSNormal() throws ClassNotFoundException, IOException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
Expand All @@ -74,6 +77,7 @@ 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("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
Expand Down
Loading