use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testInvalidCombination.
@Test
public void testInvalidCombination() throws SQLException {
long timerStart = 0;
long timerEnd = 0;
Connection con = null;
final long milsecs = threshHoldForNoRetryInMilliseconds;
try {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setLoginTimeout(loginTimeOutInSeconds);
ds.setMultiSubnetFailover(true);
ds.setFailoverPartner(RandomUtil.getIdentifier("FailoverPartner"));
timerStart = System.currentTimeMillis();
con = ds.getConnection();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Connecting to a mirrored"));
timerEnd = System.currentTimeMillis();
}
long timeDiff = timerEnd - timerStart;
assertTrue(con == null, "Should not have connected.");
assertTrue(timeDiff <= milsecs, "Exited in more than " + (milsecs / 1000) + " seconds.");
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class StatementCancellationTest method setMultiSubnetFailoverToTrue.
/**
* Tests Statement Cancellation works when MultiSubnetFailover is set to true
*/
@Test
public void setMultiSubnetFailoverToTrue() throws SQLException {
long timeStart = 0;
long timeEnd = 0;
try {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setMultiSubnetFailover(true);
try (Connection conn = ds.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
final Thread cancellationThread = new Thread() {
public void run() {
try {
Thread.sleep(CANCEL_WAIT_MILLISECONDS);
stmt.cancel();
} catch (Exception e) {
e.printStackTrace();
}
}
};
cancellationThread.setName("stmtCancel");
cancellationThread.start();
try {
timeStart = System.currentTimeMillis();
stmt.execute("WAITFOR DELAY '00:00:" + (DELAY_WAIT_MILLISECONDS / 1000) + "'");
} catch (SQLException e) {
assertTrue(e.getMessage().startsWith("The query was canceled"), "Unexpected error message.");
}
}
}
} finally {
timeEnd = System.currentTimeMillis();
long timeDifference = timeEnd - timeStart;
assertTrue(timeDifference >= CANCEL_WAIT_MILLISECONDS, "Cancellation failed.");
assertTrue(timeDifference < DELAY_WAIT_MILLISECONDS, "Cancellation failed.");
assertTrue((timeDifference - CANCEL_WAIT_MILLISECONDS) < 1000, "Cancellation failed.");
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class CallableStatementTest method getSetNullWithTypeVarchar.
/**
* test for setNull(index, varchar) to behave as setNull(index, nvarchar) when SendStringParametersAsUnicode is true
*
* @throws SQLException
*/
@Test
public void getSetNullWithTypeVarchar() throws SQLException {
String polishchar = "\u0143";
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setSendStringParametersAsUnicode(true);
String sql = "{? = call " + setNullProcedureName + " (?,?)}";
try (Connection connection = ds.getConnection();
SQLServerCallableStatement cs = (SQLServerCallableStatement) connection.prepareCall(sql);
SQLServerCallableStatement cs2 = (SQLServerCallableStatement) connection.prepareCall(sql)) {
cs.registerOutParameter(1, Types.INTEGER);
cs.setString(2, polishchar);
cs.setString(3, null);
cs.registerOutParameter(3, Types.VARCHAR);
cs.execute();
String expected = cs.getString(3);
cs2.registerOutParameter(1, Types.INTEGER);
cs2.setString(2, polishchar);
cs2.setNull(3, Types.VARCHAR);
cs2.registerOutParameter(3, Types.NVARCHAR);
cs2.execute();
String actual = cs2.getString(3);
assertEquals(expected, actual);
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class NativeMSSQLDataSourceTest method testDSNormal.
@Test
public void testDSNormal() throws ClassNotFoundException, IOException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
try (Connection conn = ds.getConnection()) {
}
ds = testSerial(ds);
try (Connection conn = ds.getConnection()) {
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class NativeMSSQLDataSourceTest method testInterfaceWrapping.
@Test
public void testInterfaceWrapping() throws ClassNotFoundException, SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
assertEquals(true, ds.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, ds.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, ds.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids = (ISQLServerDataSource) (ds.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids.setApplicationName("AppName");
SQLServerConnectionPoolDataSource poolDS = new SQLServerConnectionPoolDataSource();
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource")));
assertEquals(true, poolDS.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids2 = (ISQLServerDataSource) (poolDS.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids2.setApplicationName("AppName");
SQLServerXADataSource xaDS = new SQLServerXADataSource();
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource")));
assertEquals(true, xaDS.isWrapperFor(Class.forName("javax.sql.CommonDataSource")));
ISQLServerDataSource ids3 = (ISQLServerDataSource) (xaDS.unwrap(Class.forName("com.microsoft.sqlserver.jdbc.ISQLServerDataSource")));
ids3.setApplicationName("AppName");
}
Aggregations