|
18 | 18 | import static org.testng.Assert.assertTrue;
|
19 | 19 | import static org.testng.FileAssert.fail;
|
20 | 20 |
|
| 21 | +import java.io.BufferedInputStream; |
| 22 | +import java.io.FileInputStream; |
| 23 | +import java.io.InputStream; |
| 24 | + |
21 | 25 | import org.asynchttpclient.AsyncHttpClient;
|
22 | 26 | import org.asynchttpclient.AsyncHttpClientConfig;
|
23 | 27 | import org.asynchttpclient.Request;
|
|
26 | 30 | import org.asynchttpclient.generators.InputStreamBodyGenerator;
|
27 | 31 | import org.testng.annotations.Test;
|
28 | 32 |
|
29 |
| -import java.io.BufferedInputStream; |
30 |
| -import java.io.FileInputStream; |
31 |
| - |
32 | 33 | /**
|
33 | 34 | * Test that the url fetcher is able to communicate via a proxy
|
34 | 35 | *
|
|
37 | 38 | abstract public class ChunkingTest extends AbstractBasicTest {
|
38 | 39 | // So we can just test the returned data is the image,
|
39 | 40 | // and doesn't contain the chunked delimeters.
|
| 41 | + @Test() |
| 42 | + public void testBufferLargerThanFile() throws Throwable { |
| 43 | + doTest(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000)); |
| 44 | + } |
| 45 | + |
| 46 | + @Test() |
| 47 | + public void testBufferSmallThanFile() throws Throwable { |
| 48 | + doTest(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE))); |
| 49 | + } |
40 | 50 |
|
41 |
| - /** |
42 |
| - * Tests that the custom chunked stream result in success and content returned that is unchunked |
43 |
| - */ |
44 | 51 | @Test()
|
45 |
| - public void testCustomChunking() throws Exception { |
46 |
| - AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder(); |
| 52 | + public void testDirectFile() throws Throwable { |
| 53 | + doTest(new FileInputStream(LARGE_IMAGE_FILE)); |
| 54 | + } |
47 | 55 |
|
48 |
| - bc.setAllowPoolingConnections(true); |
49 |
| - bc.setMaxConnectionsPerHost(1); |
50 |
| - bc.setMaxConnections(1); |
51 |
| - bc.setConnectTimeout(1000); |
52 |
| - bc.setRequestTimeout(1000); |
53 |
| - bc.setFollowRedirect(true); |
| 56 | + public void doTest(InputStream is) throws Throwable { |
| 57 | + AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder()// |
| 58 | + .setAllowPoolingConnections(true)// |
| 59 | + .setMaxConnectionsPerHost(1)// |
| 60 | + .setMaxConnections(1)// |
| 61 | + .setConnectTimeout(1000)// |
| 62 | + .setRequestTimeout(1000) |
| 63 | + .setFollowRedirect(true); |
54 | 64 |
|
55 | 65 | AsyncHttpClient c = getAsyncHttpClient(bc.build());
|
56 | 66 | try {
|
57 | 67 |
|
58 | 68 | RequestBuilder builder = new RequestBuilder("POST");
|
59 | 69 | builder.setUrl(getTargetUrl());
|
60 |
| - // made buff in stream big enough to mark. |
61 |
| - builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000))); |
| 70 | + builder.setBody(new InputStreamBodyGenerator(is)); |
62 | 71 |
|
63 | 72 | Request r = builder.build();
|
64 | 73 |
|
|
0 commit comments