@@ -39,7 +39,7 @@ public class TimeoutTest extends AbstractTest {
39
39
static String randomServer = RandomUtil .getIdentifier ("Server" );
40
40
static String waitForDelaySPName = RandomUtil .getIdentifier ("waitForDelaySP" );
41
41
static final int waitForDelaySeconds = 10 ;
42
- static final int defaultTimeout = 60 ; // loginTimeout default value
42
+ static final int defaultTimeout = 15 ; // loginTimeout default value
43
43
44
44
@ BeforeAll
45
45
public static void setupTests () throws Exception {
@@ -55,13 +55,13 @@ public void testDefaultLoginTimeout() {
55
55
try (Connection con = PrepUtil .getConnection ("jdbc:sqlserver://" + randomServer + "connectRetryCount=0" )) {
56
56
fail (TestResource .getResource ("R_shouldNotConnect" ));
57
57
} catch (Exception e ) {
58
- timerEnd = System .currentTimeMillis ();
59
58
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
60
59
|| ((isSqlAzure () || isSqlAzureDW ())
61
60
? e .getMessage ().contains (
62
61
TestResource .getResource ("R_connectTimedOut" ))
63
62
: false ),
64
63
e .getMessage ());
64
+ timerEnd = System .currentTimeMillis ();
65
65
}
66
66
67
67
verifyTimeout (timerEnd - timerStart , defaultTimeout );
@@ -77,13 +77,13 @@ public void testURLLoginTimeout() {
77
77
try (Connection con = PrepUtil .getConnection ("jdbc:sqlserver://" + randomServer + ";logintimeout=" + timeout )) {
78
78
fail (TestResource .getResource ("R_shouldNotConnect" ));
79
79
} catch (Exception e ) {
80
- timerEnd = System .currentTimeMillis ();
81
80
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
82
81
|| ((isSqlAzure () || isSqlAzureDW ())
83
82
? e .getMessage ().contains (
84
83
TestResource .getResource ("R_connectTimedOut" ))
85
84
: false ),
86
85
e .getMessage ());
86
+ timerEnd = System .currentTimeMillis ();
87
87
}
88
88
89
89
verifyTimeout (timerEnd - timerStart , timeout );
@@ -100,13 +100,13 @@ public void testDMLoginTimeoutApplied() {
100
100
try (Connection con = PrepUtil .getConnection ("jdbc:sqlserver://" + randomServer )) {
101
101
fail (TestResource .getResource ("R_shouldNotConnect" ));
102
102
} catch (Exception e ) {
103
- timerEnd = System .currentTimeMillis ();
104
103
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
105
104
|| ((isSqlAzure () || isSqlAzureDW ())
106
105
? e .getMessage ().contains (
107
106
TestResource .getResource ("R_connectTimedOut" ))
108
107
: false ),
109
108
e .getMessage ());
109
+ timerEnd = System .currentTimeMillis ();
110
110
}
111
111
112
112
verifyTimeout (timerEnd - timerStart , timeout );
@@ -124,7 +124,6 @@ public void testDMLoginTimeoutNotApplied() {
124
124
.getConnection ("jdbc:sqlserver://" + randomServer + ";loginTimeout=" + timeout )) {
125
125
fail (TestResource .getResource ("R_shouldNotConnect" ));
126
126
} catch (Exception e ) {
127
- timerEnd = System .currentTimeMillis ();
128
127
assertTrue (
129
128
(e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
130
129
|| ((isSqlAzure () || isSqlAzureDW ())
@@ -133,6 +132,7 @@ public void testDMLoginTimeoutNotApplied() {
133
132
.getResource ("R_connectTimedOut" ))
134
133
: false ),
135
134
e .getMessage ());
135
+ timerEnd = System .currentTimeMillis ();
136
136
}
137
137
verifyTimeout (timerEnd - timerStart , timeout );
138
138
} finally {
@@ -152,13 +152,13 @@ public void testConnectRetryBadServer() {
152
152
.getConnection ("jdbc:sqlserver://" + randomServer + ";loginTimeout=" + loginTimeout )) {
153
153
fail (TestResource .getResource ("R_shouldNotConnect" ));
154
154
} catch (Exception e ) {
155
- timerEnd = System .currentTimeMillis ();
156
155
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
157
156
|| ((isSqlAzure () || isSqlAzureDW ())
158
157
? e .getMessage ().contains (
159
158
TestResource .getResource ("R_connectTimedOut" ))
160
159
: false ),
161
160
e .getMessage ());
161
+ timerEnd = System .currentTimeMillis ();
162
162
}
163
163
164
164
verifyTimeout (timerEnd - timerStart , loginTimeout );
@@ -179,13 +179,13 @@ public void testConnectRetryServerError() {
179
179
+ ";connectRetryInterval=" + connectRetryInterval )) {
180
180
fail (TestResource .getResource ("R_shouldNotConnect" ));
181
181
} catch (Exception e ) {
182
- timerEnd = System .currentTimeMillis ();
183
182
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
184
183
|| ((isSqlAzure () || isSqlAzureDW ())
185
184
? e .getMessage ().contains (
186
185
TestResource .getResource ("R_connectTimedOut" ))
187
186
: false ),
188
187
e .getMessage ());
188
+ timerEnd = System .currentTimeMillis ();
189
189
}
190
190
191
191
// connect + all retries should always be <= loginTimeout
@@ -211,13 +211,13 @@ public void testConnectRetryServerErrorDS() {
211
211
try (Connection con = PrepUtil .getConnection (connectStr )) {
212
212
fail (TestResource .getResource ("R_shouldNotConnect" ));
213
213
} catch (Exception e ) {
214
- timerEnd = System .currentTimeMillis ();
215
214
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
216
215
|| ((isSqlAzure () || isSqlAzureDW ())
217
216
? e .getMessage ().contains (
218
217
TestResource .getResource ("R_connectTimedOut" ))
219
218
: false ),
220
219
e .getMessage ());
220
+ timerEnd = System .currentTimeMillis ();
221
221
}
222
222
223
223
// connect + all retries should always be <= loginTimeout
@@ -228,8 +228,8 @@ public void testConnectRetryServerErrorDS() {
228
228
@ Test
229
229
public void testConnectRetryTimeout () {
230
230
long timerEnd = 0 ;
231
- int loginTimeout = 2 ;
232
231
long timerStart = System .currentTimeMillis ();
232
+ int loginTimeout = 2 ;
233
233
234
234
// non existent server with very short loginTimeout so there is no time to do all retries
235
235
try (Connection con = PrepUtil .getConnection (
@@ -238,13 +238,13 @@ public void testConnectRetryTimeout() {
238
238
+ (new Random ().nextInt (defaultTimeout - 1 ) + 1 ) + ";loginTimeout=" + loginTimeout )) {
239
239
fail (TestResource .getResource ("R_shouldNotConnect" ));
240
240
} catch (Exception e ) {
241
- timerEnd = System .currentTimeMillis ();
242
241
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
243
242
|| ((isSqlAzure () || isSqlAzureDW ())
244
243
? e .getMessage ().contains (
245
244
TestResource .getResource ("R_connectTimedOut" ))
246
245
: false ),
247
246
e .getMessage ());
247
+ timerEnd = System .currentTimeMillis ();
248
248
}
249
249
250
250
verifyTimeout (timerEnd - timerStart , loginTimeout );
@@ -260,13 +260,13 @@ public void testFailoverInstanceResolution() throws SQLException {
260
260
+ ";databaseName=FailoverDB_abc;failoverPartner=" + randomServer + "\\ foo;user=sa;password=pwd;" )) {
261
261
fail (TestResource .getResource ("R_shouldNotConnect" ));
262
262
} catch (Exception e ) {
263
- timerEnd = System .currentTimeMillis ();
264
263
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
265
264
|| ((isSqlAzure () || isSqlAzureDW ())
266
265
? e .getMessage ().contains (
267
266
TestResource .getResource ("R_connectTimedOut" ))
268
267
: false ),
269
268
e .getMessage ());
269
+ timerEnd = System .currentTimeMillis ();
270
270
}
271
271
272
272
verifyTimeout (timerEnd - timerStart , defaultTimeout * 2 );
0 commit comments