Skip to content

Commit 0bca476

Browse files
committed
resilience tests: TCP RST
1 parent 8a45a62 commit 0bca476

9 files changed

+117
-106
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import eu.rekawek.toxiproxy.Proxy;
44

55
import java.io.IOException;
6+
import java.util.concurrent.Executors;
7+
import java.util.concurrent.ScheduledExecutorService;
8+
import java.util.concurrent.TimeUnit;
69

710
/**
811
* class representing a proxied db endpoint
@@ -63,12 +66,19 @@ public void enable() {
6366
}
6467
}
6568

66-
public void disable() {
69+
public void disableNow() {
6770
try {
6871
getProxy().disable();
6972
Thread.sleep(100);
7073
} catch (IOException | InterruptedException e) {
74+
e.printStackTrace();
7175
throw new RuntimeException(e);
7276
}
7377
}
78+
79+
public void disable(long delay) {
80+
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
81+
es.schedule(this::disableNow, delay, TimeUnit.MILLISECONDS);
82+
es.shutdown();
83+
}
7484
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ void connectionFailAsync(ArangoDBAsync arangoDB) {
155155
@ParameterizedTest(name = "{index}")
156156
@MethodSource("arangoProvider")
157157
void connectionFailover(ArangoDB arangoDB) {
158-
getEndpoints().get(0).disable();
159-
getEndpoints().get(1).disable();
158+
getEndpoints().get(0).disableNow();
159+
getEndpoints().get(1).disableNow();
160160

161161
arangoDB.getVersion();
162162

@@ -171,8 +171,8 @@ void connectionFailover(ArangoDB arangoDB) {
171171
@ParameterizedTest(name = "{index}")
172172
@MethodSource("asyncArangoProvider")
173173
void connectionFailoverAsync(ArangoDBAsync arangoDB) throws ExecutionException, InterruptedException {
174-
getEndpoints().get(0).disable();
175-
getEndpoints().get(1).disable();
174+
getEndpoints().get(0).disableNow();
175+
getEndpoints().get(1).disableNow();
176176

177177
arangoDB.getVersion().get();
178178

@@ -187,8 +187,8 @@ void connectionFailoverAsync(ArangoDBAsync arangoDB) throws ExecutionException,
187187
@ParameterizedTest(name = "{index}")
188188
@MethodSource("arangoProvider")
189189
void connectionFailoverPost(ArangoDB arangoDB) {
190-
getEndpoints().get(0).disable();
191-
getEndpoints().get(1).disable();
190+
getEndpoints().get(0).disableNow();
191+
getEndpoints().get(1).disableNow();
192192

193193
arangoDB.db().query("RETURN 1", Integer.class);
194194

@@ -203,8 +203,8 @@ void connectionFailoverPost(ArangoDB arangoDB) {
203203
@ParameterizedTest(name = "{index}")
204204
@MethodSource("asyncArangoProvider")
205205
void connectionFailoverPostAsync(ArangoDBAsync arangoDB) throws ExecutionException, InterruptedException {
206-
getEndpoints().get(0).disable();
207-
getEndpoints().get(1).disable();
206+
getEndpoints().get(0).disableNow();
207+
getEndpoints().get(1).disableNow();
208208

209209
arangoDB.db().query("RETURN 1", Integer.class).get();
210210

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

+67-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package resilience.connection;
22

33
import com.arangodb.*;
4+
import eu.rekawek.toxiproxy.model.ToxicDirection;
5+
import eu.rekawek.toxiproxy.model.toxic.ResetPeer;
46
import org.junit.jupiter.params.ParameterizedTest;
57
import org.junit.jupiter.params.provider.EnumSource;
68
import org.junit.jupiter.params.provider.MethodSource;
79
import resilience.SingleServerTest;
810

11+
import java.io.IOException;
912
import java.net.ConnectException;
1013
import java.net.UnknownHostException;
1114
import java.util.stream.Stream;
1215

1316
import static org.assertj.core.api.Assertions.assertThat;
1417
import static org.assertj.core.api.Assertions.catchThrowable;
18+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
1519

1620
/**
1721
* @author Michele Rastelli
@@ -82,8 +86,7 @@ void nameResolutionFailAsync(Protocol protocol) {
8286
@ParameterizedTest(name = "{index}")
8387
@MethodSource("arangoProvider")
8488
void connectionFail(ArangoDB arangoDB) {
85-
getEndpoint().disable();
86-
89+
getEndpoint().disableNow();
8790
Throwable thrown = catchThrowable(arangoDB::getVersion);
8891
assertThat(thrown).isInstanceOf(ArangoDBException.class);
8992
assertThat(thrown.getMessage()).contains("Cannot contact any host");
@@ -98,7 +101,7 @@ void connectionFail(ArangoDB arangoDB) {
98101
@ParameterizedTest(name = "{index}")
99102
@MethodSource("asyncArangoProvider")
100103
void connectionFailAsync(ArangoDBAsync arangoDB) {
101-
getEndpoint().disable();
104+
getEndpoint().disableNow();
102105

103106
Throwable thrown = catchThrowable(() -> arangoDB.getVersion().get()).getCause();
104107
assertThat(thrown).isInstanceOf(ArangoDBException.class);
@@ -144,4 +147,65 @@ void authFailAsync(Protocol protocol) {
144147
adb.shutdown();
145148
}
146149

150+
@ParameterizedTest(name = "{index}")
151+
@MethodSource("arangoProvider")
152+
void connClose(ArangoDB adb) {
153+
getEndpoint().disable(500);
154+
Throwable thrown = catchThrowable(() -> adb.db().query("RETURN SLEEP(1)", Void.class));
155+
assertThat(thrown).isInstanceOf(ArangoDBException.class);
156+
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
157+
adb.shutdown();
158+
}
159+
160+
@ParameterizedTest(name = "{index}")
161+
@MethodSource("asyncArangoProvider")
162+
void connCloseAsync(ArangoDBAsync adb) {
163+
getEndpoint().disable(500);
164+
Throwable thrown = catchThrowable(() -> adb.db().query("RETURN SLEEP(1)", Void.class).get()).getCause();
165+
assertThat(thrown).isInstanceOf(ArangoDBException.class);
166+
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
167+
adb.shutdown();
168+
}
169+
170+
@ParameterizedTest(name = "{index}")
171+
@EnumSource(Protocol.class)
172+
void connReset(Protocol protocol) throws IOException, InterruptedException {
173+
assumeTrue(!protocol.equals(Protocol.VST), "DE-776"); // FIXME
174+
ArangoDB adb = new ArangoDB.Builder()
175+
.host(getEndpoint().getHost(), getEndpoint().getPort())
176+
.protocol(protocol)
177+
.password("test")
178+
.build();
179+
180+
ResetPeer toxic = getEndpoint().getProxy().toxics().resetPeer("reset", ToxicDirection.DOWNSTREAM, 500);
181+
Thread.sleep(100);
182+
183+
Throwable thrown = catchThrowable(() -> adb.db().query("RETURN SLEEP(1)", Void.class));
184+
assertThat(thrown).isInstanceOf(ArangoDBException.class);
185+
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
186+
adb.shutdown();
187+
toxic.remove();
188+
}
189+
190+
@ParameterizedTest(name = "{index}")
191+
@EnumSource(Protocol.class)
192+
void connResetAsync(Protocol protocol) throws IOException, InterruptedException {
193+
assumeTrue(!protocol.equals(Protocol.VST), "DE-776"); // FIXME
194+
ArangoDBAsync adb = new ArangoDB.Builder()
195+
.host(getEndpoint().getHost(), getEndpoint().getPort())
196+
.protocol(protocol)
197+
.password("test")
198+
.build()
199+
.async();
200+
201+
ResetPeer toxic = getEndpoint().getProxy().toxics().resetPeer("reset", ToxicDirection.DOWNSTREAM, 500);
202+
Thread.sleep(100);
203+
204+
Throwable thrown = catchThrowable(() -> adb.db().query("RETURN SLEEP(1)", Void.class).get()).getCause();
205+
assertThat(thrown).isInstanceOf(ArangoDBException.class);
206+
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
207+
adb.shutdown();
208+
toxic.remove();
209+
}
210+
147211
}

resilience-tests/src/test/java/resilience/loadbalance/LoadBalanceNoneClusterTest.java

+9-21
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
import java.io.IOException;
1616
import java.util.List;
17-
import java.util.concurrent.Executors;
18-
import java.util.concurrent.ScheduledExecutorService;
19-
import java.util.concurrent.TimeUnit;
2017
import java.util.stream.Stream;
2118

2219
import static org.assertj.core.api.Assertions.assertThat;
@@ -57,17 +54,17 @@ void loadBalancingAsync(ArangoDBAsync arangoDB) {
5754
void failover(ArangoDB arangoDB) {
5855
List<Endpoint> endpoints = getEndpoints();
5956

60-
endpoints.get(0).disable();
57+
endpoints.get(0).disableNow();
6158
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
6259
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
6360
enableAllEndpoints();
6461

65-
endpoints.get(1).disable();
62+
endpoints.get(1).disableNow();
6663
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
6764
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
6865
enableAllEndpoints();
6966

70-
endpoints.get(2).disable();
67+
endpoints.get(2).disableNow();
7168
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
7269
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
7370
enableAllEndpoints();
@@ -78,17 +75,17 @@ void failover(ArangoDB arangoDB) {
7875
void failoverAsync(ArangoDBAsync arangoDB) {
7976
List<Endpoint> endpoints = getEndpoints();
8077

81-
endpoints.get(0).disable();
78+
endpoints.get(0).disableNow();
8279
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
8380
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
8481
enableAllEndpoints();
8582

86-
endpoints.get(1).disable();
83+
endpoints.get(1).disableNow();
8784
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
8885
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
8986
enableAllEndpoints();
9087

91-
endpoints.get(2).disable();
88+
endpoints.get(2).disableNow();
9289
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
9390
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
9491
enableAllEndpoints();
@@ -106,15 +103,12 @@ void retryGET(ArangoDB arangoDB) throws IOException, InterruptedException {
106103
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
107104
Thread.sleep(100);
108105

109-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
110-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
111-
106+
getEndpoints().get(0).disable(300);
112107
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
113108
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
114109

115110
toxic.remove();
116111
enableAllEndpoints();
117-
es.shutdown();
118112
}
119113

120114

@@ -129,9 +123,7 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
129123
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
130124
Thread.sleep(100);
131125

132-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
133-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
134-
126+
getEndpoints().get(0).disable(300);
135127
Throwable thrown = catchThrowable(() -> serverIdPOST(arangoDB));
136128
assertThat(thrown).isInstanceOf(ArangoDBException.class);
137129
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
@@ -141,7 +133,6 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
141133

142134
toxic.remove();
143135
enableAllEndpoints();
144-
es.shutdown();
145136
}
146137

147138

@@ -156,9 +147,7 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
156147
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
157148
Thread.sleep(100);
158149

159-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
160-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
161-
150+
getEndpoints().get(0).disable(300);
162151
Throwable thrown = catchThrowable(() -> serverIdPOST(arangoDB));
163152
assertThat(thrown).isInstanceOf(ArangoDBException.class);
164153
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
@@ -168,7 +157,6 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
168157

169158
toxic.remove();
170159
enableAllEndpoints();
171-
es.shutdown();
172160
}
173161

174162
}

resilience-tests/src/test/java/resilience/loadbalance/LoadBalanceRoundRobinClusterTest.java

+6-25
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import java.io.IOException;
1616
import java.util.List;
1717
import java.util.concurrent.ExecutionException;
18-
import java.util.concurrent.Executors;
19-
import java.util.concurrent.ScheduledExecutorService;
20-
import java.util.concurrent.TimeUnit;
2118
import java.util.stream.Stream;
2219

2320
import static org.assertj.core.api.Assertions.assertThat;
@@ -61,7 +58,7 @@ void loadBalancingAsync(ArangoDBAsync arangoDB) {
6158
@MethodSource("arangoProvider")
6259
void failover(ArangoDB arangoDB) {
6360
List<Endpoint> endpoints = getEndpoints();
64-
endpoints.get(0).disable();
61+
endpoints.get(0).disableNow();
6562
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
6663
endpoints.get(0).enable();
6764
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
@@ -72,7 +69,7 @@ void failover(ArangoDB arangoDB) {
7269
@MethodSource("asyncArangoProvider")
7370
void failoverAsync(ArangoDBAsync arangoDB) {
7471
List<Endpoint> endpoints = getEndpoints();
75-
endpoints.get(0).disable();
72+
endpoints.get(0).disableNow();
7673
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
7774
endpoints.get(0).enable();
7875
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
@@ -88,18 +85,14 @@ void retryGET(ArangoDB arangoDB) throws IOException, InterruptedException {
8885
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
8986
Thread.sleep(100);
9087

91-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
92-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
93-
88+
getEndpoints().get(0).disable(300);
9489
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
9590
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
9691

9792
toxic.remove();
9893
enableAllEndpoints();
9994

10095
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
101-
102-
es.shutdown();
10396
}
10497

10598
@ParameterizedTest(name = "{index}")
@@ -111,18 +104,14 @@ void retryGETAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcept
111104
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
112105
Thread.sleep(100);
113106

114-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
115-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
116-
107+
getEndpoints().get(0).disable(300);
117108
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(1).getServerId());
118109
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(2).getServerId());
119110

120111
toxic.remove();
121112
enableAllEndpoints();
122113

123114
assertThat(serverIdGET(arangoDB)).isEqualTo(endpoints.get(0).getServerId());
124-
125-
es.shutdown();
126115
}
127116

128117
@ParameterizedTest(name = "{index}")
@@ -137,9 +126,7 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
137126
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
138127
Thread.sleep(100);
139128

140-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
141-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
142-
129+
getEndpoints().get(0).disable(300);
143130
Throwable thrown = catchThrowable(() -> serverIdPOST(arangoDB));
144131
assertThat(thrown).isInstanceOf(ArangoDBException.class);
145132
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
@@ -151,8 +138,6 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
151138
enableAllEndpoints();
152139

153140
assertThat(serverIdPOST(arangoDB)).isEqualTo(getEndpoints().get(0).getServerId());
154-
155-
es.shutdown();
156141
}
157142

158143
@ParameterizedTest(name = "{index}")
@@ -167,9 +152,7 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
167152
Latency toxic = getEndpoints().get(0).getProxy().toxics().latency("latency", ToxicDirection.DOWNSTREAM, 10_000);
168153
Thread.sleep(100);
169154

170-
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
171-
es.schedule(() -> getEndpoints().get(0).disable(), 300, TimeUnit.MILLISECONDS);
172-
155+
getEndpoints().get(0).disable(300);
173156
Throwable thrown = catchThrowable(() -> serverIdPOST(arangoDB));
174157
assertThat(thrown).isInstanceOf(ArangoDBException.class);
175158
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
@@ -181,8 +164,6 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
181164
enableAllEndpoints();
182165

183166
assertThat(serverIdPOST(arangoDB)).isEqualTo(getEndpoints().get(0).getServerId());
184-
185-
es.shutdown();
186167
}
187168

188169
}

0 commit comments

Comments
 (0)