Skip to content

Commit

Permalink
test compression
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Jan 11, 2024
1 parent 689b5cf commit ad7002c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void beforeEach() throws IOException {
for (Endpoint ph : endpoints) {
ph.getProxy().enable();
}
logs.reset();
}

protected static List<Endpoint> getEndpoints() {
Expand Down
1 change: 1 addition & 0 deletions resilience-tests/src/test/java/resilience/ClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void beforeEach() throws IOException {
for (Endpoint endpoint : endpoints) {
endpoint.getProxy().enable();
}
logs.reset();
}

protected static List<Endpoint> getEndpoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void afterAll() throws IOException {
@BeforeEach
void beforeEach() {
getEndpoint().enable();
logs.reset();
}

protected static Endpoint getEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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"));
}

}

0 comments on commit ad7002c

Please sign in to comment.