Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-794] default ttl #553

Merged
merged 3 commits into from
Mar 21, 2024
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
5 changes: 3 additions & 2 deletions core/src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,10 @@ public Builder maxConnections(final Integer maxConnections) {
}

/**
* Set the maximum time to life of a connection. After this time the connection will be closed automatically.
* Set the time to live of an inactive connection. After this time of inactivity the connection will be
* closed automatically.
*
* @param connectionTtl the maximum time to life of a connection in milliseconds
* @param connectionTtl the time to live of a connection in milliseconds
* @return {@link ArangoDB.Builder}
*/
public Builder connectionTtl(final Long connectionTtl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public final class ArangoDefaults {
public static final Protocol DEFAULT_PROTOCOL = Protocol.HTTP2_JSON;
public static final String DEFAULT_USER = "root";
public static final Integer DEFAULT_TIMEOUT = 0;
public static final Long DEFAULT_CONNECTION_TTL_HTTP = 30_000L;
public static final Boolean DEFAULT_USE_SSL = false;
public static final Boolean DEFAULT_VERIFY_HOST = true;
public static final Integer DEFAULT_CHUNK_SIZE = 30_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public void setMaxConnections(Integer maxConnections) {
}

public Long getConnectionTtl() {
if (connectionTtl == null && getProtocol() != Protocol.VST) {
connectionTtl = ArangoDefaults.DEFAULT_CONNECTION_TTL_HTTP;
}
return connectionTtl;
}

Expand Down
1 change: 1 addition & 0 deletions resilience-tests/src/test/java/resilience/ClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static void afterAll() throws IOException {
@BeforeEach
void beforeEach() {
enableAllEndpoints();
logs.reset();
}

protected static List<Endpoint> getEndpoints() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void afterAll() throws IOException {
@BeforeEach
void beforeEach() {
getEndpoint().enable();
logs.reset();
}

protected static Endpoint getEndpoint() {
Expand Down
68 changes: 68 additions & 0 deletions resilience-tests/src/test/java/resilience/ttl/TtlTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package resilience.ttl;

import com.arangodb.ArangoDB;
import com.arangodb.ArangoDBAsync;
import com.arangodb.Protocol;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import resilience.SingleServerTest;

import java.time.Duration;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;

import static org.awaitility.Awaitility.await;

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

static Stream<Arguments> args() {
return Stream.of(
Arguments.of(Protocol.HTTP_JSON, "UNREGISTERED"),
Arguments.of(Protocol.HTTP2_JSON, "OUTBOUND GO_AWAY")
);
}

@ParameterizedTest
@MethodSource("args")
void connectionTtl(Protocol p, String expectedLog) {
ArangoDB arangoDB = dbBuilder()
.connectionTtl(1_000L)
.maxConnections(1)
.protocol(p)
.build();

arangoDB.getVersion();

await()
.timeout(Duration.ofSeconds(3))
.until(() -> logs.getLogs().anyMatch(it -> it.getFormattedMessage().contains(expectedLog)));

arangoDB.getVersion();
arangoDB.shutdown();
}

@ParameterizedTest
@MethodSource("args")
void connectionTtlAsync(Protocol p, String expectedLog) throws ExecutionException, InterruptedException {
ArangoDBAsync arangoDB = dbBuilder()
.connectionTtl(1_000L)
.maxConnections(1)
.protocol(p)
.build()
.async();

arangoDB.getVersion().get();

await()
.timeout(Duration.ofSeconds(3))
.until(() -> logs.getLogs().anyMatch(it -> it.getFormattedMessage().contains(expectedLog)));

arangoDB.getVersion().get();
arangoDB.shutdown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public synchronized void open() throws IOException {
LOGGER.debug("[" + connectionName + "]: Start Callable");

final long openTime = new Date().getTime();
final Long ttlTime = ttl != null ? openTime + ttl : null;
final Long ttlTime = ttl != null && ttl > 0 ? openTime + ttl : null;
final ChunkStore chunkStore = new ChunkStore(messageStore);
while (true) {
if (ttlTime != null && new Date().getTime() > ttlTime && messageStore.isEmpty()) {
Expand Down
Loading