Skip to content

Commit

Permalink
fixed resilience tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Nov 30, 2023
1 parent 6740948 commit 3e80267
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public Host get(final HostHandle hostHandle, final AccessType accessType) {
}

@Override
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
public void checkNext(HostHandle hostHandle, AccessType accessType) {
this.currentAccessType = accessType;
return determineHostHandler().hasNext(hostHandle, accessType);
determineHostHandler().checkNext(hostHandle, accessType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@ public FallbackHostHandler(final HostResolver resolver) {

@Override
public Host get(final HostHandle hostHandle, AccessType accessType) {
if (hasNext(hostHandle, accessType)) {
return current;
} else {
checkNext(hostHandle, accessType);
return current;
}

@Override
public void checkNext(HostHandle hostHandle, AccessType accessType) {
if (current == lastSuccess && iterations >= 3) {
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
reset();
throw e;
}
}

@Override
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
return current != lastSuccess || iterations < 3;
}

@Override
public void success() {
lastSuccess = current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface HostHandler {

Host get(HostHandle hostHandle, AccessType accessType);

boolean hasNext(HostHandle hostHandle, AccessType accessType);
void checkNext(HostHandle hostHandle, AccessType accessType);

void success();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
}

@Override
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
return true;
public void checkNext(HostHandle hostHandle, AccessType accessType) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,8 @@ public RoundRobinHostHandler(final HostResolver resolver) {

@Override
public Host get(final HostHandle hostHandle, AccessType accessType) {
hosts = resolver.getHosts();
checkNext(hostHandle, accessType);
final int size = hosts.getHostsList().size();

if (fails > size) {
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
reset();
throw e;
}

final int index = (int) ((current++) % size);
Host host = hosts.getHostsList().get(index);
if (hostHandle != null) {
Expand All @@ -83,10 +75,16 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
}

@Override
public boolean hasNext(HostHandle hostHandle, AccessType accessType) {
public void checkNext(HostHandle hostHandle, AccessType accessType) {
hosts = resolver.getHosts();
int size = hosts.getHostsList().size();
return fails <= size;
final int size = hosts.getHostsList().size();

if (fails > size) {
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
reset();
throw e;
}
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions http/src/main/java/com/arangodb/http/HttpCommunication.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ private void handleException(boolean isSafe, Throwable e, HostHandle hostHandle,
if (hostHandle != null && hostHandle.getHost() != null) {
hostHandle.setHost(null);
}
boolean hasNextHost = hostHandler.hasNext(hostHandle, RequestUtils.determineAccessType(request));
if (hasNextHost && isSafe) {
hostHandler.checkNext(hostHandle, RequestUtils.determineAccessType(request));
if (isSafe) {
Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request));
LOGGER.warn("Could not connect to {} while executing request [id={}]",
host.getDescription(), reqId, ioEx);
Expand Down

0 comments on commit 3e80267

Please sign in to comment.