@@ -333,6 +333,22 @@ public void testEncryptedConnection() throws SQLException {
333
333
try (Connection con = ds .getConnection ()) {}
334
334
}
335
335
336
+ @ Tag (Constants .xSQLv11 )
337
+ @ Tag (Constants .xSQLv12 )
338
+ @ Tag (Constants .xSQLv14 )
339
+ @ Tag (Constants .xSQLv15 )
340
+ @ Tag (Constants .xAzureSQLDW )
341
+ @ Tag (Constants .xAzureSQLDB )
342
+ @ Test
343
+ public void testEncryptedStrictConnection () throws SQLException {
344
+ SQLServerDataSource ds = new SQLServerDataSource ();
345
+ ds .setURL (connectionString );
346
+ ds .setServerCertificate (serverCertificate );
347
+ ds .setEncrypt (Constants .STRICT );
348
+
349
+ try (Connection con = ds .getConnection ()) {}
350
+ }
351
+
336
352
@ Test
337
353
public void testJdbcDataSourceMethod () throws SQLFeatureNotSupportedException {
338
354
SQLServerDataSource fxds = new SQLServerDataSource ();
@@ -936,65 +952,63 @@ public void run() {
936
952
assertTrue (status && future .isCancelled (), TestResource .getResource ("R_threadInterruptNotSet" ));
937
953
}
938
954
955
+ /**
956
+ * Test thread count when finding socket using threading.
957
+ */
958
+ @ Test
959
+ @ Tag (Constants .xAzureSQLDB )
960
+ @ Tag (Constants .xAzureSQLDW )
961
+ public void testThreadCountWhenFindingSocket () {
962
+ ExecutorService executor = null ;
963
+ ManagementFactory .getThreadMXBean ().resetPeakThreadCount ();
964
+
965
+ // First, check to see if there is a reachable local host, or else test will fail.
966
+ try {
967
+ SQLServerDataSource ds = new SQLServerDataSource ();
968
+ ds .setServerName ("localhost" );
969
+ Connection con = ds .getConnection ();
970
+ } catch (SQLServerException e ) {
971
+ // Assume this will be an error different than 'localhost is unreachable'. If it is 'localhost is
972
+ // unreachable' abort and skip the test.
973
+ Assume .assumeFalse (e .getMessage ().startsWith (TestResource .getResource ("R_tcpipConnectionToHost" )));
974
+ }
975
+
976
+ try {
977
+ executor = Executors .newSingleThreadExecutor (r -> new Thread (r , "" ));
978
+ executor .submit (() -> {
979
+ try {
980
+ SQLServerDataSource ds = new SQLServerDataSource ();
981
+ ds .setServerName ("localhost" );
982
+ Thread .sleep (5000 );
983
+ Connection conn2 = ds .getConnection ();
984
+ } catch (Exception e ) {
985
+ if (!(e instanceof SQLServerException )) {
986
+ fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
987
+ }
988
+ }
989
+ });
990
+ SQLServerDataSource ds = new SQLServerDataSource ();
991
+ ds .setServerName ("localhost" );
992
+ Connection conn = ds .getConnection ();
993
+ Thread .sleep (5000 );
994
+ } catch (Exception e ) {
995
+ if (!(e instanceof SQLServerException )) {
996
+ fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
997
+ }
998
+ } finally {
999
+ if (executor != null ) {
1000
+ executor .shutdown ();
1001
+ }
1002
+ }
1003
+
1004
+ // At this point, thread count has returned to normal. If the peak was more
1005
+ // than 2 times the current, this is an issue and the test should fail.
1006
+ if (ManagementFactory .getThreadMXBean ().getPeakThreadCount () > 2
1007
+ * ManagementFactory .getThreadMXBean ().getThreadCount ()) {
1008
+ fail (TestResource .getResource ("R_unexpectedThreadCount" ));
1009
+ }
1010
+ }
939
1011
940
- /**
941
- * Test thread count when finding socket using threading.
942
- */
943
- @ Test
944
- @ Tag (Constants .xAzureSQLDB )
945
- @ Tag (Constants .xAzureSQLDW )
946
- public void testThreadCountWhenFindingSocket () {
947
- ExecutorService executor = null ;
948
- ManagementFactory .getThreadMXBean ().resetPeakThreadCount ();
949
-
950
- // First, check to see if there is a reachable local host, or else test will fail.
951
- try {
952
- SQLServerDataSource ds = new SQLServerDataSource ();
953
- ds .setServerName ("localhost" );
954
- Connection con = ds .getConnection ();
955
- } catch (SQLServerException e ) {
956
- // Assume this will be an error different than 'localhost is unreachable'. If it is 'localhost is
957
- // unreachable' abort and skip the test.
958
- Assume .assumeFalse (e .getMessage ().startsWith (TestResource .getResource ("R_tcpipConnectionToHost" )));
959
- }
960
-
961
- try {
962
- executor = Executors .newSingleThreadExecutor (r -> new Thread (r , "" ));
963
- executor .submit (() -> {
964
- try {
965
- SQLServerDataSource ds = new SQLServerDataSource ();
966
- ds .setServerName ("localhost" );
967
- Thread .sleep (5000 );
968
- Connection conn2 = ds .getConnection ();
969
- } catch (Exception e ) {
970
- if (!(e instanceof SQLServerException )) {
971
- fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
972
- }
973
- }
974
- });
975
- SQLServerDataSource ds = new SQLServerDataSource ();
976
- ds .setServerName ("localhost" );
977
- Connection conn = ds .getConnection ();
978
- Thread .sleep (5000 );
979
- } catch (Exception e ) {
980
- if (!(e instanceof SQLServerException )) {
981
- fail (TestResource .getResource ("R_unexpectedException" ) + e .getMessage ());
982
- }
983
- } finally {
984
- if (executor != null ) {
985
- executor .shutdown ();
986
- }
987
- }
988
-
989
- // At this point, thread count has returned to normal. If the peak was more
990
- // than 2 times the current, this is an issue and the test should fail.
991
- if (ManagementFactory .getThreadMXBean ().getPeakThreadCount ()
992
- > 2 * ManagementFactory .getThreadMXBean ().getThreadCount ()) {
993
- fail (TestResource .getResource ("R_unexpectedThreadCount" ));
994
- }
995
- }
996
-
997
-
998
1012
/**
999
1013
* Test calling method to get redirected server string.
1000
1014
*/
0 commit comments