use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testIncorrectDatabase.
@Test
public void testIncorrectDatabase() 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.setDatabaseName(RandomUtil.getIdentifier("DataBase"));
timerStart = System.currentTimeMillis();
con = ds.getConnection();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Cannot open database"));
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 ConnectionDriverTest method testJdbcDataSourceMethod.
@Test
public void testJdbcDataSourceMethod() throws SQLFeatureNotSupportedException {
SQLServerDataSource fxds = new SQLServerDataSource();
Logger logger = fxds.getParentLogger();
assertEquals(logger.getName(), "com.microsoft.sqlserver.jdbc", "Parent Logger name is wrong");
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testIncorrectUserName.
@Test
public void testIncorrectUserName() 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.setUser(RandomUtil.getIdentifier("User"));
timerStart = System.currentTimeMillis();
con = ds.getConnection();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Login failed"));
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 ConnectionDriverTest method testIncorrectDatabaseWithFailoverPartner.
@Test
@Tag("slow")
public void testIncorrectDatabaseWithFailoverPartner() throws SQLException {
long timerStart = 0;
long timerEnd = 0;
Connection con = null;
try {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
ds.setLoginTimeout(loginTimeOutInSeconds);
ds.setDatabaseName(RandomUtil.getIdentifierForDB("DB"));
ds.setFailoverPartner(RandomUtil.getIdentifier("FailoverPartner"));
timerStart = System.currentTimeMillis();
con = ds.getConnection();
} catch (Exception e) {
timerEnd = System.currentTimeMillis();
}
long timeDiff = timerEnd - timerStart;
assertTrue(con == null, "Should not have connected.");
assertTrue(timeDiff >= ((loginTimeOutInSeconds - 1) * 1000), "Exited in less than " + (loginTimeOutInSeconds - 1) + " seconds.");
}
use of com.microsoft.sqlserver.jdbc.SQLServerDataSource in project mssql-jdbc by Microsoft.
the class ConnectionDriverTest method testEncryptedConnection.
@Test
public void testEncryptedConnection() throws SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setApplicationName("User");
ds.setURL(connectionString);
ds.setEncrypt(true);
ds.setTrustServerCertificate(true);
ds.setPacketSize(8192);
try (Connection con = ds.getConnection()) {
}
}
Aggregations