Skip to content

Commit

Permalink
Refactor some defaults, use QueryOptions.DEFAULT in E2E test.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Griffin committed Oct 31, 2024
1 parent 3996335 commit 1dd3442
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/fauna/client/FaunaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.util.logging.Handler;
import java.util.logging.Level;

import static com.fauna.constants.Defaults.LOCAL_FAUNA_SECRET;
import static com.fauna.constants.Defaults.MAX_CONTENTION_RETRIES;
import static com.fauna.constants.Defaults.CLIENT_TIMEOUT_BUFFER;

/**
* FaunaConfig is a configuration class used to set up and configure a connection to Fauna.
* It encapsulates various settings such as the endpoint URL, secret key, and more.
Expand All @@ -25,7 +29,7 @@ public static class FaunaEndpoint {
private final StatsCollector statsCollector;
public static final FaunaConfig DEFAULT = FaunaConfig.builder().build();
public static final FaunaConfig LOCAL = FaunaConfig.builder().endpoint(
FaunaEndpoint.LOCAL).secret("secret").build();
FaunaEndpoint.LOCAL).secret(LOCAL_FAUNA_SECRET).build();

/**
* Private constructor for FaunaConfig.
Expand Down Expand Up @@ -107,8 +111,8 @@ public static Builder builder() {
public static class Builder {
private String endpoint = FaunaEnvironment.faunaEndpoint().orElse(FaunaEndpoint.DEFAULT);
private String secret = FaunaEnvironment.faunaSecret().orElse("");
private int maxContentionRetries = 3;
private Duration clientTimeoutBuffer = Duration.ofSeconds(5);
private int maxContentionRetries = MAX_CONTENTION_RETRIES;
private Duration clientTimeoutBuffer = CLIENT_TIMEOUT_BUFFER;
private Handler logHandler = defaultLogHandler();
private StatsCollector statsCollector = new StatsCollectorImpl();

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/fauna/constants/Defaults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fauna.constants;

import java.time.Duration;

public class Defaults {

public static final Duration CLIENT_TIMEOUT_BUFFER = Duration.ofSeconds(5);
public static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
public static final String LOCAL_FAUNA_SECRET = "secret";
public static final int MAX_CONTENTION_RETRIES = 3;

}
4 changes: 2 additions & 2 deletions src/main/java/com/fauna/event/FeedOptions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fauna.event;

import com.fauna.query.QueryOptions;
import static com.fauna.constants.Defaults.DEFAULT_TIMEOUT;

import java.time.Duration;
import java.util.Optional;
Expand Down Expand Up @@ -43,7 +43,7 @@ public static class Builder {
public String cursor = null;
public Long startTs = null;
public Integer pageSize = null;
public Duration timeout = QueryOptions.DEFAULT_TIMEOUT;
public Duration timeout = DEFAULT_TIMEOUT;

public Builder cursor(String cursor) {
if (startTs != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/fauna/query/QueryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.time.Duration;
import java.util.Optional;

import static com.fauna.constants.Defaults.DEFAULT_TIMEOUT;

public class QueryOptions {
private final Boolean linearized;
private final Boolean typeCheck;
private final Duration timeout;
private final QueryTags queryTags;
private final String traceParent;

public static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
public static QueryOptions DEFAULT = QueryOptions.builder().build();

public QueryOptions(Builder builder) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/fauna/e2e/E2EQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public void query_syncWithParameterized() {
@Test
public void query_syncWithClassAndOptions() {
var q = fql("42");
var res = c.query(q, int.class, QueryOptions.builder().build());
var res = c.query(q, int.class, QueryOptions.DEFAULT);
var exp = 42;
assertEquals(exp, res.getData());
}

@Test
public void query_syncWithParameterizedAndOptions() {
var q = fql("[42]");
var res = c.query(q, listOf(int.class), QueryOptions.builder().build());
var res = c.query(q, listOf(int.class), QueryOptions.DEFAULT);
var exp = List.of(42);
assertEquals(exp, res.getData());
}
Expand Down Expand Up @@ -139,15 +139,15 @@ public void query_asyncWithParameterized() throws ExecutionException, Interrupte
@Test
public void query_asyncWithClassAndOptions() throws ExecutionException, InterruptedException {
var q = fql("42");
var res = c.asyncQuery(q, int.class, QueryOptions.builder().build()).get();
var res = c.asyncQuery(q, int.class, QueryOptions.DEFAULT).get();
var exp = 42;
assertEquals(exp, res.getData());
}

@Test
public void query_asyncWithParameterizedAndOptions() throws ExecutionException, InterruptedException {
var q = fql("[42]");
var res = c.asyncQuery(q, listOf(int.class), QueryOptions.builder().build()).get();
var res = c.asyncQuery(q, listOf(int.class), QueryOptions.DEFAULT).get();
var exp = List.of(42);
assertEquals(exp, res.getData());
}
Expand Down

0 comments on commit 1dd3442

Please sign in to comment.