Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add brotli to IntegrationTest #1449

Merged
merged 1 commit into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -2,5 +2,6 @@ versions_groovy=3.0.13
versions_ribbon=2.4.4
versions_netty=4.1.87.Final
versions_netty_io_uring=0.0.16.Final
versions_brotli4j=1.9.0
release.scope=patch
release.version=2.3.1-SNAPSHOT
5 changes: 5 additions & 0 deletions zuul-integration-test/build.gradle
Expand Up @@ -16,6 +16,11 @@ dependencies {
testImplementation libraries.truth, libraries.jupiterApi, libraries.jupiterParams, libraries.jupiterEngine, libraries.jupiterMockito, libraries.okhttp
testRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.19.0'
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
testRuntimeOnly "com.aayushatharva.brotli4j:brotli4j:$versions_brotli4j"
testRuntimeOnly "com.aayushatharva.brotli4j:native-osx-aarch64:$versions_brotli4j"
testRuntimeOnly "com.aayushatharva.brotli4j:native-osx-x86_64:$versions_brotli4j"
testRuntimeOnly "com.aayushatharva.brotli4j:native-linux-x86_64:$versions_brotli4j"
testRuntimeOnly "com.aayushatharva.brotli4j:native-linux-aarch64:$versions_brotli4j"
}

tasks.withType(Test).all {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.netflix.zuul.integration.server.Bootstrap;
import com.netflix.zuul.integration.server.HeaderNames;
import com.netflix.zuul.integration.server.TestUtil;
import io.netty.handler.codec.compression.Brotli;
import io.netty.util.ResourceLeakDetector;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -389,6 +390,41 @@ void gzipOnly() throws Exception {
connection.disconnect();
}

@Test
void brotliOnly() throws Throwable {
Brotli.ensureAvailability();
final String expectedResponseBody = TestUtil.COMPRESSIBLE_CONTENT;
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", "br");
InputStream inputStream = connection.getInputStream();
assertEquals(200, connection.getResponseCode());
assertEquals("text/plain", connection.getHeaderField("Content-Type"));
assertEquals("br", connection.getHeaderField("Content-Encoding"));
byte[] compressedData = IOUtils.toByteArray(inputStream);
assertTrue(compressedData.length > 0);
/* TODO : call brotli4j DirectDecompress
DirectDecompress decompressResult = DirectDecompress.decompress(ByteBufUtil.getBytes(contentBuf));
assertEquals(DecoderJNI.Status.DONE, decompressResult.getResultStatus());
assertEquals("blah blah blah",
new String(decompressResult.getDecompressedData(), TestUtil.CHARSET));
*/

inputStream.close();
connection.disconnect();
}

@Test
void noCompression() throws Exception {
final String expectedResponseBody = TestUtil.COMPRESSIBLE_CONTENT;
Expand Down