Skip to content

Commit 5709a97

Browse files
authored
Fixed host handler failures count (#398)
* fixed host handler failures count * fixed host handler tests
1 parent aeb8c5e commit 5709a97

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/main/java/com/arangodb/internal/net/FallbackHostHandler.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
5555
@Override
5656
public void success() {
5757
lastSuccess = current;
58+
iterations = 0;
5859
}
5960

6061
@Override

src/main/java/com/arangodb/internal/net/RandomHostHandler.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,26 @@ public class RandomHostHandler implements HostHandler {
3030

3131
private final HostResolver resolver;
3232
private final HostHandler fallback;
33-
private Host origin;
3433
private Host current;
3534

3635
public RandomHostHandler(final HostResolver resolver, final HostHandler fallback) {
3736
super();
3837
this.resolver = resolver;
3938
this.fallback = fallback;
40-
origin = current = getRandomHost(true, false);
39+
current = getRandomHost(true, false);
4140
}
4241

4342
@Override
4443
public Host get(final HostHandle hostHandle, AccessType accessType) {
4544
if (current == null) {
46-
origin = current = getRandomHost(false, true);
45+
current = getRandomHost(false, true);
4746
}
4847
return current;
4948
}
5049

5150
@Override
5251
public void success() {
53-
current = origin;
52+
fallback.success();
5453
}
5554

5655
@Override
@@ -60,7 +59,6 @@ public void fail() {
6059
}
6160

6261
private Host getRandomHost(final boolean initial, final boolean closeConnections) {
63-
6462
final ArrayList<Host> hosts = new ArrayList<>(resolver.resolve(initial, closeConnections).getHostsList());
6563
Collections.shuffle(hosts);
6664
return hosts.get(0);

src/main/java/com/arangodb/internal/velocystream/VstCommunication.java

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected synchronized C connect(final HostHandle hostHandle, final AccessType a
8383
}
8484
final C connection = (C) host.connection();
8585
if (connection.isOpen()) {
86+
hostHandler.success();
8687
return connection;
8788
} else {
8889
try {

src/test/java/com/arangodb/internal/HostHandlerTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ public void randomHostHandlerSingleHost() {
117117
@Test
118118
public void randomHostHandlerMultipeHosts() {
119119
final HostHandler handler = new RandomHostHandler(MULTIPLE_HOSTS, new FallbackHostHandler(MULTIPLE_HOSTS));
120+
120121
final Host pick0 = handler.get(null, null);
121122
assertThat(pick0, anyOf(is(HOST_0), is(HOST_1), is(HOST_2)));
122123
handler.fail();
123-
assertThat(handler.get(null, null), anyOf(is(HOST_0), is(HOST_1), is(HOST_2)));
124+
125+
final Host pick1 = handler.get(null, null);
126+
assertThat(pick1, anyOf(is(HOST_0), is(HOST_1), is(HOST_2)));
124127
handler.success();
125-
assertThat(handler.get(null, null), is(pick0));
128+
129+
final Host pick3 = handler.get(null, null);
130+
assertThat(pick3, anyOf(is(HOST_0), is(HOST_1), is(HOST_2)));
131+
assertThat(pick3, is(pick1));
126132
}
127133

128134
@Test

0 commit comments

Comments
 (0)