Skip to content

Commit

Permalink
add brotli to IntegrationTest (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
sullis committed Jan 31, 2023
1 parent fded9b4 commit 378d105
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
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

0 comments on commit 378d105

Please sign in to comment.