From ad7002c27d8f8488a2916cd864d95f7a7185b556 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Thu, 11 Jan 2024 20:40:52 +0100 Subject: [PATCH] test compression --- .../java/resilience/ActiveFailoverTest.java | 1 + .../src/test/java/resilience/ClusterTest.java | 1 + .../java/resilience/SingleServerTest.java | 1 + .../compression/CompressionTest.java | 72 +++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 resilience-tests/src/test/java/resilience/compression/CompressionTest.java diff --git a/resilience-tests/src/test/java/resilience/ActiveFailoverTest.java b/resilience-tests/src/test/java/resilience/ActiveFailoverTest.java index bad70d4c1..5ccc494cf 100644 --- a/resilience-tests/src/test/java/resilience/ActiveFailoverTest.java +++ b/resilience-tests/src/test/java/resilience/ActiveFailoverTest.java @@ -49,6 +49,7 @@ void beforeEach() throws IOException { for (Endpoint ph : endpoints) { ph.getProxy().enable(); } + logs.reset(); } protected static List getEndpoints() { diff --git a/resilience-tests/src/test/java/resilience/ClusterTest.java b/resilience-tests/src/test/java/resilience/ClusterTest.java index bfe88d6e4..39cb67987 100644 --- a/resilience-tests/src/test/java/resilience/ClusterTest.java +++ b/resilience-tests/src/test/java/resilience/ClusterTest.java @@ -54,6 +54,7 @@ void beforeEach() throws IOException { for (Endpoint endpoint : endpoints) { endpoint.getProxy().enable(); } + logs.reset(); } protected static List getEndpoints() { diff --git a/resilience-tests/src/test/java/resilience/SingleServerTest.java b/resilience-tests/src/test/java/resilience/SingleServerTest.java index 3aa587d93..89d028469 100644 --- a/resilience-tests/src/test/java/resilience/SingleServerTest.java +++ b/resilience-tests/src/test/java/resilience/SingleServerTest.java @@ -37,6 +37,7 @@ static void afterAll() throws IOException { @BeforeEach void beforeEach() { getEndpoint().enable(); + logs.reset(); } protected static Endpoint getEndpoint() { diff --git a/resilience-tests/src/test/java/resilience/compression/CompressionTest.java b/resilience-tests/src/test/java/resilience/compression/CompressionTest.java new file mode 100644 index 000000000..ccd462a59 --- /dev/null +++ b/resilience-tests/src/test/java/resilience/compression/CompressionTest.java @@ -0,0 +1,72 @@ +package resilience.compression; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import com.arangodb.ArangoDB; +import com.arangodb.Compression; +import com.arangodb.Protocol; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import resilience.ClusterTest; +import resilience.SingleServerTest; + +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +/** + * @author Michele Rastelli + */ +class CompressionTest extends ClusterTest { + + @ParameterizedTest + @EnumSource(Protocol.class) + void gzip(Protocol protocol) { + doTest(protocol, Compression.GZIP); + } + + @ParameterizedTest + @EnumSource(Protocol.class) + void deflate(Protocol protocol) { + doTest(protocol, Compression.DEFLATE); + } + + void doTest(Protocol protocol, Compression compression) { + assumeTrue(protocol != Protocol.VST); + assumeTrue(protocol != Protocol.HTTP_VPACK); + assumeTrue(protocol != Protocol.HTTP_JSON); + + ArangoDB adb = dbBuilder() + .protocol(protocol) + .compression(compression) + .compressionThreshold(0) + .build(); + + List data = IntStream.range(0, 500) + .mapToObj(i -> UUID.randomUUID().toString()) + .collect(Collectors.toList()); + + adb.db().query("FOR i IN @data RETURN i", String.class, + Collections.singletonMap("data", data)).asListRemaining(); + + adb.shutdown(); + + String compressionLC = compression.toString().toLowerCase(Locale.ROOT); + + // request + assertThat(logs.getLogs()) + .map(ILoggingEvent::getFormattedMessage) + .anyMatch(l -> l.contains("content-encoding: " + compressionLC) && l.contains("accept-encoding: " + compressionLC)); + + // response + assertThat(logs.getLogs()) + .map(ILoggingEvent::getFormattedMessage) + .anyMatch(l -> l.contains("content-encoding: " + compressionLC) && l.contains("server: ArangoDB")); + } + +}