8000 added compression configuration options · rashtao/arangodb-java-driver@0c21dea · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c21dea

Browse files
committed
added compression configuration options
1 parent 3423afa commit 0c21dea

File tree

11 files changed

+184
-3
lines changed

11 files changed

+184
-3
lines changed

core/src/main/java/com/arangodb/ArangoDB.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,44 @@ public Builder asyncExecutor(final Executor executor) {
625625
return this;
626626
}
627627

628+
/**
629+
* Sets the {@code content-encoding} and {@code accept-encoding} to use for HTTP requests and the related
630+
* algorithm to encode and decode the transferred data. (default: {@link Compression#NONE})
631+
*
632+
* @param compression format
633+
* @return {@link ArangoDB.Builder}
634+
* @since ArangoDB 3.12
635+
*/
636+
public Builder compression(final Compression compression) {
637+
config.setCompression(compression);
638+
return this;
639+
}
640+
641+
/**
642+
* Sets the minimum HTTP request body size (in bytes) to trigger compression.
643+
* (default: {@code 1024})
644+
*
645+
* @param threshold body size (in bytes)
646+
* @return {@link ArangoDB.Builder}
647+
* @since ArangoDB 3.12
648+
*/
649+
public Builder compressionThreshold(Integer threshold) {
650+
config.setCompressionThreshold(threshold);
651+
return this;
652+
}
653+
654+
/**
655+
* Sets the compression level. (default: {@code 6})
656+
*
657+
* @param level compression level
658+
* @return {@link ArangoDB.Builder}
659+
* @since ArangoDB 3.12
660+
*/
661+
public Builder compressionLevel(Integer level) {
662+
config.setCompressionLevel(level);
663+
return this;
664+
}
665+
628666
@UnstableApi
629667
protected A3DB ProtocolProvider protocolProvider(Protocol protocol) {
630668
ServiceLoader<ProtocolProvider> loader = ServiceLoader.load(ProtocolProvider.class);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.arangodb;
2+
3+
public enum Compression {
4+
NONE,
5+
DEFLATE,
6+
GZIP
7+
}

core/src/main/java/com/arangodb/config/ArangoConfigProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.arangodb.config;
22

3+
import com.arangodb.Compression;
34
import com.arangodb.Protocol;
45
import com.arangodb.entity.LoadBalancingStrategy;
56
import com.arangodb.internal.config.ArangoConfigPropertiesImpl;
@@ -97,4 +98,16 @@ default Optional<Integer> getResponseQueueTimeSamples() {
9798
return Optional.empty();
9899
}
99100

101+
default Optional<Compression> getCompression() {
102+
return Optional.empty();
103+
}
104+
105+
default Optional<Integer> getCompressionThreshold() {
106+
return Optional.empty();
107+
}
108+
109+
default Optional<Integer> getCompressionLevel() {
110+
return Optional.empty();
111+
}
112+
100113
}

core/src/main/java/com/arangodb/internal/ArangoDefaults.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.arangodb.internal;
2222

23+
import com.arangodb.Compression;
2324
import com.arangodb.Protocol;
2425
import com.arangodb.config.HostDescription;
2526
import com.arangodb.entity.LoadBalancingStrategy;
@@ -54,6 +55,12 @@ public final class ArangoDefaults {
5455
public static final LoadBalancingStrategy DEFAULT_LOAD_BALANCING_STRATEGY = LoadBalancingStrategy.NONE;
5556
public static final Integer DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES = 10;
5657

58+
// region compression
59+
public static final Compression DEFAULT_COMPRESSION = Compression.NONE;
60+
public static final Integer DEFAULT_COMPRESSION_THRESHOLD = 1024;
61+
public static final Integer DEFAULT_COMPRESSION_LEVEL = 6;
62+
// endregion
63+
5764
private ArangoDefaults() {
5865
super();
5966
}

core/src/main/java/com/arangodb/internal/config/ArangoConfig.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.arangodb.internal.config;
22

33
import com.arangodb.ArangoDBException;
4+
import com.arangodb.Compression;
45
import com.arangodb.ContentType;
56
import com.arangodb.Protocol;
67
import com.arangodb.arch.UsedInApi;
@@ -45,6 +46,9 @@ public class ArangoConfig {
4546
private Integer responseQueueTimeSamples;
4647
private Module protocolModule;
4748
private Executor asyncExecutor;
49+
private Compression compression;
50+
private Integer compressionThreshold;
51+
private Integer compressionLevel;
4852

4953
private static final Logger LOG = LoggerFactory.getLogger(ArangoConfig.class);
5054

@@ -105,6 +109,9 @@ public void loadProperties(final ArangoConfigProperties properties) {
105109
acquireHostListInterval = properties.getAcquireHostListInterval().orElse(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST_INTERVAL);
106110
loadBalancingStrategy = properties.getLoadBalancingStrategy().orElse(ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY);
107111
responseQueueTimeSamples = properties.getResponseQueueTimeSamples().orElse(ArangoDefaults.DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES);
112+
compression = properties.getCompression().orElse(ArangoDefaults.DEFAULT_COMPRESSION);
113+
compressionThreshold = properties.getCompressionThreshold().orElse(ArangoDefaults.DEFAULT_COMPRESSION_THRESHOLD);
114+
compressionLevel = properties.getCompressionLevel().orElse(ArangoDefaults.DEFAULT_COMPRESSION_LEVEL);
108115
}
109116

110117
public List<HostDescription> getHosts() {
@@ -298,4 +305,28 @@ public Executor getAsyncExecutor() {
298305
public void setAsyncExecutor(Executor asyncExecutor) {
299306
this.asyncExecutor = asyncExecutor;
300307
}
308+
309+
public Compression getCompression() {
310+
return compression;
311+
}
312+
313+
public void setCompression(Compression compression) {
314+
this.compression = compression;
315+
}
316+
317+
public Integer getCompressionThreshold() {
318+
return compressionThreshold;
319+
}
320+
321+
public void setCompressionThreshold(Integer compressionThreshold) {
322+
this.compressionThreshold = compressionThreshold;
323+
}
324+
325+
public Integer getCompressionLevel() {
326+
return compressionLevel;
327+
}
328+
329+
public void setCompressionLevel(Integer compressionLevel) {
330+
this.compressionLevel = compressionLevel;
331+
}
301332
}

core/src/main/java/com/arangodb/internal/config/ArangoConfigPropertiesImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.arangodb.internal.config;
22

33
import com.arangodb.ArangoDBException;
4+
import com.arangodb.Compression;
45
import com.arangodb.Protocol;
56
import com.arangodb.config.ArangoConfigProperties;
67
import com.arangodb.config.HostDescription;
@@ -145,4 +146,19 @@ public Optional<Integer> getResponseQueueTimeSamples() {
145146
return Optional.ofNullable(getProperty("responseQueueTimeSamples")).map(Integer::valueOf);
146147
}
147148

149+
@Override
150+
public Optional<Compression> getCompression() {
151+
return Optional.ofNullable(getProperty("compression")).map(Compression::valueOf);
152+
}
153+
154+
@Override
155+
public Optional<Integer> getCompressionThreshold() {
156+
return Optional.ofNullable(getProperty("compressionThreshold")).map(Integer::valueOf);
157+
}
158+
159+
@Override
160+
public Optional<Integer> getCompressionLevel() {
161+
return Optional.ofNullable(getProperty("compressionLevel")).map(Integer::valueOf);
162+
}
163+
148164
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.arangodb;
2+
3+
import com.arangodb.internal.ArangoDefaults;
4+
import com.arangodb.internal.config.ArangoConfig;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class ArangoConfigTest {
10+
@Test
11+
void defaultValues() {
12+
ArangoConfig cfg = new ArangoConfig();
13+
assertThat(cfg.getHosts()).isEqualTo(ArangoDefaults.DEFAULT_HOSTS);
14+
assertThat(cfg.getProtocol()).isEqualTo(Protocol.HTTP2_JSON);
15+
assertThat(cfg.getTimeout()).isEqualTo(ArangoDefaults.DEFAULT_TIMEOUT);
16+
assertThat(cfg.getUser()).isEqualTo(ArangoDefaults.DEFAULT_USER);
17+
assertThat(cfg.getPassword()).isNull();
18+
assertThat(cfg.getJwt()).isNull();
19+
assertThat(cfg.getUseSsl()).isEqualTo(ArangoDefaults.DEFAULT_USE_SSL);
20+
assertThat(cfg.getSslContext()).isNull();
21+
assertThat(cfg.getVerifyHost()).isEqualTo(ArangoDefaults.DEFAULT_VERIFY_HOST);
22+
assertThat(cfg.getChunkSize()).isEqualTo(ArangoDefaults.DEFAULT_CHUNK_SIZE);
23+
assertThat(cfg.getMaxConnections()).isEqualTo(ArangoDefaults.MAX_CONNECTIONS_HTTP2_DEFAULT);
24+
assertThat(cfg.getConnectionTtl()).isNull();
25+
assertThat(cfg.getKeepAliveInterval()).isNull();
26+
assertThat(cfg.getAcquireHostList()).isEqualTo(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST);
27+
assertThat(cfg.getAcquireHostListInterval()).isEqualTo(ArangoDefaults.DEFAULT_ACQUIRE_HOST_LIST_INTERVAL);
28+
assertThat(cfg.getLoadBalancingStrategy()).isEqualTo(ArangoDefaults.DEFAULT_LOAD_BALANCING_STRATEGY);
29+
assertThat(cfg.getResponseQueueTimeSamples()).isEqualTo(ArangoDefaults.DEFAULT_RESPONSE_QUEUE_TIME_SAMPLES);
30+
assertThat(cfg.getAsyncExecutor()).isNull();
31+
assertThat(cfg.getCompression()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION);
32+
assertThat(cfg.getCompressionThreshold()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION_THRESHOLD);
33+
assertThat(cfg.getCompressionLevel()).isEqualTo(ArangoDefaults.DEFAULT_COMPRESSION_LEVEL);
34+
}
35+
}

driver/src/test/java/mp/ArangoConfigPropertiesMPImpl.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mp;
22

3+
import com.arangodb.Compression;
34
import com.arangodb.Protocol;
45
import com.arangodb.config.ArangoConfigProperties;
56
import com.arangodb.config.HostDescription;
@@ -29,6 +30,9 @@ public final class ArangoConfigPropertiesMPImpl implements ArangoConfigPropertie
2930
private Optional<Integer> acquireHostListInterval;
3031
private Optional<LoadBalancingStrategy> loadBalancingStrategy;
3132
private Optional<Integer> responseQueueTimeSamples;
33+
private Optional<Compression> compression;
34+
private Optional<Integer> compressionThreshold;
35+
private Optional<Integer> compressionLevel;
3236

3337
@Override
3438
public Optional<List<HostDescription>> getHosts() {
@@ -110,17 +114,32 @@ public Optional<Integer> getResponseQueueTimeSamples() {
110114
return responseQueueTimeSamples;
111115
}
112116

117+
@Override
118+
public Optional<Compression> getCompression() {
119+
return compression;
120+
}
121+
122+
@Override
123+
public Optional<Integer> getCompressionThreshold() {
124+
return compressionThreshold;
125+
}
126+
127+
@Override
128+
public Optional<Integer> getCompressionLevel() {
129+
return compressionLevel;
130+
}
131+
113132
@Override
114133
public boolean equals(Object o) {
115134
if (this == o) return true;
116135
if (o == null || getClass() != o.getClass()) return false;
117136
ArangoConfigPropertiesMPImpl that = (ArangoConfigPropertiesMPImpl) o;
118-
return Objects.equals(hosts, that.hosts) && Objects.equals(protocol, that.protocol) && Objects.equals(user, that.user) && Objects.equals(password, that.password) && Objects.equals(jwt, that.jwt) && Objects.equals(timeout, that.timeout) && Objects.equals(useSsl, that.useSsl) && Objects.equals(verifyHost, that.verifyHost) && Objects.equals(chunkSize, that.chunkSize) && Objects.equals(maxConnections, that.maxConnections) && Objects.equals(connectionTtl, that.connectionTtl) && Objects.equals(keepAliveInterval, that.keepAliveInterval) && Objects.equals(acquireHostList, that.acquireHostList) && Objects.equals(acquireHostListInterval, that.acquireHostListInterval) && Objects.equals(loadBalancingStrategy, that.loadBalancingStrategy) && Objects.equals(responseQueueTimeSamples, that.responseQueueTimeSamples);
137+
return Objects.equals(hosts, that.hosts) && Objects.equals(protocol, that.protocol) && Objects.equals(user, that.user) && Objects.equals(password, that.password) && Objects.equals(jwt, that.jwt) && Objects.equals(timeout, that.timeout) && Objects.equals(useSsl, that.useSsl) && Objects.equals(verifyHost, that.verifyHost) && Objects.equals(chunkSize, that.chunkSize) && Objects.equals(maxConnections, that.maxConnections) && Objects.equals(connectionTtl, that.connectionTtl) && Objects.equals(keepAliveInterval, that.keepAliveInterval) && Objects.equals(acquireHostList, that.acquireHostList) && Objects.equals(acquireHostListInterval, that.acquireHostListInterval) && Objects.equals(loadBalancingStrategy, that.loadBalancingStrategy) && Objects.equals(responseQueueTimeSamples, that.responseQueueTimeSamples) && Objects.equals(compression, that.compression) && Objects.equals(compressionThreshold, that.compressionThreshold) && Objects.equals(compressionLevel, that.compressionLevel);
119138
}
120139

121140
@Override
122141
public int hashCode() {
123-
return Objects.hash(hosts, protocol, user, password, jwt, timeout, useSsl, verifyHost, chunkSize, maxConnections, connectionTtl, keepAliveInterval, acquireHostList, acquireHostListInterval, loadBalancingStrategy, responseQueueTimeSamples);
142+
return Objects.hash(hosts, protocol, user, password, jwt, timeout, useSsl, verifyHost, chunkSize, maxConnections, connectionTtl, keepAliveInterval, acquireHostList, acquireHostListInterval, loadBalancingStrategy, responseQueueTimeSamples, compression, compressionThreshold, compressionLevel);
124143
}
125144

126145
@Override
@@ -142,6 +161,9 @@ public String toString() {
142161
", acquireHostListInterval=" + acquireHostListInterval +
143162
", loadBalancingStrategy=" + loadBalancingStrategy +
144163
", responseQueueTimeSamples=" + responseQueueTimeSamples +
164+
", compression=" + compression +
165+
", compressionThreshold=" + compressionThreshold +
166+
", compressionLevel=" + compressionLevel +
145167
'}';
146168
}
147169
}

driver/src/test/java/mp/ConfigMPDefaultsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ private void checkResult(ArangoConfigProperties config) {
3232
assertThat(config.getAcquireHostListInterval()).isEmpty();
3333
assertThat(config.getLoadBalancingStrategy()).isEmpty();
3434
assertThat(config.getResponseQueueTimeSamples()).isEmpty();
35+
assertThat(config.getCompression()).isEmpty();
36+
assertThat(config.getCompressionThreshold()).isNotPresent();
37+
assertThat(config.getCompressionLevel()).isNotPresent();
3538
}
3639

3740
}

driver/src/test/java/mp/ConfigMPTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mp;
22

3+
import com.arangodb.Compression;
34
import com.arangodb.Protocol;
45
import com.arangodb.config.ArangoConfigProperties;
56
import com.arangodb.config.HostDescription;
@@ -29,6 +30,9 @@ class ConfigMPTest {
2930
private final Integer acquireHostListInterval = 1234567;
3031
private final LoadBalancingStrategy loadBalancingStrategy = LoadBalancingStrategy.ROUND_ROBIN;
3132
private final Integer responseQueueTimeSamples = 12345678;
33+
private final Compression compression = Compression.GZIP;
34+
private final Integer compressionThreshold = 123456789;
35+
private final Integer compressionLevel = 9;
3236

3337
@Test
3438
void readConfig() {
@@ -66,5 +70,8 @@ private void checkResult(ArangoConfigProperties config) {
6670
assertThat(config.getAcquireHostListInterval()).hasValue(acquireHostListInterval);
6771
assertThat(config.getLoadBalancingStrategy()).hasValue(loadBalancingStrategy);
6872
assertThat(config.getResponseQueueTimeSamples()).hasValue(responseQueueTimeSamples);
73+
assertThat(config.getCompression()).hasValue(compression);
74+
assertThat(config.getCompressionThreshold()).hasValue(compressionThreshold);
75+
assertThat(config.getCompressionLevel()).hasValue(compressionLevel);
6976
}
7077
}

driver/src/test/resources/arangodb-config-test.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ adb.acquireHostList=true
1414
adb.acquireHostListInterval=1234567
1515
adb.loadBalancingStrategy=ROUND_ROBIN
1616
adb.responseQueueTimeSamples=12345678
17-
17+
adb.compression=GZIP
18+
adb.compressionThreshold=123456789
19+
adb.compressionLevel=9

0 commit comments

Comments
 (0)
0