15
15
import java .io .IOException ;
16
16
import java .util .List ;
17
17
import java .util .concurrent .ExecutionException ;
18
- import java .util .concurrent .Executors ;
19
- import java .util .concurrent .ScheduledExecutorService ;
20
- import java .util .concurrent .TimeUnit ;
21
18
import java .util .stream .Stream ;
22
19
23
20
import static org .assertj .core .api .Assertions .assertThat ;
@@ -61,7 +58,7 @@ void loadBalancingAsync(ArangoDBAsync arangoDB) {
61
58
@ MethodSource ("arangoProvider" )
62
59
void failover (ArangoDB arangoDB ) {
63
60
List <Endpoint > endpoints = getEndpoints ();
64
- endpoints .get (0 ).disable ();
61
+ endpoints .get (0 ).disableNow ();
65
62
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (1 ).getServerId ());
66
63
endpoints .get (0 ).enable ();
67
64
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (2 ).getServerId ());
@@ -72,7 +69,7 @@ void failover(ArangoDB arangoDB) {
72
69
@ MethodSource ("asyncArangoProvider" )
73
70
void failoverAsync (ArangoDBAsync arangoDB ) {
74
71
List <Endpoint > endpoints = getEndpoints ();
75
- endpoints .get (0 ).disable ();
72
+ endpoints .get (0 ).disableNow ();
76
73
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (1 ).getServerId ());
77
74
endpoints .get (0 ).enable ();
78
75
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (2 ).getServerId ());
@@ -88,18 +85,14 @@ void retryGET(ArangoDB arangoDB) throws IOException, InterruptedException {
88
85
Latency toxic = getEndpoints ().get (0 ).getProxy ().toxics ().latency ("latency" , ToxicDirection .DOWNSTREAM , 10_000 );
89
86
Thread .sleep (100 );
90
87
91
- ScheduledExecutorService es = Executors .newSingleThreadScheduledExecutor ();
92
- es .schedule (() -> getEndpoints ().get (0 ).disable (), 300 , TimeUnit .MILLISECONDS );
93
-
88
+ getEndpoints ().get (0 ).disable (300 );
94
89
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (1 ).getServerId ());
95
90
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (2 ).getServerId ());
96
91
97
92
toxic .remove ();
98
93
enableAllEndpoints ();
99
94
100
95
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (0 ).getServerId ());
101
-
102
- es .shutdown ();
103
96
}
104
97
105
98
@ ParameterizedTest (name = "{index}" )
@@ -111,18 +104,14 @@ void retryGETAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcept
111
104
Latency toxic = getEndpoints ().get (0 ).getProxy ().toxics ().latency ("latency" , ToxicDirection .DOWNSTREAM , 10_000 );
112
105
Thread .sleep (100 );
113
106
114
- ScheduledExecutorService es = Executors .newSingleThreadScheduledExecutor ();
115
- es .schedule (() -> getEndpoints ().get (0 ).disable (), 300 , TimeUnit .MILLISECONDS );
116
-
107
+ getEndpoints ().get (0 ).disable (300 );
117
108
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (1 ).getServerId ());
118
109
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (2 ).getServerId ());
119
110
120
111
toxic .remove ();
121
112
enableAllEndpoints ();
122
113
123
114
assertThat (serverIdGET (arangoDB )).isEqualTo (endpoints .get (0 ).getServerId ());
124
-
125
- es .shutdown ();
126
115
}
127
116
128
117
@ ParameterizedTest (name = "{index}" )
@@ -137,9 +126,7 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
137
126
Latency toxic = getEndpoints ().get (0 ).getProxy ().toxics ().latency ("latency" , ToxicDirection .DOWNSTREAM , 10_000 );
138
127
Thread .sleep (100 );
139
128
140
- ScheduledExecutorService es = Executors .newSingleThreadScheduledExecutor ();
141
- es .schedule (() -> getEndpoints ().get (0 ).disable (), 300 , TimeUnit .MILLISECONDS );
142
-
129
+ getEndpoints ().get (0 ).disable (300 );
143
130
Throwable thrown = catchThrowable (() -> serverIdPOST (arangoDB ));
144
131
assertThat (thrown ).isInstanceOf (ArangoDBException .class );
145
132
assertThat (thrown .getCause ()).isInstanceOf (IOException .class );
@@ -151,8 +138,6 @@ void retryPOST(ArangoDB arangoDB) throws IOException, InterruptedException {
151
138
enableAllEndpoints ();
152
139
153
140
assertThat (serverIdPOST (arangoDB )).isEqualTo (getEndpoints ().get (0 ).getServerId ());
154
-
155
- es .shutdown ();
156
141
}
157
142
158
143
@ ParameterizedTest (name = "{index}" )
@@ -167,9 +152,7 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
167
152
Latency toxic = getEndpoints ().get (0 ).getProxy ().toxics ().latency ("latency" , ToxicDirection .DOWNSTREAM , 10_000 );
168
153
Thread .sleep (100 );
169
154
170
- ScheduledExecutorService es = Executors .newSingleThreadScheduledExecutor ();
171
- es .schedule (() -> getEndpoints ().get (0 ).disable (), 300 , TimeUnit .MILLISECONDS );
172
-
155
+ getEndpoints ().get (0 ).disable (300 );
173
156
Throwable thrown = catchThrowable (() -> serverIdPOST (arangoDB ));
174
157
assertThat (thrown ).isInstanceOf (ArangoDBException .class );
175
158
assertThat (thrown .getCause ()).isInstanceOf (IOException .class );
@@ -181,8 +164,6 @@ void retryPOSTAsync(ArangoDBAsync arangoDB) throws IOException, InterruptedExcep
181
164
enableAllEndpoints ();
182
165
183
166
assertThat (serverIdPOST (arangoDB )).isEqualTo (getEndpoints ().get (0 ).getServerId ());
184
-
185
- es .shutdown ();
186
167
}
187
168
188
169
}
0 commit comments