Skip to content

Commit

Permalink
integration test: jumbo origin response (#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
sullis committed Oct 24, 2023
1 parent e3e7f85 commit 6f064c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Expand Up @@ -19,6 +19,7 @@
import com.aayushatharva.brotli4j.decoder.DecoderJNI;
import com.aayushatharva.brotli4j.decoder.DirectDecompress;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.Slf4jNotifier;
import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.http.Fault;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
Expand Down Expand Up @@ -102,7 +103,10 @@ class IntegrationTest {
@RegisterExtension
static WireMockExtension wireMockExtension = WireMockExtension.newInstance()
.configureStaticDsl(true)
.options(wireMockConfig().dynamicPort().useChunkedTransferEncoding(Options.ChunkedEncodingPolicy.ALWAYS))
.options(wireMockConfig()
.dynamicPort()
.useChunkedTransferEncoding(Options.ChunkedEncodingPolicy.ALWAYS)
.notifier(new Slf4jNotifier(true)))
.build();

@BeforeAll
Expand Down Expand Up @@ -499,6 +503,33 @@ void noCompression() throws Exception {
connection.disconnect();
}

@Test
void jumboOriginResponseShouldBeChunked() throws Exception {
final String expectedResponseBody = TestUtil.JUMBO_RESPONSE_BODY;
final WireMock wireMock = wmRuntimeInfo.getWireMock();
wireMock.register(get(anyUrl())
.willReturn(aResponse()
.withStatus(200)
.withBody(expectedResponseBody)
.withHeader("Content-Type", TestUtil.COMPRESSIBLE_CONTENT_TYPE)));

URL url = new URL(zuulBaseUri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Accept-Encoding", ""); // no compression
InputStream inputStream = connection.getInputStream();
assertEquals(200, connection.getResponseCode());
assertEquals("text/plain", connection.getHeaderField("Content-Type"));
assertNull(connection.getHeaderField("Content-Encoding"));
assertEquals("chunked", connection.getHeaderField("Transfer-Encoding"));
byte[] data = IOUtils.toByteArray(inputStream);
String text = new String(data, TestUtil.CHARSET);
assertEquals(expectedResponseBody, text);
inputStream.close();
connection.disconnect();
}

@Test
@EnabledOnOs(value = {OS.LINUX})
void epollIsAvailableOnLinux() {
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.netflix.appinfo.InstanceInfo;
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
import org.apache.commons.lang3.StringUtils;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand All @@ -30,6 +31,7 @@ private TestUtil() {}

public static final String COMPRESSIBLE_CONTENT = "Hello Hello Hello Hello Hello";
public static final String COMPRESSIBLE_CONTENT_TYPE = "text/plain";
public static final String JUMBO_RESPONSE_BODY = StringUtils.repeat("abc", 1_000_000);

public static DiscoveryEnabledServer makeDiscoveryEnabledServer(
final String appName, final String ipAddress, final int port) {
Expand Down
1 change: 1 addition & 0 deletions zuul-integration-test/src/test/resources/log4j2-test.xml
Expand Up @@ -27,6 +27,7 @@
</Root>
<Logger name="org.apache" level="WARN"/>
<Logger name="org.eclipse" level="WARN"/>
<Logger name="WireMock" level="WARN"/>
<Logger name="zuul.server.nettylog" level="WARN"/>
<Logger name="zuul.origin.nettylog" level="WARN"/>
</Loggers>
Expand Down

0 comments on commit 6f064c7

Please sign in to comment.