@@ -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 = 15 ; // loginTimeout default value
42
+ static final int defaultTimeout = 60 ; // 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 ();
58
59
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
59
60
|| ((isSqlAzure () || isSqlAzureDW ())
60
61
? e .getMessage ().contains (
61
62
TestResource .getResource ("R_connectTimedOut" ))
62
63
: false ),
63
64
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 ();
80
81
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
81
82
|| ((isSqlAzure () || isSqlAzureDW ())
82
83
? e .getMessage ().contains (
83
84
TestResource .getResource ("R_connectTimedOut" ))
84
85
: false ),
85
86
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 ();
103
104
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
104
105
|| ((isSqlAzure () || isSqlAzureDW ())
105
106
? e .getMessage ().contains (
106
107
TestResource .getResource ("R_connectTimedOut" ))
107
108
: false ),
108
109
e .getMessage ());
109
- timerEnd = System .currentTimeMillis ();
110
110
}
111
111
112
112
verifyTimeout (timerEnd - timerStart , timeout );
@@ -124,6 +124,7 @@ 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 ();
127
128
assertTrue (
128
129
(e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
129
130
|| ((isSqlAzure () || isSqlAzureDW ())
@@ -132,7 +133,6 @@ public void testDMLoginTimeoutNotApplied() {
132
133
.getResource ("R_connectTimedOut" ))
133
134
: false ),
134
135
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 ();
155
156
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
156
157
|| ((isSqlAzure () || isSqlAzureDW ())
157
158
? e .getMessage ().contains (
158
159
TestResource .getResource ("R_connectTimedOut" ))
159
160
: false ),
160
161
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 ();
182
183
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
183
184
|| ((isSqlAzure () || isSqlAzureDW ())
184
185
? e .getMessage ().contains (
185
186
TestResource .getResource ("R_connectTimedOut" ))
186
187
: false ),
187
188
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 ();
214
215
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
215
216
|| ((isSqlAzure () || isSqlAzureDW ())
216
217
? e .getMessage ().contains (
217
218
TestResource .getResource ("R_connectTimedOut" ))
218
219
: false ),
219
220
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
- long timerStart = System .currentTimeMillis ();
232
231
int loginTimeout = 2 ;
232
+ long timerStart = System .currentTimeMillis ();
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 ();
241
242
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_cannotOpenDatabase" )))
242
243
|| ((isSqlAzure () || isSqlAzureDW ())
243
244
? e .getMessage ().contains (
244
245
TestResource .getResource ("R_connectTimedOut" ))
245
246
: false ),
246
247
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 ();
263
264
assertTrue ((e .getMessage ().contains (TestResource .getResource ("R_tcpipConnectionToHost" )))
264
265
|| ((isSqlAzure () || isSqlAzureDW ())
265
266
? e .getMessage ().contains (
266
267
TestResource .getResource ("R_connectTimedOut" ))
267
268
: false ),
268
269
e .getMessage ());
269
- timerEnd = System .currentTimeMillis ();
270
270
}
271
271
272
272
verifyTimeout (timerEnd - timerStart , defaultTimeout * 2 );
0 commit comments