Skip to content

Commit 3e80267

Browse files
committed
fixed resilience tests
1 parent 6740948 commit 3e80267

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

Diff for: core/src/main/java/com/arangodb/internal/net/DirtyReadHostHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public Host get(final HostHandle hostHandle, final AccessType accessType) {
5353
}
5454

5555
@Override
56-
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
56+
public void checkNext(HostHandle hostHandle, AccessType accessType) {
5757
this.currentAccessType = accessType;
58-
return determineHostHandler().hasNext(hostHandle, accessType);
58+
determineHostHandler().checkNext(hostHandle, accessType);
5959
}
6060

6161
@Override

Diff for: core/src/main/java/com/arangodb/internal/net/FallbackHostHandler.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,20 @@ public FallbackHostHandler(final HostResolver resolver) {
4949

5050
@Override
5151
public Host get(final HostHandle hostHandle, AccessType accessType) {
52-
if (hasNext(hostHandle, accessType)) {
53-
return current;
54-
} else {
52+
checkNext(hostHandle, accessType);
53+
return current;
54+
}
55+
56+
@Override
57+
public void checkNext(HostHandle hostHandle, AccessType accessType) {
58+
if (current == lastSuccess && iterations >= 3) {
5559
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
5660
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
5761
reset();
5862
throw e;
5963
}
6064
}
6165

62-
@Override
63-
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
64-
return current != lastSuccess || iterations < 3;
65-
}
66-
6766
@Override
6867
public void success() {
6968
lastSuccess = current;

Diff for: core/src/main/java/com/arangodb/internal/net/HostHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface HostHandler {
3131

3232
Host get(HostHandle hostHandle, AccessType accessType);
3333

34-
boolean hasNext(HostHandle hostHandle, AccessType accessType);
34+
void checkNext(HostHandle hostHandle, AccessType accessType);
3535

3636
void success();
3737

Diff for: core/src/main/java/com/arangodb/internal/net/RandomHostHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
5353
}
5454

5555
@Override
56-
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
57-
return true;
56+
public void checkNext(HostHandle hostHandle, AccessType accessType) {
5857
}
5958

6059
@Override

Diff for: core/src/main/java/com/arangodb/internal/net/RoundRobinHostHandler.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,8 @@ public RoundRobinHostHandler(final HostResolver resolver) {
5353

5454
@Override
5555
public Host get(final HostHandle hostHandle, AccessType accessType) {
56-
hosts = resolver.getHosts();
56+
checkNext(hostHandle, accessType);
5757
final int size = hosts.getHostsList().size();
58-
59-
if (fails > size) {
60-
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
61-
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
62-
reset();
63-
throw e;
64-
}
65-
6658
final int index = (int) ((current++) % size);
6759
Host host = hosts.getHostsList().get(index);
6860
if (hostHandle != null) {
@@ -83,10 +75,16 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
8375
}
8476

8577
@Override
86-
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
78+
public void checkNext(HostHandle hostHandle, AccessType accessType) {
8779
hosts = resolver.getHosts();
88-
int size = hosts.getHostsList().size();
89-
return fails <= size;
80+
final int size = hosts.getHostsList().size();
81+
82+
if (fails > size) {
83+
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
84+
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
85+
reset();
86+
throw e;
87+
}
9088
}
9189

9290
@Override

Diff for: http/src/main/java/com/arangodb/http/HttpCommunication.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ private void handleException(boolean isSafe, Throwable e, HostHandle hostHandle,
134134
if (hostHandle != null && hostHandle.getHost() != null) {
135135
hostHandle.setHost(null);
136136
}
137-
boolean hasNextHost = hostHandler.hasNext(hostHandle, RequestUtils.determineAccessType(request));
138-
if (hasNextHost && isSafe) {
137+
hostHandler.checkNext(hostHandle, RequestUtils.determineAccessType(request));
138+
if (isSafe) {
139139
Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request));
140140
LOGGER.warn("Could not connect to {} while executing request [id={}]",
141141
host.getDescription(), reqId, ioEx);

0 commit comments

Comments
 (0)