9
9
import static org .junit .jupiter .api .Assertions .fail ;
10
10
11
11
import java .sql .Connection ;
12
+ import java .sql .DriverManager ;
12
13
import java .sql .SQLException ;
13
14
import java .sql .Statement ;
14
15
@@ -53,6 +54,59 @@ public void testDefaultLoginTimeout() {
53
54
54
55
long timeDiff = timerEnd - timerStart ;
55
56
assertTrue (timeDiff > 14000 );
57
+ // Verify that login timeout does not default to max value of 60 seconds
58
+ assertTrue (timeDiff < 30000 );
59
+ }
60
+
61
+ @ Test
62
+ public void testURLLoginTimeout () {
63
+ long timerStart = 0 ;
64
+ long timerEnd = 0 ;
65
+
66
+ timerStart = System .currentTimeMillis ();
67
+
68
+ try (Connection con = PrepUtil
69
+ .getConnection ("jdbc:sqlserver://" + randomServer + ";user=sa;password=pwd;logintimeout=5" )) {
70
+
71
+ } catch (Exception e ) {
72
+ assertTrue (e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )));
73
+ timerEnd = System .currentTimeMillis ();
74
+ }
75
+
76
+ assertTrue (0 != timerEnd , TestResource .getResource ("R_shouldNotConnect" ));
77
+
78
+ long timeDiff = timerEnd - timerStart ;
79
+ assertTrue (timeDiff > 4000 );
80
+
81
+ // Verify that login timeout does not default to default value of 15 seconds
82
+ assertTrue (timeDiff < 10000 );
83
+ }
84
+
85
+ @ Test
86
+ public void testGlobalLoginTimeout () {
87
+ long timerStart = 0 ;
88
+ long timerEnd = 0 ;
89
+ DriverManager .setLoginTimeout (30 );
90
+ timerStart = System .currentTimeMillis ();
91
+
92
+ try (Connection con = PrepUtil
93
+ .getConnection ("jdbc:sqlserver://" + randomServer + ";user=sa;password=pwd;logintimeout=60" )) {
94
+
95
+ } catch (Exception e ) {
96
+ assertTrue (e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )));
97
+ timerEnd = System .currentTimeMillis ();
98
+ }
99
+
100
+ assertTrue (0 != timerEnd , TestResource .getResource ("R_shouldNotConnect" ));
101
+
102
+ long timeDiff = timerEnd - timerStart ;
103
+
104
+ // Verify that login timeout is not set to default value of 15 seconds
105
+ assertTrue (timeDiff > 29000 );
106
+
107
+ // Verify that login timeout does not get set to URL provided value of 60 seconds
108
+ assertTrue (timeDiff < 40000 );
109
+ DriverManager .setLoginTimeout (0 );
56
110
}
57
111
58
112
@ Test
@@ -62,9 +116,9 @@ public void testFailoverInstanceResolution() throws SQLException {
62
116
63
117
timerStart = System .currentTimeMillis ();
64
118
// Try a non existing server and see if the default timeout is 15 seconds
65
- try (Connection con = PrepUtil
66
- . getConnection ( "jdbc:sqlserver:// " + randomServer + ";databaseName=FailoverDB_abc;failoverPartner="
67
- + randomServer + " \\ foo;user=sa;password=pwd;" )) { } catch (Exception e ) {
119
+ try (Connection con = PrepUtil . getConnection ( "jdbc:sqlserver://" + randomServer
120
+ + ";databaseName=FailoverDB_abc;failoverPartner= " + randomServer + "\\ foo;user=sa;password=pwd;" )) {
121
+ } catch (Exception e ) {
68
122
assertTrue (e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )));
69
123
timerEnd = System .currentTimeMillis ();
70
124
}
@@ -80,9 +134,9 @@ public void testFOInstanceResolution2() throws SQLException {
80
134
long timerEnd = 0 ;
81
135
82
136
timerStart = System .currentTimeMillis ();
83
- try (Connection con = PrepUtil
84
- . getConnection ( "jdbc:sqlserver:// " + randomServer + "\\ fooggg;databaseName=FailoverDB;failoverPartner="
85
- + randomServer + " \\ foo;user=sa;password=pwd;" )) { } catch (Exception e ) {
137
+ try (Connection con = PrepUtil . getConnection ( "jdbc:sqlserver://" + randomServer
138
+ + " \\ fooggg;databaseName=FailoverDB;failoverPartner= " + randomServer + "\\ foo;user=sa;password=pwd;" )) {
139
+ } catch (Exception e ) {
86
140
timerEnd = System .currentTimeMillis ();
87
141
}
88
142
assertTrue (0 != timerEnd , TestResource .getResource ("R_shouldNotConnect" ));
0 commit comments