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

Commitfea92a5

Browse files
committed
Re-enable BodyDeferringAsyncHandlerTest#deferredSimpleWithFailure
1 parent5fed25b commitfea92a5

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

‎client/src/test/java/org/asynchttpclient/handler/BodyDeferringAsyncHandlerTest.java‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
packageorg.asynchttpclient.handler;
1414

15+
importstaticio.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
1516
importstaticorg.apache.commons.io.IOUtils.copy;
1617
importstaticorg.asynchttpclient.Dsl.*;
1718
importstaticorg.asynchttpclient.test.TestUtils.findFreePort;
@@ -34,22 +35,22 @@
3435
importorg.asynchttpclient.AsyncHttpClientConfig;
3536
importorg.asynchttpclient.BoundRequestBuilder;
3637
importorg.asynchttpclient.Response;
38+
importorg.asynchttpclient.exception.RemotelyClosedException;
3739
importorg.asynchttpclient.handler.BodyDeferringAsyncHandler.BodyDeferringInputStream;
3840
importorg.eclipse.jetty.server.Request;
3941
importorg.eclipse.jetty.server.handler.AbstractHandler;
4042
importorg.testng.annotations.Test;
4143

4244
publicclassBodyDeferringAsyncHandlerTestextendsAbstractBasicTest {
4345

44-
// not a half gig ;) for test shorter run's sake
45-
protectedstaticfinalintHALF_GIG =100000;
46+
protectedstaticfinalintCONTENT_LENGTH_VALUE =100000;
4647

4748
publicstaticclassSlowAndBigHandlerextendsAbstractHandler {
4849

4950
publicvoidhandle(StringpathInContext,Requestrequest,HttpServletRequesthttpRequest,HttpServletResponsehttpResponse)throwsIOException,ServletException {
5051

5152
httpResponse.setStatus(200);
52-
httpResponse.setContentLength(HALF_GIG);
53+
httpResponse.setContentLength(CONTENT_LENGTH_VALUE);
5354
httpResponse.setContentType("application/octet-stream");
5455

5556
httpResponse.flushBuffer();
@@ -58,7 +59,7 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
5859
finalbooleanwantSlow =httpRequest.getHeader("X-SLOW") !=null;
5960

6061
OutputStreamos =httpResponse.getOutputStream();
61-
for (inti =0;i <HALF_GIG;i++) {
62+
for (inti =0;i <CONTENT_LENGTH_VALUE;i++) {
6263
os.write(i %255);
6364

6465
if (wantSlow) {
@@ -70,9 +71,9 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
7071
}
7172

7273
if (wantFailure) {
73-
if (i >HALF_GIG /2) {
74+
if (i >CONTENT_LENGTH_VALUE /2) {
7475
// kaboom
75-
// yes, response iscommited, but Jetty does aborts and
76+
// yes, response iscommitted, but Jetty does aborts and
7677
// drops connection
7778
httpResponse.sendError(500);
7879
break;
@@ -120,46 +121,45 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce
120121
Responseresp =bdah.getResponse();
121122
assertNotNull(resp);
122123
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
123-
assertEquals(resp.getHeader("content-length"),String.valueOf(HALF_GIG));
124+
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
124125
// we got headers only, it's probably not all yet here (we have BIG file
125126
// downloading)
126-
assertTrue(cos.getByteCount() <=HALF_GIG);
127+
assertTrue(cos.getByteCount() <=CONTENT_LENGTH_VALUE);
127128

128129
// now be polite and wait for body arrival too (otherwise we would be
129130
// dropping the "line" on server)
130131
f.get();
131132
// it all should be here now
132-
assertEquals(cos.getByteCount(),HALF_GIG);
133+
assertEquals(cos.getByteCount(),CONTENT_LENGTH_VALUE);
133134
}
134135
}
135136

136-
@Test(groups ="standalone",enabled =false)
137-
publicvoiddeferredSimpleWithFailure()throwsIOException,ExecutionException,TimeoutException,InterruptedException {
137+
@Test(groups ="standalone",expectedExceptions =RemotelyClosedException.class)
138+
publicvoiddeferredSimpleWithFailure()throwsThrowable {
138139
try (AsyncHttpClientclient =asyncHttpClient(getAsyncHttpClientConfig())) {
139-
BoundRequestBuilderr =client.prepareGet("http://localhost:" +port1 +"/deferredSimpleWithFailure").addHeader("X-FAIL-TRANSFER",
140-
Boolean.TRUE.toString());
140+
BoundRequestBuilderr =client.prepareGet("http://localhost:" +port1 +"/deferredSimpleWithFailure").addHeader("X-FAIL-TRANSFER",Boolean.TRUE.toString());
141141

142142
CountingOutputStreamcos =newCountingOutputStream();
143143
BodyDeferringAsyncHandlerbdah =newBodyDeferringAsyncHandler(cos);
144144
Future<Response>f =r.execute(bdah);
145145
Responseresp =bdah.getResponse();
146146
assertNotNull(resp);
147147
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
148-
assertEquals(resp.getHeader("content-length"),String.valueOf(HALF_GIG));
148+
assertEquals(resp.getHeader(CONTENT_LENGTH),String.valueOf(CONTENT_LENGTH_VALUE));
149149
// we got headers only, it's probably not all yet here (we have BIG file
150150
// downloading)
151-
assertTrue(cos.getByteCount() <=HALF_GIG);
151+
assertTrue(cos.getByteCount() <=CONTENT_LENGTH_VALUE);
152152

153153
// now be polite and wait for body arrival too (otherwise we would be
154154
// dropping the "line" on server)
155155
try {
156156
f.get();
157-
fail("get() should fail with IOException!");
158-
}catch (Exceptione) {
157+
}catch (ExecutionExceptione) {
159158
// good
159+
// it's incomplete, there was an error
160+
assertNotEquals(cos.getByteCount(),CONTENT_LENGTH_VALUE);
161+
throwe.getCause();
160162
}
161-
// it's incomplete, there was an error
162-
assertNotEquals(cos.getByteCount(),HALF_GIG);
163163
}
164164
}
165165

@@ -179,7 +179,7 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
179179
Responseresp =is.getAsapResponse();
180180
assertNotNull(resp);
181181
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
182-
assertEquals(resp.getHeader("content-length"),String.valueOf(HALF_GIG));
182+
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
183183
// "consume" the body, but our code needs input stream
184184
CountingOutputStreamcos =newCountingOutputStream();
185185
try {
@@ -192,15 +192,14 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T
192192
// now we don't need to be polite, since consuming and closing
193193
// BodyDeferringInputStream does all.
194194
// it all should be here now
195-
assertEquals(cos.getByteCount(),HALF_GIG);
195+
assertEquals(cos.getByteCount(),CONTENT_LENGTH_VALUE);
196196
}
197197
}
198198

199199
@Test(groups ="standalone")
200200
publicvoiddeferredInputStreamTrickWithFailure()throwsIOException,ExecutionException,TimeoutException,InterruptedException {
201201
try (AsyncHttpClientclient =asyncHttpClient(getAsyncHttpClientConfig())) {
202-
BoundRequestBuilderr =client.prepareGet("http://localhost:" +port1 +"/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER",
203-
Boolean.TRUE.toString());
202+
BoundRequestBuilderr =client.prepareGet("http://localhost:" +port1 +"/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER",Boolean.TRUE.toString());
204203
PipedOutputStreampos =newPipedOutputStream();
205204
PipedInputStreampis =newPipedInputStream(pos);
206205
BodyDeferringAsyncHandlerbdah =newBodyDeferringAsyncHandler(pos);
@@ -212,7 +211,7 @@ public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionE
212211
Responseresp =is.getAsapResponse();
213212
assertNotNull(resp);
214213
assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
215-
assertEquals(resp.getHeader("content-length"),String.valueOf(HALF_GIG));
214+
assertEquals(resp.getHeader("content-length"),String.valueOf(CONTENT_LENGTH_VALUE));
216215
// "consume" the body, but our code needs input stream
217216
CountingOutputStreamcos =newCountingOutputStream();
218217
try {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp