Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79016a7

Browse files
committed
Re-enable most of AuthTimeoutTest tests
1 parentdd0775e commit79016a7

File tree

1 file changed

+54
-64
lines changed

1 file changed

+54
-64
lines changed

‎client/src/test/java/org/asynchttpclient/AuthTimeoutTest.java‎

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
importstaticjava.nio.charset.StandardCharsets.UTF_8;
1717
importstaticorg.asynchttpclient.Dsl.*;
1818
importstaticorg.asynchttpclient.test.TestUtils.*;
19-
importstaticorg.testng.Assert.*;
2019

2120
importjava.io.IOException;
2221
importjava.io.OutputStream;
2322
importjava.util.concurrent.Future;
2423
importjava.util.concurrent.TimeUnit;
24+
importjava.util.concurrent.TimeoutException;
2525

2626
importjavax.servlet.ServletException;
2727
importjavax.servlet.http.HttpServletRequest;
2828
importjavax.servlet.http.HttpServletResponse;
2929

30-
importorg.asynchttpclient.exception.RemotelyClosedException;
3130
importorg.eclipse.jetty.server.Request;
3231
importorg.eclipse.jetty.server.Server;
3332
importorg.eclipse.jetty.server.ServerConnector;
@@ -38,6 +37,10 @@
3837

3938
publicclassAuthTimeoutTestextendsAbstractBasicTest {
4039

40+
privatestaticfinalintREQUEST_TIMEOUT =1000;
41+
privatestaticfinalintSHORT_FUTURE_TIMEOUT =500;// shorter than REQUEST_TIMEOUT
42+
privatestaticfinalintLONG_FUTURE_TIMEOUT =1500;// longer than REQUEST_TIMEOUT
43+
4144
privateServerserver2;
4245

4346
@BeforeClass(alwaysRun =true)
@@ -83,115 +86,102 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR
8386
}
8487
}
8588

86-
@Test(groups ="standalone",enabled =false)
87-
publicvoidbasicAuthTimeoutTest()throwsException {
89+
@Test(expectedExceptions =TimeoutException.class)
90+
publicvoidbasicAuthTimeoutTest()throwsThrowable {
8891
try (AsyncHttpClientclient =newClient()) {
89-
Future<Response>f =execute(client,server,false);
90-
f.get();
91-
fail("expected timeout");
92+
execute(client,true,false).get(LONG_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
9293
}catch (Exceptione) {
93-
inspectException(e);
94+
throwe.getCause();
9495
}
9596
}
9697

97-
@Test(groups ="standalone",enabled =false)
98-
publicvoidbasicPreemptiveAuthTimeoutTest()throwsException {
98+
@Test(expectedExceptions =TimeoutException.class)
99+
publicvoidbasicPreemptiveAuthTimeoutTest()throwsThrowable {
99100
try (AsyncHttpClientclient =newClient()) {
100-
Future<Response>f =execute(client,server,true);
101-
f.get();
102-
fail("expected timeout");
101+
execute(client,true,true).get(LONG_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
103102
}catch (Exceptione) {
104-
inspectException(e);
103+
throwe.getCause();
105104
}
106105
}
107106

108-
@Test(groups ="standalone",enabled =false)
109-
publicvoiddigestAuthTimeoutTest()throwsException {
107+
@Test(expectedExceptions =TimeoutException.class)
108+
publicvoiddigestAuthTimeoutTest()throwsThrowable {
110109
try (AsyncHttpClientclient =newClient()) {
111-
Future<Response>f =execute(client,server2,false);
112-
f.get();
113-
fail("expected timeout");
110+
execute(client,false,false).get(LONG_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
114111
}catch (Exceptione) {
115-
inspectException(e);
112+
throwe.getCause();
116113
}
117114
}
118115

119-
@Test(groups ="standalone",enabled =false)
120-
publicvoiddigestPreemptiveAuthTimeoutTest()throwsException {
116+
@Test(expectedExceptions =TimeoutException.class,enabled =false)
117+
publicvoiddigestPreemptiveAuthTimeoutTest()throwsThrowable {
121118
try (AsyncHttpClientclient =newClient()) {
122-
Future<Response>f =execute(client,server2,true);
123-
f.get();
124-
fail("expected timeout");
119+
execute(client,false,true).get(LONG_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
125120
}catch (Exceptione) {
126-
inspectException(e);
121+
throwe.getCause();
127122
}
128123
}
129124

130-
@Test(groups ="standalone",enabled =false)
131-
publicvoidbasicFutureAuthTimeoutTest()throwsException {
125+
@Test(expectedExceptions =TimeoutException.class)
126+
publicvoidbasicAuthFutureTimeoutTest()throwsThrowable {
132127
try (AsyncHttpClientclient =newClient()) {
133-
Future<Response>f =execute(client,server,false);
134-
f.get(1,TimeUnit.SECONDS);
135-
fail("expected timeout");
136-
}catch (Exceptione) {
137-
inspectException(e);
128+
execute(client,true,false).get(SHORT_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
138129
}
139130
}
140131

141-
@Test(groups ="standalone",enabled =false)
142-
publicvoidbasicFuturePreemptiveAuthTimeoutTest()throwsException {
132+
@Test(expectedExceptions =TimeoutException.class)
133+
publicvoidbasicPreemptiveAuthFutureTimeoutTest()throwsThrowable {
143134
try (AsyncHttpClientclient =newClient()) {
144-
Future<Response>f =execute(client,server,true);
145-
f.get(1,TimeUnit.SECONDS);
146-
fail("expected timeout");
147-
}catch (Exceptione) {
148-
inspectException(e);
135+
execute(client,true,true).get(SHORT_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
149136
}
150137
}
151138

152-
@Test(groups ="standalone",enabled =false)
153-
publicvoiddigestFutureAuthTimeoutTest()throwsException {
139+
@Test(expectedExceptions =TimeoutException.class)
140+
publicvoiddigestAuthFutureTimeoutTest()throwsThrowable {
154141
try (AsyncHttpClientclient =newClient()) {
155-
Future<Response>f =execute(client,server2,false);
156-
f.get(1,TimeUnit.SECONDS);
157-
fail("expected timeout");
158-
}catch (Exceptione) {
159-
inspectException(e);
142+
execute(client,false,false).get(SHORT_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
160143
}
161144
}
162145

163-
@Test(groups ="standalone",enabled =false)
164-
publicvoiddigestFuturePreemptiveAuthTimeoutTest()throwsException {
146+
@Test(expectedExceptions =TimeoutException.class,enabled =false)
147+
publicvoiddigestPreemptiveAuthFutureTimeoutTest()throwsThrowable {
165148
try (AsyncHttpClientclient =newClient()) {
166-
Future<Response>f =execute(client,server2,true);
167-
f.get(1,TimeUnit.SECONDS);
168-
fail("expected timeout");
169-
}catch (Exceptione) {
170-
inspectException(e);
149+
execute(client,false,true).get(SHORT_FUTURE_TIMEOUT,TimeUnit.MILLISECONDS);
171150
}
172151
}
173152

174-
protectedvoidinspectException(Throwablet) {
175-
assertEquals(t.getCause(),RemotelyClosedException.INSTANCE);
176-
}
177-
178153
privateAsyncHttpClientnewClient() {
179-
returnasyncHttpClient(config().setPooledConnectionIdleTimeout(2000).setConnectTimeout(20000).setRequestTimeout(2000));
154+
returnasyncHttpClient(config().setRequestTimeout(REQUEST_TIMEOUT));
180155
}
181156

182-
protectedFuture<Response>execute(AsyncHttpClientclient,Serverserver,booleanpreemptive)throwsIOException {
183-
returnclient.prepareGet(getTargetUrl()).setRealm(realm(preemptive)).setHeader("X-Content","Test").execute();
184-
}
157+
protectedFuture<Response>execute(AsyncHttpClientclient,booleanbasic,booleanpreemptive)throwsIOException {
158+
Realm.Builderrealm;
159+
Stringurl;
160+
161+
if (basic) {
162+
realm =basicAuthRealm(USER,ADMIN);
163+
url =getTargetUrl();
164+
}else {
165+
realm =digestAuthRealm(USER,ADMIN);
166+
url =getTargetUrl2();
167+
if (preemptive) {
168+
realm.setNonce("fFDVc60re9zt8fFDvht0tNrYuvqrcchN");
169+
}
170+
}
185171

186-
privateRealmrealm(booleanpreemptive) {
187-
returnbasicAuthRealm(USER,ADMIN).setUsePreemptiveAuth(preemptive).build();
172+
returnclient.prepareGet(url).setRealm(realm.setUsePreemptiveAuth(preemptive).build()).setHeader("X-Content","Test").execute();
188173
}
189174

190175
@Override
191176
protectedStringgetTargetUrl() {
192177
return"http://localhost:" +port1 +"/";
193178
}
194179

180+
@Override
181+
protectedStringgetTargetUrl2() {
182+
return"http://localhost:" +port2 +"/";
183+
}
184+
195185
@Override
196186
publicAbstractHandlerconfigureHandler()throwsException {
197187
returnnewIncompleteResponseHandler();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp