|
| 1 | +package resilience.ttl; |
| 2 | + |
| 3 | +import com.arangodb.ArangoDB; |
| 4 | +import com.arangodb.ArangoDBAsync; |
| 5 | +import com.arangodb.Protocol; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.Arguments; |
| 8 | +import org.junit.jupiter.params.provider.MethodSource; |
| 9 | +import resilience.SingleServerTest; |
| 10 | + |
| 11 | +import java.time.Duration; |
| 12 | +import java.util.concurrent.ExecutionException; |
| 13 | +import java.util.stream.Stream; |
| 14 | + |
| 15 | +import static org.awaitility.Awaitility.await; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Michele Rastelli |
| 19 | + */ |
| 20 | +class TtlTest extends SingleServerTest { |
| 21 | + |
| 22 | + static Stream<Arguments> args() { |
| 23 | + return Stream.of( |
| 24 | + Arguments.of(Protocol.HTTP_JSON, "UNREGISTERED"), |
| 25 | + Arguments.of(Protocol.HTTP2_JSON, "OUTBOUND GO_AWAY") |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + @ParameterizedTest |
| 30 | + @MethodSource("args") |
| 31 | + void connectionTtl(Protocol p, String expectedLog) { |
| 32 | + ArangoDB arangoDB = dbBuilder() |
| 33 | + .connectionTtl(1_000L) |
| 34 | + .maxConnections(1) |
| 35 | + .protocol(p) |
| 36 | + .build(); |
| 37 | + |
| 38 | + arangoDB.getVersion(); |
| 39 | + |
| 40 | + await() |
| 41 | + .timeout(Duration.ofSeconds(3)) |
| 42 | + .until(() -> logs.getLogs().anyMatch(it -> it.getFormattedMessage().contains(expectedLog))); |
| 43 | + |
| 44 | + arangoDB.getVersion(); |
| 45 | + arangoDB.shutdown(); |
| 46 | + } |
| 47 | + |
| 48 | + @ParameterizedTest |
| 49 | + @MethodSource("args") |
| 50 | + void connectionTtlAsync(Protocol p, String expectedLog) throws ExecutionException, InterruptedException { |
| 51 | + ArangoDBAsync arangoDB = dbBuilder() |
| 52 | + .connectionTtl(1_000L) |
| 53 | + .maxConnections(1) |
| 54 | + .protocol(p) |
| 55 | + .build() |
| 56 | + .async(); |
| 57 | + |
| 58 | + arangoDB.getVersion().get(); |
| 59 | + |
| 60 | + await() |
| 61 | + .timeout(Duration.ofSeconds(3)) |
| 62 | + .until(() -> logs.getLogs().anyMatch(it -> it.getFormattedMessage().contains(expectedLog))); |
| 63 | + |
| 64 | + arangoDB.getVersion().get(); |
| 65 | + arangoDB.shutdown(); |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments