From f8b33e18a29c48ef52e8a85a9c408663cf5a1aff Mon Sep 17 00:00:00 2001 From: Jeff Wasty Date: Wed, 18 Sep 2024 19:23:54 -0700 Subject: [PATCH] More cleanup --- .../sqlserver/jdbc/SQLServerConnection.java | 1 - .../sqlserver/jdbc/SQLServerConnectionTest.java | 7 +++---- .../sqlserver/jdbc/connection/TimeoutTest.java | 13 +++++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 73d38bf57..99d80d526 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -2002,7 +2002,6 @@ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnectio } throw e; } else { - // only retry if transient error SQLServerError sqlServerError = e.getSQLServerError(); if (!TransientError.isTransientError(sqlServerError)) { diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java index 2cb984be0..4061035a7 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java @@ -5,10 +5,9 @@ package com.microsoft.sqlserver.jdbc; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.io.Reader; @@ -194,7 +193,7 @@ public void testDataSource() throws SQLServerException { assertEquals("False", EncryptOption.valueOfString(ds.getEncrypt()).toString(), TestResource.getResource("R_valuesAreDifferent")); - // verify encrypt=strict options + // verify enrypt=strict options ds.setEncrypt(EncryptOption.STRICT.toString()); assertEquals("Strict", EncryptOption.valueOfString(ds.getEncrypt()).toString(), TestResource.getResource("R_valuesAreDifferent")); @@ -486,7 +485,7 @@ private void testConnectCountInLoginAndCorrectRetryCount(int connectRetryCount) timerStart = System.currentTimeMillis(); try (Connection con = ds.getConnection()) { - assertNull(con, TestResource.getResource("R_shouldNotConnect")); + assertTrue(con == null, TestResource.getResource("R_shouldNotConnect")); } } catch (Exception e) { assertTrue( 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 0007123bb..d7290b262 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java @@ -49,11 +49,8 @@ public static void setupTests() throws Exception { /* * TODO: * The tests below uses a simple interval counting logic to determine whether there was at least 1 retry. - * Given the interval is long enough, then 1 retry should take at least 1 interval long, so if it took < 1 interval, - * then it assumes there were no retry. However, this only works if TNIR or failover is not enabled since those cases - * should retry but no wait interval in between. So this interval counting can not detect these cases. - * Note a better and more reliable way would be to check attemptNumber using reflection to - * determine the number of retries. + * Given the interval is long enough, then 1 retry should take at least 1 interval long, so if it took < 1 interval, then it assumes there were no retry. However, this only works if TNIR or failover is not enabled since those cases should retry but no wait interval in between. So this interval counting can not detect these cases. + * Note a better and more reliable way would be to check attemptNumber using reflection to determine the number of retries. */ // test default loginTimeout used if not specified in connection string @@ -80,7 +77,7 @@ public void testDefaultLoginTimeout() { // time should be < default loginTimeout assertTrue(totalTime < TimeUnit.SECONDS.toMillis(defaultTimeout), - "total time: " + totalTime + " default logintimeout: " + TimeUnit.SECONDS.toMillis(defaultTimeout)); + "total time: " + totalTime + " default loginTimout: " + TimeUnit.SECONDS.toMillis(defaultTimeout)); } // test setting loginTimeout value @@ -92,7 +89,7 @@ public void testURLLoginTimeout() { long timerStart = System.currentTimeMillis(); // non existing server and set loginTimeout - try (Connection con = PrepUtil.getConnection("jdbc:sqlserver://" + randomServer + ";loginTimout=" + timeout)) { + try (Connection con = PrepUtil.getConnection("jdbc:sqlserver://" + randomServer + ";logintimeout=" + timeout)) { fail(TestResource.getResource("R_shouldNotConnect")); } catch (Exception e) { totalTime = System.currentTimeMillis() - timerStart; @@ -205,7 +202,7 @@ public void testConnectRetryDisable() { "total time: " + totalTime + " interval: " + TimeUnit.SECONDS.toMillis(interval)); } - // Test connect retry for non existent server with loginTimeout + // Test connect retry for non-existent server with loginTimeout @Test public void testConnectRetryBadServer() { long totalTime = 0;