Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ jobs:
name: Analyze
runs-on: ubuntu-latest

defaults:
run:
working-directory: driver

permissions:
actions: read
contents: read
Expand Down Expand Up @@ -66,6 +62,7 @@ jobs:
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
working-directory: driver

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -79,3 +76,4 @@ jobs:

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
working-directory: driver
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.arangodb.internal.net;

import com.arangodb.ArangoDBException;
import com.arangodb.internal.velocystream.internal.VstConnection;
import com.arangodb.internal.velocystream.internal.VstConnectionSync;
import org.slf4j.Logger;
Expand All @@ -42,6 +43,7 @@ public class ConnectionPoolImpl implements ConnectionPool {
private final ConnectionFactory factory;
private int current;
private volatile String jwt = null;
private boolean closed = false;

public ConnectionPoolImpl(final HostDescription host, final Integer maxConnections,
final ConnectionFactory factory) {
Expand All @@ -62,6 +64,9 @@ public Connection createConnection(final HostDescription host) {

@Override
public synchronized Connection connection() {
if (closed) {
throw new ArangoDBException("Connection pool already closed!");
}

final Connection connection;

Expand Down Expand Up @@ -91,6 +96,7 @@ public void setJwt(String jwt) {

@Override
public synchronized void close() throws IOException {
closed = true;
for (final Connection connection : connections) {
connection.close();
}
Expand Down
11 changes: 5 additions & 6 deletions resilience-tests/src/test/java/resilience/retry/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class RetryTest extends SingleServerTest {

static Stream<ArangoDB> arangoProvider() {
return Stream.of(
dbBuilder().timeout(1_000).useProtocol(Protocol.VST).build(),
dbBuilder().timeout(1_000).useProtocol(Protocol.HTTP_VPACK).build(),
dbBuilder().timeout(1_000).useProtocol(Protocol.HTTP2_VPACK).build()
dbBuilder().useProtocol(Protocol.VST).build(),
dbBuilder().useProtocol(Protocol.HTTP_VPACK).build(),
dbBuilder().useProtocol(Protocol.HTTP2_VPACK).build()
);
}

Expand All @@ -57,9 +57,8 @@ void unreachableHost(ArangoDB arangoDB) {
assertThat(thrown.getMessage()).contains("Cannot contact any host");
assertThat(thrown.getCause()).isNotNull();
assertThat(thrown.getCause()).isInstanceOf(ArangoDBMultipleException.class);
((ArangoDBMultipleException) thrown.getCause()).getExceptions().forEach(e -> {
assertThat(e).isInstanceOf(ConnectException.class);
});
((ArangoDBMultipleException) thrown.getCause()).getExceptions().forEach(e ->
assertThat(e).isInstanceOf(ConnectException.class));
}

long warnsCount = logs.getLoggedEvents().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package resilience.shutdown;

import com.arangodb.ArangoDB;
import com.arangodb.ArangoDBException;
import com.arangodb.Protocol;
import io.vertx.core.http.HttpClosedException;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import resilience.SingleServerTest;

import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* @author Michele Rastelli
*/
class ShutdownTest extends SingleServerTest {

@ParameterizedTest
@EnumSource(Protocol.class)
void shutdown(Protocol protocol) throws InterruptedException {
ArangoDB arangoDB = dbBuilder()
.useProtocol(protocol)
.build();

arangoDB.getVersion();
arangoDB.shutdown();
Thread.sleep(1_000);
Throwable thrown = catchThrowable(arangoDB::getVersion);
assertThat(thrown).isInstanceOf(ArangoDBException.class);
assertThat(thrown.getMessage()).contains("closed");
}

@ParameterizedTest
@EnumSource(Protocol.class)
void shutdownWithPendingRequests(Protocol protocol) {
assumeTrue(protocol != Protocol.VST);
ArangoDB arangoDB = dbBuilder()
.useProtocol(protocol)
.build();

ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
es.schedule(arangoDB::shutdown, 200, TimeUnit.MILLISECONDS);
Throwable thrown = catchThrowable(() -> arangoDB.db().query("return sleep(1)", Void.class));
thrown.printStackTrace();
assertThat(thrown).isInstanceOf(ArangoDBException.class);
assertThat(thrown.getCause()).isInstanceOf(IOException.class);
assertThat(thrown.getCause().getCause()).isInstanceOf(HttpClosedException.class);
es.shutdown();
}

}