|
1 | 1 | package com.blazemeter.jmeter.http2.core; |
2 | 2 |
|
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.junit.Assert.assertThrows; |
| 5 | + |
3 | 6 | import com.blazemeter.jmeter.http2.sampler.HTTP2Sampler; |
4 | 7 | import com.blazemeter.jmeter.http2.sampler.JMeterTestUtils; |
5 | 8 | import com.google.common.base.Stopwatch; |
6 | 9 | import com.google.common.io.Resources; |
7 | 10 | import jakarta.servlet.http.HttpServlet; |
8 | 11 | import jakarta.servlet.http.HttpServletRequest; |
9 | 12 | import jakarta.servlet.http.HttpServletResponse; |
| 13 | +import java.io.ByteArrayOutputStream; |
| 14 | +import java.io.IOException; |
| 15 | +import java.io.InputStream; |
| 16 | +import java.net.MalformedURLException; |
| 17 | +import java.net.URL; |
| 18 | +import java.nio.charset.StandardCharsets; |
| 19 | +import java.nio.file.Files; |
| 20 | +import java.nio.file.Paths; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Base64; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.List; |
| 25 | +import java.util.concurrent.ExecutionException; |
| 26 | +import java.util.concurrent.TimeUnit; |
| 27 | +import java.util.concurrent.TimeoutException; |
| 28 | +import java.util.stream.Collectors; |
| 29 | +import java.util.zip.GZIPOutputStream; |
10 | 30 | import jodd.net.MimeTypes; |
11 | 31 | import org.apache.jmeter.config.Arguments; |
12 | 32 | import org.apache.jmeter.protocol.http.control.AuthManager; |
|
55 | 75 | import org.junit.runner.RunWith; |
56 | 76 | import org.mockito.junit.MockitoJUnitRunner; |
57 | 77 |
|
58 | | -import java.io.ByteArrayOutputStream; |
59 | | -import java.io.IOException; |
60 | | -import java.io.InputStream; |
61 | | -import java.net.MalformedURLException; |
62 | | -import java.net.URL; |
63 | | -import java.nio.charset.StandardCharsets; |
64 | | -import java.nio.file.Files; |
65 | | -import java.nio.file.Paths; |
66 | | -import java.util.Arrays; |
67 | | -import java.util.Base64; |
68 | | -import java.util.Collections; |
69 | | -import java.util.List; |
70 | | -import java.util.concurrent.ExecutionException; |
71 | | -import java.util.concurrent.TimeUnit; |
72 | | -import java.util.concurrent.TimeoutException; |
73 | | -import java.util.stream.Collectors; |
74 | | -import java.util.zip.GZIPOutputStream; |
75 | | - |
76 | | -import static org.assertj.core.api.Assertions.assertThat; |
77 | | -import static org.junit.Assert.assertThrows; |
78 | | - |
79 | 78 | @RunWith(MockitoJUnitRunner.class) |
80 | 79 | public class HTTP2JettyClientTest { |
81 | 80 |
|
@@ -301,17 +300,17 @@ public void shouldSendBodyInformationWhenRequestWithBodyRaw() throws Exception { |
301 | 300 | } |
302 | 301 |
|
303 | 302 | private HTTPSampleResult buildOkResult(String requestBody, String requestContentType) { |
304 | | - return buildResult(true, Code.OK, null, |
| 303 | + return buildResult(true, HttpStatus.Code.OK, null, |
305 | 304 | requestBody != null ? requestBody.getBytes(StandardCharsets.UTF_8) : null, |
306 | 305 | requestContentType); |
307 | 306 | } |
308 | 307 |
|
309 | | - private HTTPSampleResult buildResult(boolean successful, Code statusCode, |
| 308 | + private HTTPSampleResult buildResult(boolean successful, HttpStatus.Code statusCode, |
310 | 309 | HttpFields headers, byte[] requestBody, String requestContentType) { |
311 | 310 |
|
312 | 311 | Mutable httpFields = HttpFields.build() |
313 | 312 | .add(HttpHeader.ACCEPT_ENCODING, "gzip") |
314 | | - .add(HttpHeader.USER_AGENT, "Jetty/11.0.6"); |
| 313 | + .add(HttpHeader.USER_AGENT, "Jetty/11.0.10"); |
315 | 314 |
|
316 | 315 | if (requestContentType != null) { |
317 | 316 | httpFields.add(HttpHeader.CONTENT_TYPE, requestContentType); |
@@ -613,14 +612,12 @@ public void shouldGetFileDataWithFileIsSentAsBodyPart() throws Exception { |
613 | 612 | validateResponse(result, expected); |
614 | 613 | } |
615 | 614 |
|
616 | | - @Test |
617 | | - public void shouldReturnErrorMessageWhenResponseTimeIsOver() throws Exception { |
| 615 | + @Test(expected = TimeoutException.class) |
| 616 | + public void shouldThrowTimeoutExceptionWhenResponseBiggerThanTimeout() throws Exception { |
618 | 617 | buildStartedServer(); |
619 | 618 | long timeout = 1000; |
620 | 619 | sampler.setResponseTimeout(String.valueOf(timeout)); |
621 | | - Stopwatch waitTime = Stopwatch.createStarted(); |
622 | | - assertThrows(TimeoutException.class, () -> sampleWithGet(SERVER_PATH_SLOW)); |
623 | | - softly.assertThat(waitTime.elapsed(TimeUnit.MILLISECONDS)).isGreaterThanOrEqualTo(timeout); |
| 620 | + sampleWithGet(SERVER_PATH_SLOW); |
624 | 621 | } |
625 | 622 |
|
626 | 623 | @Test |
@@ -869,7 +866,7 @@ public void shouldNotUseMultipartWhenHasOneFileWithEmptyParamName() throws Excep |
869 | 866 | buildStartedServer(); |
870 | 867 | URL file = getClass().getResource("blazemeter-labs-logo.png"); |
871 | 868 | sampler.setHTTPFiles(new HTTPFileArg[]{new HTTPFileArg(file.getPath(), "", "image/png")}); |
872 | | - HTTPSampleResult expected = buildResult(true, Code.OK, null, |
| 869 | + HTTPSampleResult expected = buildResult(true, HttpStatus.Code.OK, null, |
873 | 870 | Resources.toByteArray(file), "image/png"); |
874 | 871 | validateResponse(sample(SERVER_PATH_200_FILE_SENT, HTTPConstants.POST), expected); |
875 | 872 | } |
@@ -923,19 +920,12 @@ public void shouldThrowAnExceptionWhenBufferSizeIsBiggerThanMaxBufferSize() thro |
923 | 920 | sampleWithGet(SERVER_PATH_BIG_RESPONSE); |
924 | 921 | } |
925 | 922 |
|
926 | | - @Test |
| 923 | + @Test(expected = IllegalArgumentException.class) |
927 | 924 | public void shouldNotGetAResponseWhenBufferSizeIsBiggerThanMaxBufferSize() throws Exception { |
928 | 925 | buildStartedServer(); |
929 | 926 | JMeterUtils.setProperty("httpJettyClient.maxBufferSize", String.valueOf(BIG_BUFFER_SIZE - 1)); |
930 | 927 | //There is no response, since an exception is thrown in this case |
931 | | - |
932 | | - Exception exception = assertThrows(IllegalArgumentException.class, |
933 | | - () -> sampleWithGet(SERVER_PATH_BIG_RESPONSE)); |
934 | | - |
935 | | - assertThat(exception.toString()).contains( |
936 | | - "java.lang.IllegalArgumentException: Buffer capacity 4194303 exceeded." |
937 | | - + " To modify buffer size, set the property httpJettyClient.maxBufferSize" |
938 | | - + " in the jmeter.properties file"); |
| 928 | + sampleWithGet(SERVER_PATH_BIG_RESPONSE); |
939 | 929 | } |
940 | 930 |
|
941 | 931 | } |
0 commit comments