diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLController.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLController.java index 0f764b72..d4c316b1 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLController.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLController.java @@ -143,7 +143,7 @@ private Map getReplacements( } replacements.put( "subscriptionClientTimeout", - String.valueOf(graphiQLProperties.getSubscriptions().getTimeout() * 1000)); + String.valueOf(graphiQLProperties.getSubscriptions().getTimeout().toMillis())); replacements.put( "subscriptionClientReconnect", String.valueOf(graphiQLProperties.getSubscriptions().isReconnect())); diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLProperties.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLProperties.java index b7b849f6..dd51ecbe 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLProperties.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/editor/graphiql/GraphiQLProperties.java @@ -1,7 +1,10 @@ package graphql.kickstart.autoconfigure.editor.graphiql; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.convert.DurationUnit; @Data @ConfigurationProperties("graphql.graphiql") @@ -65,7 +68,11 @@ static class Cdn { @Data static class Subscriptions { - private int timeout = 30; + /** + * Subscription timeout. If a duration suffix is not specified, second will be used. + */ + @DurationUnit(ChronoUnit.SECONDS) + private Duration timeout = Duration.ofSeconds(30); private boolean reconnect = false; } } diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/AsyncServletProperties.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/AsyncServletProperties.java index 0f2b5680..ef289ec6 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/AsyncServletProperties.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/AsyncServletProperties.java @@ -1,14 +1,23 @@ package graphql.kickstart.autoconfigure.web.servlet; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.convert.DurationUnit; @Data @ConfigurationProperties(prefix = "graphql.servlet.async") public class AsyncServletProperties { + public static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(30); + private boolean enabled = true; - private long timeout = 30000; + /** + * Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be used. + */ + @DurationUnit(ChronoUnit.MILLIS) + private Duration timeout = DEFAULT_TIMEOUT; private boolean delegateSecurityContext = true; private Threads threads = new Threads(); diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java index 18996d49..914c2750 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLServletProperties.java @@ -19,22 +19,31 @@ package graphql.kickstart.autoconfigure.web.servlet; import graphql.kickstart.execution.context.ContextSetting; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.convert.DurationUnit; /** @author Michiel Oliemans */ @Data @ConfigurationProperties(prefix = "graphql.servlet") public class GraphQLServletProperties { + public final static Duration DEFAULT_SUBSCRIPTION_TIMEOUT = Duration.ZERO; + private boolean enabled = true; private boolean corsEnabled = true; private String mapping = "/graphql"; private boolean exceptionHandlersEnabled = false; - private long subscriptionTimeout = 0; + /** + * Subscription timeout. If a duration suffix is not specified, millisecond will be used. + */ + @DurationUnit(ChronoUnit.MILLIS) + private Duration subscriptionTimeout = DEFAULT_SUBSCRIPTION_TIMEOUT; private ContextSetting contextSetting = ContextSetting.PER_QUERY_WITH_INSTRUMENTATION; - /** @deprecated Use graphql.servlet.async.timeout instead */ - @Deprecated private Long asyncTimeout; + /** Asynchronous execution timeout. If a duration suffix is not specified, millisecond will be used. @deprecated Use graphql.servlet.async.timeout instead */ + @Deprecated @DurationUnit(ChronoUnit.MILLIS) private Duration asyncTimeout; /** @deprecated Use graphql.servlet.async.enabled instead */ @Deprecated private Boolean asyncModeEnabled; diff --git a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java index c02edeba..af0fae21 100644 --- a/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java +++ b/graphql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/autoconfigure/web/servlet/GraphQLWebAutoConfiguration.java @@ -57,11 +57,13 @@ import graphql.kickstart.spring.error.ErrorHandlerSupplier; import graphql.kickstart.spring.error.GraphQLErrorStartupListener; import graphql.schema.GraphQLSchema; +import java.time.Duration; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.concurrent.Executor; import javax.servlet.MultipartConfigElement; import lombok.RequiredArgsConstructor; @@ -301,19 +303,21 @@ public GraphQLConfiguration graphQLServletConfiguration( @Autowired(required = false) GraphQLResponseCacheManager responseCacheManager, @Autowired(required = false) AsyncTaskDecorator asyncTaskDecorator, @Autowired(required = false) @Qualifier("graphqlAsyncTaskExecutor") Executor asyncExecutor) { - long asyncTimeout = - graphQLServletProperties.getAsyncTimeout() != null - ? graphQLServletProperties.getAsyncTimeout() - : asyncServletProperties.getTimeout(); + Duration asyncTimeout = Optional.ofNullable(asyncServletProperties.getTimeout()) // + .orElse(AsyncServletProperties.DEFAULT_TIMEOUT); + long asyncTimeoutMilliseconds = Optional.ofNullable(graphQLServletProperties.getAsyncTimeout()) // + .orElse(asyncTimeout).toMillis(); + long subscriptionTimeoutMilliseconds = Optional.ofNullable(graphQLServletProperties.getSubscriptionTimeout()) // + .orElse(GraphQLServletProperties.DEFAULT_SUBSCRIPTION_TIMEOUT).toMillis(); return GraphQLConfiguration.with(invocationInputFactory) .with(graphQLInvoker) .with(graphQLObjectMapper) .with(listeners) - .with(graphQLServletProperties.getSubscriptionTimeout()) + .with(subscriptionTimeoutMilliseconds) .with(batchInputPreProcessor) .with(graphQLServletProperties.getContextSetting()) .with(responseCacheManager) - .asyncTimeout(asyncTimeout) + .asyncTimeout(asyncTimeoutMilliseconds) .with(asyncTaskDecorator) .asyncCorePoolSize(asyncServletProperties.getThreads().getMin()) .asyncCorePoolSize(asyncServletProperties.getThreads().getMax()) diff --git a/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/autoconfigure/annotations/GraphQLAnnotationsSubscriptionTest.java b/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/autoconfigure/annotations/GraphQLAnnotationsSubscriptionTest.java index 45c70e7e..8ce39598 100644 --- a/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/autoconfigure/annotations/GraphQLAnnotationsSubscriptionTest.java +++ b/graphql-spring-boot-autoconfigure/src/test/java/graphql/kickstart/autoconfigure/annotations/GraphQLAnnotationsSubscriptionTest.java @@ -4,6 +4,7 @@ import com.graphql.spring.boot.test.GraphQLResponse; import com.graphql.spring.boot.test.GraphQLTestSubscription; +import java.time.Duration; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -25,7 +26,7 @@ void testSubscription() { graphQLTestSubscription .init() .start("annotations/subscriptions/test-subscription.graphql") - .awaitAndGetNextResponse(10000); + .awaitAndGetNextResponse(Duration.ofSeconds(10)); // THEN assertThat(graphQLResponse.get("$.data.testSubscription")).isEqualTo("some value"); } diff --git a/graphql-spring-boot-test-autoconfigure/src/test/java/com/graphql/spring/boot/test/GraphQLTestAutoConfigurationTestBase.java b/graphql-spring-boot-test-autoconfigure/src/test/java/com/graphql/spring/boot/test/GraphQLTestAutoConfigurationTestBase.java index b59213b2..3a0ffe36 100644 --- a/graphql-spring-boot-test-autoconfigure/src/test/java/com/graphql/spring/boot/test/GraphQLTestAutoConfigurationTestBase.java +++ b/graphql-spring-boot-test-autoconfigure/src/test/java/com/graphql/spring/boot/test/GraphQLTestAutoConfigurationTestBase.java @@ -1,6 +1,7 @@ package com.graphql.spring.boot.test; import java.io.IOException; +import java.time.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; @@ -19,7 +20,7 @@ void assertThatTestSubscriptionWorksCorrectly() { // WHEN - THEN testSubscription .start("test-subscription.graphql") - .awaitAndGetNextResponse(1000) + .awaitAndGetNextResponse(Duration.ofSeconds(1)) .assertThatNoErrorsArePresent() .assertThatField("$.data.testSubscription") .asString() diff --git a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java index d05fb7a9..82132c20 100644 --- a/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java +++ b/graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java @@ -13,13 +13,13 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Queue; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import javax.websocket.ClientEndpointConfig; @@ -49,7 +49,7 @@ public class GraphQLTestSubscription { private static final WebSocketContainer WEB_SOCKET_CONTAINER = ContainerProvider.getWebSocketContainer(); - private static final int ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT = 60000; + private static final Duration ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT = Duration.ofMinutes(1); private static final AtomicInteger ID_COUNTER = new AtomicInteger(1); private static final UriBuilderFactory URI_BUILDER_FACTORY = new DefaultUriBuilderFactory(); private static final Object STATE_LOCK = new Object(); @@ -205,8 +205,23 @@ public void reset() { * @param timeout timeout in milliseconds. Test will fail if no message received from the * subscription until the timeout expires. * @return The received response. + * @see #awaitAndGetNextResponse(Duration) + * @deprecated since 12.0.0. Use {@link #awaitAndGetNextResponse(Duration)} instead. */ + @Deprecated public GraphQLResponse awaitAndGetNextResponse(final int timeout) { + return awaitAndGetNextResponse(Duration.ofMillis(timeout)); + } + + /** + * Awaits and returns the next response received from the subscription. The subscription will be + * stopped after receiving the message (or timeout). + * + * @param timeout Timeout duration. Test will fail if no message received from the + * subscription until the timeout expires. + * @return The received response. + */ + public GraphQLResponse awaitAndGetNextResponse(final Duration timeout) { return awaitAndGetNextResponses(timeout, 1, true).get(0); } @@ -218,8 +233,24 @@ public GraphQLResponse awaitAndGetNextResponse(final int timeout) { * @param stopAfter if true, the subscription will be stopped after the message was received (or * timeout). * @return The received response. + * @see #awaitAndGetNextResponse(Duration,boolean) + * @deprecated since 12.0.0. Use {@link #awaitAndGetNextResponse(Duration,boolean)} instead. */ + @Deprecated public GraphQLResponse awaitAndGetNextResponse(final int timeout, final boolean stopAfter) { + return awaitAndGetNextResponse(Duration.ofMillis(timeout),stopAfter); + } + + /** + * Awaits and returns the next response received from the subscription. + * + * @param timeout Timeout duration. Test will fail if no message received from the + * subscription until the timeout expires. + * @param stopAfter if true, the subscription will be stopped after the message was received (or + * timeout). + * @return The received response. + */ + public GraphQLResponse awaitAndGetNextResponse(final Duration timeout, final boolean stopAfter) { return awaitAndGetNextResponses(timeout, 1, stopAfter).get(0); } @@ -230,8 +261,23 @@ public GraphQLResponse awaitAndGetNextResponse(final int timeout, final boolean * * @param timeToWait the time to wait, in milliseconds * @return the list of responses received during that time. + * @see #awaitAndGetAllResponses(Duration) + * @deprecated since 12.0.0. Use {@link #awaitAndGetAllResponses(Duration)} instead. */ + @Deprecated public List awaitAndGetAllResponses(final int timeToWait) { + return awaitAndGetAllResponses(Duration.ofMillis(timeToWait)); + } + + /** + * Waits a specified amount time and returns all responses received during that time. This method + * does not have any expectation regarding the number of messages. The subscription will be + * stopped after the time elapsed. + * + * @param timeToWait the time to wait. + * @return the list of responses received during that time. + */ + public List awaitAndGetAllResponses(final Duration timeToWait) { return awaitAndGetNextResponses(timeToWait, -1, true); } @@ -242,9 +288,25 @@ public List awaitAndGetAllResponses(final int timeToWait) { * @param timeToWait the time to wait, in milliseconds * @param stopAfter if true, the subscription will be stopped after the time elapsed. * @return the list of responses received during that time. + * @see #awaitAndGetAllResponses(Duration,boolean) + * @deprecated since 12.0.0. Use {@link #awaitAndGetAllResponses(Duration,boolean)} instead. */ + @Deprecated public List awaitAndGetAllResponses( final int timeToWait, final boolean stopAfter) { + return awaitAndGetNextResponses(Duration.ofMillis(timeToWait), -1, stopAfter); + } + + /** + * Waits a specified amount time and returns all responses received during that time. This method + * does not have any expectation regarding the number of messages. + * + * @param timeToWait the time to wait + * @param stopAfter if true, the subscription will be stopped after the time elapsed. + * @return the list of responses received during that time. + */ + public List awaitAndGetAllResponses( + final Duration timeToWait, final boolean stopAfter) { return awaitAndGetNextResponses(timeToWait, -1, stopAfter); } @@ -261,9 +323,31 @@ public List awaitAndGetAllResponses( * @return The list containing the expected number of responses. The list contains the responses * in the order they were received. If more responses are received than minimally expected, * {@link #getRemainingResponses()} can be used to retrieved them. + * @see #awaitAndGetNextResponses(Duration,int) + * @deprecated since 12.0.0. Use {@link #awaitAndGetNextResponses(Duration,int)} instead. */ + @Deprecated public List awaitAndGetNextResponses( final int timeout, final int numExpectedResponses) { + return awaitAndGetNextResponses(Duration.ofMillis(timeout), numExpectedResponses, true); + } + + /** + * Awaits and returns the specified number of responses. The subscription will be stopped after + * receiving the messages (or timeout). + * + * @param timeout timeout duration. Test will fail if the expected number of responses is + * not received. + * @param numExpectedResponses the number of expected responses. If negative, the method will wait + * the timeout and return all responses received during that time. In this case, no assertion + * is made regarding the number of responses, and the returned list may be empty. If zero, it + * is expected that no responses are sent during the timeout period. + * @return The list containing the expected number of responses. The list contains the responses + * in the order they were received. If more responses are received than minimally expected, + * {@link #getRemainingResponses()} can be used to retrieved them. + */ + public List awaitAndGetNextResponses( + final Duration timeout, final int numExpectedResponses) { return awaitAndGetNextResponses(timeout, numExpectedResponses, true); } @@ -281,9 +365,32 @@ public List awaitAndGetNextResponses( * @return The list containing the expected number of responses. The list contains the responses * in the order they were received. If more responses are received than minimally expected, * {@link #getRemainingResponses()} can be used to retrieved them. + * @see #awaitAndGetNextResponses(Duration,int,boolean) + * @deprecated since 12.0.0. Use {@link #awaitAndGetNextResponses(Duration,int,boolean)} instead. */ + @Deprecated public List awaitAndGetNextResponses( final int timeout, final int numExpectedResponses, final boolean stopAfter) { + return awaitAndGetNextResponses(Duration.ofMillis(timeout),numExpectedResponses,stopAfter); + } + + /** + * Awaits and returns the specified number of responses. + * + * @param timeout timeout duration. Test will fail if the expected number of responses is + * not received. + * @param numExpectedResponses the number of expected responses. If negative, the method will wait + * the timeout and return all responses received during that time. In this case, no assertion + * is made regarding the number of responses, and the returned list may be empty. If zero, it + * is expected that no responses are sent during the timeout period. + * @param stopAfter if true, the subscription will be stopped after the messages were received (or + * timeout). + * @return The list containing the expected number of responses. The list contains the responses + * in the order they were received. If more responses are received than minimally expected, + * {@link #getRemainingResponses()} can be used to retrieved them. + */ + public List awaitAndGetNextResponses( + final Duration timeout, final int numExpectedResponses, final boolean stopAfter) { if (!isStarted()) { fail("Start message not sent. Please send start message first."); } @@ -293,11 +400,11 @@ public List awaitAndGetNextResponses( if (numExpectedResponses > 0) { await() - .atMost(timeout, TimeUnit.MILLISECONDS) + .atMost(timeout) .until(() -> state.getResponses().size() >= numExpectedResponses); } else { try { - Thread.sleep(timeout); + Thread.sleep(timeout.toMillis()); } catch (InterruptedException e) { fail("Unable to wait the specified amount of time.", e); // Restore interrupted state @@ -315,13 +422,13 @@ public List awaitAndGetNextResponses( assertThat(responses) .as( String.format( - "Expected no responses in %s MS, but received %s", timeout, responses.size())) + "Expected no responses in %s, but received %s", timeout, responses.size())) .isEmpty(); } if (numExpectedResponses > 0) { assertThat(responses) .as( - "Expected at least %s message(s) in %d MS, but %d received.", + "Expected at least %d message(s) in %s, but %d received.", numExpectedResponses, timeout, responses.size()) .hasSizeGreaterThanOrEqualTo(numExpectedResponses); responsesToPoll = numExpectedResponses; @@ -340,9 +447,24 @@ public List awaitAndGetNextResponses( * * @param timeToWait time to wait, in milliseconds. * @param stopAfter if true, the subscription will be stopped afterwards. + * @see #waitAndExpectNoResponse(Duration,boolean) + * @deprecated since 12.0.0. Use {@link #waitAndExpectNoResponse(Duration,boolean)} instead. */ + @Deprecated public GraphQLTestSubscription waitAndExpectNoResponse( final int timeToWait, final boolean stopAfter) { + waitAndExpectNoResponse(Duration.ofMillis(timeToWait),stopAfter); + return this; + } + + /** + * Waits a specified amount of time and asserts that no responses were received during that time. + * + * @param timeToWait time to wait. + * @param stopAfter if true, the subscription will be stopped afterwards. + */ + public GraphQLTestSubscription waitAndExpectNoResponse( + final Duration timeToWait, final boolean stopAfter) { awaitAndGetNextResponses(timeToWait, 0, stopAfter); return this; } @@ -352,8 +474,21 @@ public GraphQLTestSubscription waitAndExpectNoResponse( * The subscription will be stopped afterwards. * * @param timeToWait time to wait, in milliseconds. + * @see #waitAndExpectNoResponse(Duration) + * @deprecated since 12.0.0. Use {@link #waitAndExpectNoResponse(Duration)} instead. */ + @Deprecated public GraphQLTestSubscription waitAndExpectNoResponse(final int timeToWait) { + return waitAndExpectNoResponse(Duration.ofMillis(timeToWait)); + } + + /** + * Waits a specified amount of time and asserts that no responses were received during that time. + * The subscription will be stopped afterwards. + * + * @param timeToWait time to wait. + */ + public GraphQLTestSubscription waitAndExpectNoResponse(final Duration timeToWait) { awaitAndGetNextResponses(timeToWait, 0, true); return this; } @@ -392,7 +527,7 @@ private void initClient() throws IOException, DeploymentException { .getUserProperties() .put( "org.apache.tomcat.websocket.IO_TIMEOUT_MS", - String.valueOf(ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT)); + String.valueOf(ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT.toMillis())); session = WEB_SOCKET_CONTAINER.connectToServer( new TestWebSocketClient(state), clientEndpointConfig, uri); @@ -441,7 +576,7 @@ private void awaitStop() { private void awaitAcknowledgementOrConnection( final Predicate condition, final String timeoutDescription) { await(timeoutDescription) - .atMost(ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS) + .atMost(ACKNOWLEDGEMENT_AND_CONNECTION_TIMEOUT) .until(() -> condition.test(this)); } diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java index 61472185..02efff32 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionGetRemainingResponsesTest.java @@ -18,7 +18,7 @@ void shouldGetRemainingResponses() { graphQLTestSubscription .start(TIMER_SUBSCRIPTION_RESOURCE) .awaitAndGetNextResponse(TIMEOUT, false); - await().atMost(TIMEOUT, MILLISECONDS); + await().atMost(TIMEOUT); graphQLTestSubscription.stop(); // THEN assertThatSubscriptionWasStopped(); diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionTestBase.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionTestBase.java index 4aff72d1..bdf44907 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionTestBase.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionTestBase.java @@ -30,7 +30,7 @@ public class GraphQLTestSubscriptionTestBase { "$.data.subscriptionWithParameter"; protected static final String DATA_SUBSCRIPTION_WITH_INIT_PAYLOAD_FIELD = "$.data.subscriptionWithInitPayload"; - protected static final int TIMEOUT = 2000; + protected static final Duration TIMEOUT = Duration.ofSeconds(2); @Autowired protected Environment environment; @@ -70,6 +70,6 @@ protected void assertThatSubscriptionWasNotStopped() { protected void assertThatMinimumRequiredTimeElapsedSince(final Instant timeBeforeTestStart) { assertThat(Duration.between(timeBeforeTestStart, Instant.now())) .as("Should wait the specified amount of time") - .isGreaterThanOrEqualTo(Duration.ofMillis(TIMEOUT)); + .isGreaterThanOrEqualTo(TIMEOUT); } } diff --git a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java index 4599f605..467cdf1b 100644 --- a/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java +++ b/graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestSubscriptionUsageErrorHandlingTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import java.time.Duration; import org.awaitility.core.ConditionTimeoutException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -22,7 +23,7 @@ void shouldRaiseAssertionErrorIfInitAfterInit() { void shouldRaiseAssertionErrorIfAwaitAndGetTimesOut() { graphQLTestSubscription.start(SUBSCRIPTION_THAT_TIMES_OUT_RESOURCE); assertThatExceptionOfType(ConditionTimeoutException.class) - .isThrownBy(() -> graphQLTestSubscription.awaitAndGetNextResponse(110)); + .isThrownBy(() -> graphQLTestSubscription.awaitAndGetNextResponse(Duration.ofMillis(110))); } @Test