Skip to content

Commit 6f0edb4

Browse files
committed
resilience tests: disabled VST for ADB 3.12
1 parent deb5c43 commit 6f0edb4

19 files changed

+222
-166
lines changed

resilience-tests/src/test/java/resilience/ClusterTest.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.arangodb.ArangoDB;
44
import com.arangodb.ArangoDBAsync;
5+
import com.arangodb.Protocol;
56
import com.arangodb.Request;
67
import com.fasterxml.jackson.databind.node.ObjectNode;
78
import eu.rekawek.toxiproxy.Proxy;
@@ -10,23 +11,20 @@
1011
import org.junit.jupiter.api.BeforeAll;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Tag;
13-
import resilience.utils.MemoryAppender;
1414

1515
import java.io.IOException;
1616
import java.util.Arrays;
1717
import java.util.List;
1818
import java.util.concurrent.ExecutionException;
19+
import java.util.stream.Stream;
1920

2021
@Tag("cluster")
21-
public abstract class ClusterTest {
22+
public abstract class ClusterTest extends TestUtils {
2223

23-
protected static final String HOST = "127.0.0.1";
24-
protected static final String PASSWORD = "test";
25-
protected static final MemoryAppender logs = new MemoryAppender();
2624
private static final List<Endpoint> endpoints = Arrays.asList(
27-
new Endpoint("cluster1", HOST, 18529, "172.28.0.1:8529"),
28-
new Endpoint("cluster2", HOST, 18539, "172.28.0.1:8539"),
29-
new Endpoint("cluster3", HOST, 18549, "172.28.0.1:8549")
25+
new Endpoint("cluster1", HOST, 18529, UPSTREAM_GW + ":8529"),
26+
new Endpoint("cluster2", HOST, 18539, UPSTREAM_GW + ":8539"),
27+
new Endpoint("cluster3", HOST, 18549, UPSTREAM_GW + ":8549")
3028
);
3129

3230
@BeforeAll
@@ -61,12 +59,29 @@ protected static List<Endpoint> getEndpoints() {
6159

6260
protected static ArangoDB.Builder dbBuilder() {
6361
ArangoDB.Builder builder = new ArangoDB.Builder();
64-
for (Endpoint endpoint : endpoints) {
62+
for (Endpoint endpoint : getEndpoints()) {
6563
builder.host(endpoint.getHost(), endpoint.getPort());
6664
}
6765
return builder.password(PASSWORD);
6866
}
6967

68+
protected static Stream<Protocol> protocolProvider() {
69+
return Stream.of(Protocol.values())
70+
.filter(p -> !p.equals(Protocol.VST) || isLessThanVersion(3, 12));
71+
}
72+
73+
protected static Stream<ArangoDB.Builder> builderProvider() {
74+
return protocolProvider().map(p -> dbBuilder().protocol(p));
75+
}
76+
77+
protected static Stream<ArangoDB> adbProvider() {
78+
return builderProvider().map(ArangoDB.Builder::build);
79+
}
80+
81+
protected static Stream<ArangoDBAsync> asyncAdbProvider() {
82+
return adbProvider().map(ArangoDB::async);
83+
}
84+
7085
protected static String serverIdGET(ArangoDB adb) {
7186
return adb.execute(Request.builder()
7287
.method(Request.Method.GET)

resilience-tests/src/test/java/resilience/SingleServerTest.java

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

33
import com.arangodb.ArangoDB;
4-
import resilience.utils.MemoryAppender;
4+
import com.arangodb.ArangoDBAsync;
5+
import com.arangodb.Protocol;
56
import eu.rekawek.toxiproxy.Proxy;
67
import eu.rekawek.toxiproxy.ToxiproxyClient;
78
import org.junit.jupiter.api.AfterAll;
@@ -10,14 +11,12 @@
1011
import org.junit.jupiter.api.Tag;
1112

1213
import java.io.IOException;
14+
import java.util.stream.Stream;
1315

1416
@Tag("singleServer")
15-
public abstract class SingleServerTest {
17+
public abstract class SingleServerTest extends TestUtils {
1618

17-
protected static final String HOST = "127.0.0.1";
18-
protected static final String PASSWORD = "test";
19-
protected static final MemoryAppender logs = new MemoryAppender();
20-
private static final Endpoint endpoint = new Endpoint("singleServer", HOST, 18529, "172.28.0.1:8529");
19+
private static final Endpoint endpoint = new Endpoint("singleServer", HOST, 18529, UPSTREAM_GW + ":8529");
2120

2221
@BeforeAll
2322
static void beforeAll() throws IOException {
@@ -50,4 +49,21 @@ protected static ArangoDB.Builder dbBuilder() {
5049
.password(PASSWORD);
5150
}
5251

52+
protected static Stream<Protocol> protocolProvider() {
53+
return Stream.of(Protocol.values())
54+
.filter(p -> !p.equals(Protocol.VST) || isLessThanVersion(3, 12));
55+
}
56+
57+
protected static Stream<ArangoDB.Builder> builderProvider() {
58+
return protocolProvider().map(p -> dbBuilder().protocol(p));
59+
}
60+
61+
protected static Stream<ArangoDB> adbProvider() {
62+
return builderProvider().map(ArangoDB.Builder::build);
63+
}
64+
65+
protected static Stream<ArangoDBAsync> asyncAdbProvider() {
66+
return adbProvider().map(ArangoDB::async);
67+
}
68+
5369
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package resilience;
22+
23+
24+
import com.arangodb.ArangoDB;
25+
import com.arangodb.entity.ArangoDBVersion;
26+
import resilience.utils.MemoryAppender;
27+
28+
/**
29+
* @author Michele Rastelli
30+
*/
31+
public abstract class TestUtils {
32+
33+
protected static final String HOST = "127.0.0.1";
34+
protected static final String UPSTREAM_GW = "172.28.0.1";
35+
protected static final String PASSWORD = "test";
36+
protected static final MemoryAppender logs = new MemoryAppender();
37+
private static final ArangoDBVersion version = new ArangoDB.Builder()
38+
.host(UPSTREAM_GW, 8529)
39+
.password(PASSWORD)
40+
.build()
41+
.getVersion();
42+
43+
protected static boolean isAtLeastVersion(final int major, final int minor) {
44+
return isAtLeastVersion(major, minor, 0);
45+
}
46+
47+
protected static boolean isAtLeastVersion(final int major, final int minor, final int patch) {
48+
return isAtLeastVersion(version.getVersion(), major, minor, patch);
49+
}
50+
51+
protected static boolean isLessThanVersion(final int major, final int minor) {
52+
return isLessThanVersion(major, minor, 0);
53+
}
54+
55+
protected static boolean isLessThanVersion(final int major, final int minor, final int patch) {
56+
return isLessThanVersion(version.getVersion(), major, minor, patch);
57+
}
58+
59+
/**
60+
* Parses {@param version} and checks whether it is greater or equal to <{@param otherMajor}, {@param otherMinor},
61+
* {@param otherPatch}> comparing the corresponding version components in lexicographical order.
62+
*/
63+
private static boolean isAtLeastVersion(final String version, final int otherMajor, final int otherMinor,
64+
final int otherPatch) {
65+
return compareVersion(version, otherMajor, otherMinor, otherPatch) >= 0;
66+
}
67+
68+
/**
69+
* Parses {@param version} and checks whether it is less than <{@param otherMajor}, {@param otherMinor},
70+
* {@param otherPatch}> comparing the corresponding version components in lexicographical order.
71+
*/
72+
private static boolean isLessThanVersion(final String version, final int otherMajor, final int otherMinor,
73+
final int otherPatch) {
74+
return compareVersion(version, otherMajor, otherMinor, otherPatch) < 0;
75+
}
76+
77+
private static int compareVersion(final String version, final int otherMajor, final int otherMinor,
78+
final int otherPatch) {
79+
String[] parts = version.split("-")[0].split("\\.");
80+
81+
int major = Integer.parseInt(parts[0]);
82+
int minor = Integer.parseInt(parts[1]);
83+
int patch = Integer.parseInt(parts[2]);
84+
85+
int majorComparison = Integer.compare(major, otherMajor);
86+
if (majorComparison != 0) {
87+
return majorComparison;
88+
}
89+
90+
int minorComparison = Integer.compare(minor, otherMinor);
91+
if (minorComparison != 0) {
92+
return minorComparison;
93+
}
94+
95+
return Integer.compare(patch, otherPatch);
96+
}
97+
98+
}

resilience-tests/src/test/java/resilience/compression/CompressionTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.arangodb.Compression;
66
import com.arangodb.Protocol;
77
import org.junit.jupiter.params.ParameterizedTest;
8-
import org.junit.jupiter.params.provider.EnumSource;
8+
import org.junit.jupiter.params.provider.MethodSource;
99
import resilience.ClusterTest;
1010

1111
import java.util.Collections;
@@ -24,21 +24,27 @@
2424
class CompressionTest extends ClusterTest {
2525

2626
@ParameterizedTest
27-
@EnumSource(Protocol.class)
27+
@MethodSource("protocolProvider")
2828
void gzip(Protocol protocol) {
2929
doTest(protocol, Compression.GZIP);
3030
}
3131

3232
@ParameterizedTest
33-
@EnumSource(Protocol.class)
33+
@MethodSource("protocolProvider")
3434
void deflate(Protocol protocol) {
3535
doTest(protocol, Compression.DEFLATE);
3636
}
3737

3838
void doTest(Protocol protocol, Compression compression) {
39-
assumeTrue(protocol != Protocol.VST, "VST does not support compression");
40-
assumeTrue(protocol != Protocol.HTTP_VPACK, "hex dumps logs");
41-
assumeTrue(protocol != Protocol.HTTP_JSON, "hex dumps logs");
39+
assumeTrue(isAtLeastVersion(3, 12));
40+
assumeTrue(protocol != Protocol.VST);
41+
42+
assumeTrue(protocol != Protocol.HTTP_VPACK, "hex dumps logs"); // FIXME
43+
assumeTrue(protocol != Protocol.HTTP_JSON, "hex dumps logs"); // FIXME
44+
45+
// FIXME:
46+
// When using HTTP_VPACK or HTTP_JSON, the logs are hex dumps.
47+
// Implement a way to check the content-encoding and accept-encoding headers from these logs.
4248

4349
ArangoDB adb = dbBuilder()
4450
.protocol(protocol)

resilience-tests/src/test/java/resilience/connection/AcquireHostListTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.arangodb.entity.LoadBalancingStrategy;
66
import org.junit.jupiter.params.ParameterizedTest;
77
import org.junit.jupiter.params.provider.EnumSource;
8+
import org.junit.jupiter.params.provider.MethodSource;
89
import resilience.ClusterTest;
910
import resilience.Endpoint;
1011

@@ -17,7 +18,7 @@
1718
public class AcquireHostListTest extends ClusterTest {
1819

1920
@ParameterizedTest(name = "{index}")
20-
@EnumSource(Protocol.class)
21+
@MethodSource("protocolProvider")
2122
void acquireHostList(Protocol protocol) {
2223
ArangoDB adb = new ArangoDB.Builder()
2324
.host("127.0.0.1", 8529)

resilience-tests/src/test/java/resilience/connection/ConnectionClusterTest.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.net.ConnectException;
1010
import java.net.UnknownHostException;
1111
import java.util.concurrent.ExecutionException;
12-
import java.util.stream.Stream;
1312

1413
import static org.assertj.core.api.Assertions.assertThat;
1514
import static org.assertj.core.api.Assertions.catchThrowable;
@@ -19,26 +18,6 @@
1918
*/
2019
class ConnectionClusterTest extends ClusterTest {
2120

22-
static Stream<Protocol> protocolProvider() {
23-
return Stream.of(
24-
Protocol.VST,
25-
Protocol.HTTP_VPACK,
26-
Protocol.HTTP2_VPACK
27-
);
28-
}
29-
30-
static Stream<ArangoDB> arangoProvider() {
31-
return Stream.of(
32-
dbBuilder().protocol(Protocol.VST).build(),
33-
dbBuilder().protocol(Protocol.HTTP_VPACK).build(),
34-
dbBuilder().protocol(Protocol.HTTP2_JSON).build()
35-
);
36-
}
37-
38-
static Stream<ArangoDBAsync> asyncArangoProvider() {
39-
return arangoProvider().map(ArangoDB::async);
40-
}
41-
4221
@ParameterizedTest
4322
@MethodSource("protocolProvider")
4423
void nameResolutionFail(Protocol protocol) {
@@ -120,7 +99,7 @@ void nameResolutionFailoverAsync(Protocol protocol) throws ExecutionException, I
12099
}
121100

122101
@ParameterizedTest(name = "{index}")
123-
@MethodSource("arangoProvider")
102+
@MethodSource("adbProvider")
124103
void connectionFail(ArangoDB arangoDB) {
125104
disableAllEndpoints();
126105

@@ -137,7 +116,7 @@ void connectionFail(ArangoDB arangoDB) {
137116
}
138117

139118
@ParameterizedTest(name = "{index}")
140-
@MethodSource("asyncArangoProvider")
119+
@MethodSource("asyncAdbProvider")
141120
void connectionFailAsync(ArangoDBAsync arangoDB) {
142121
disableAllEndpoints();
143122

@@ -153,7 +132,7 @@ void connectionFailAsync(ArangoDBAsync arangoDB) {
153132
}
154133

155134
@ParameterizedTest(name = "{index}")
156-
@MethodSource("arangoProvider")
135+
@MethodSource("adbProvider")
157136
void connectionFailover(ArangoDB arangoDB) {
158137
getEndpoints().get(0).disableNow();
159138
getEndpoints().get(1).disableNow();
@@ -169,7 +148,7 @@ void connectionFailover(ArangoDB arangoDB) {
169148
}
170149

171150
@ParameterizedTest(name = "{index}")
172-
@MethodSource("asyncArangoProvider")
151+
@MethodSource("asyncAdbProvider")
173152
void connectionFailoverAsync(ArangoDBAsync arangoDB) throws ExecutionException, InterruptedException {
174153
getEndpoints().get(0).disableNow();
175154
getEndpoints().get(1).disableNow();
@@ -185,7 +164,7 @@ void connectionFailoverAsync(ArangoDBAsync arangoDB) throws ExecutionException,
185164
}
186165

187166
@ParameterizedTest(name = "{index}")
188-
@MethodSource("arangoProvider")
167+
@MethodSource("adbProvider")
189168
void connectionFailoverPost(ArangoDB arangoDB) {
190169
getEndpoints().get(0).disableNow();
191170
getEndpoints().get(1).disableNow();
@@ -201,7 +180,7 @@ void connectionFailoverPost(ArangoDB arangoDB) {
201180
}
202181

203182
@ParameterizedTest(name = "{index}")
204-
@MethodSource("asyncArangoProvider")
183+
@MethodSource("asyncAdbProvider")
205184
void connectionFailoverPostAsync(ArangoDBAsync arangoDB) throws ExecutionException, InterruptedException {
206185
getEndpoints().get(0).disableNow();
207186
getEndpoints().get(1).disableNow();

0 commit comments

Comments
 (0)