Skip to content

Commit

Permalink
Java: Update timeout handling in IT. (valkey-io#1217)
Browse files Browse the repository at this point in the history
Update timeout handling in IT. (#170)

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand authored and cyip10 committed Jun 24, 2024
1 parent d83a89a commit c33e0e3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 34 deletions.
7 changes: 4 additions & 3 deletions java/integTest/src/test/java/glide/ConnectionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import glide.api.RedisClient;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClientConfiguration;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10) // seconds
public class ConnectionTests {

@Test
Expand All @@ -19,7 +20,7 @@ public void basic_client() {
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get(10, TimeUnit.SECONDS);
.get();
regularClient.close();
}

Expand All @@ -31,7 +32,7 @@ public void cluster_client() {
RedisClientConfiguration.builder()
.address(NodeAddress.builder().port(TestConfiguration.CLUSTER_PORTS[0]).build())
.build())
.get(10, TimeUnit.SECONDS);
.get();
regularClient.close();
}
}
16 changes: 7 additions & 9 deletions java/integTest/src/test/java/glide/ErrorHandlingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import glide.api.models.exceptions.RequestException;
import java.net.ServerSocket;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10) // seconds
public class ErrorHandlingTests {

@Test
Expand All @@ -29,7 +30,7 @@ public void basic_client_tries_to_connect_to_wrong_address() {
RedisClientConfiguration.builder()
.address(NodeAddress.builder().port(getFreePort()).build())
.build())
.get(10, TimeUnit.SECONDS));
.get());
assertAll(
() -> assertTrue(exception.getCause() instanceof ClosingException),
() -> assertTrue(exception.getCause().getMessage().contains("Connection refused")));
Expand All @@ -44,11 +45,11 @@ public void basic_client_tries_wrong_command() {
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get(10, TimeUnit.SECONDS)) {
.get()) {
var exception =
assertThrows(
ExecutionException.class,
() -> regularClient.customCommand(new String[] {"pewpew"}).get(10, TimeUnit.SECONDS));
() -> regularClient.customCommand(new String[] {"pewpew"}).get());
assertAll(
() -> assertTrue(exception.getCause() instanceof RequestException),
() -> assertTrue(exception.getCause().getMessage().contains("unknown command")));
Expand All @@ -64,14 +65,11 @@ public void basic_client_tries_wrong_command_arguments() {
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get(10, TimeUnit.SECONDS)) {
.get()) {
var exception =
assertThrows(
ExecutionException.class,
() ->
regularClient
.customCommand(new String[] {"ping", "pang", "pong"})
.get(10, TimeUnit.SECONDS));
() -> regularClient.customCommand(new String[] {"ping", "pang", "pong"}).get());
assertAll(
() -> assertTrue(exception.getCause() instanceof RequestException),
() ->
Expand Down
2 changes: 1 addition & 1 deletion java/integTest/src/test/java/glide/SharedClientTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@Timeout(25)
@Timeout(25) // seconds
public class SharedClientTests {

private static RedisClient standaloneClient = null;
Expand Down
2 changes: 1 addition & 1 deletion java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@Timeout(10)
@Timeout(10) // seconds
public class SharedCommandTests {

private static RedisClient standaloneClient = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10)
@Timeout(10) // seconds
public class ClusterClientTests {

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10) // seconds
public class ClusterTransactionTests {

private static RedisClusterClient clusterClient = null;
Expand All @@ -36,7 +37,7 @@ public static void init() {
.address(NodeAddress.builder().port(TestConfiguration.CLUSTER_PORTS[0]).build())
.requestTimeout(5000)
.build())
.get(10, TimeUnit.SECONDS);
.get();
}

@AfterAll
Expand All @@ -49,7 +50,7 @@ public static void teardown() {
@SneakyThrows
public void custom_command_info() {
ClusterTransaction transaction = new ClusterTransaction().customCommand(new String[] {"info"});
Object[] result = clusterClient.exec(transaction).get(10, TimeUnit.SECONDS);
Object[] result = clusterClient.exec(transaction).get();
assertTrue(((String) result[0]).contains("# Stats"));
}

Expand All @@ -68,8 +69,7 @@ public void WATCH_transaction_failure_returns_null() {
@SneakyThrows
public void info_simple_route_test() {
ClusterTransaction transaction = new ClusterTransaction().info().info();
ClusterValue<Object>[] result =
clusterClient.exec(transaction, RANDOM).get(10, TimeUnit.SECONDS);
ClusterValue<Object>[] result = clusterClient.exec(transaction, RANDOM).get();

// check single-value result
assertTrue(result[0].hasSingleData());
Expand All @@ -85,8 +85,7 @@ public void test_cluster_transactions() {
ClusterTransaction transaction = (ClusterTransaction) transactionTest(new ClusterTransaction());
Object[] expectedResult = transactionTestResult();

ClusterValue<Object>[] clusterValues =
clusterClient.exec(transaction, RANDOM).get(10, TimeUnit.SECONDS);
ClusterValue<Object>[] clusterValues = clusterClient.exec(transaction, RANDOM).get();
Object[] results =
Arrays.stream(clusterValues)
.map(v -> v.hasSingleData() ? v.getSingleValue() : v.getMultiValue())
Expand Down
6 changes: 2 additions & 4 deletions java/integTest/src/test/java/glide/cluster/CommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10)
@Timeout(10) // seconds
public class CommandTests {

private static RedisClusterClient clusterClient = null;
Expand Down Expand Up @@ -129,8 +128,7 @@ public void custom_command_info() {
@Test
@SneakyThrows
public void custom_command_ping() {
ClusterValue<Object> data =
clusterClient.customCommand(new String[] {"ping"}).get(10, TimeUnit.SECONDS);
ClusterValue<Object> data = clusterClient.customCommand(new String[] {"ping"}).get();
assertEquals("PONG", data.getSingleValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10)
@Timeout(10) // seconds
public class CommandTests {

private static final String INITIAL_VALUE = "VALUE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10)
@Timeout(10) // seconds
public class StandaloneClientTests {

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClientConfiguration;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

@Timeout(10) // seconds
public class TransactionTests {

private static RedisClient client = null;
Expand All @@ -36,7 +37,7 @@ public static void init() {
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get(10, TimeUnit.SECONDS);
.get();
}

@AfterAll
Expand All @@ -49,7 +50,7 @@ public static void teardown() {
@SneakyThrows
public void custom_command_info() {
Transaction transaction = new Transaction().customCommand(new String[] {"info"});
Object[] result = client.exec(transaction).get(10, TimeUnit.SECONDS);
Object[] result = client.exec(transaction).get();
assertTrue(((String) result[0]).contains("# Stats"));
}

Expand All @@ -60,7 +61,7 @@ public void info_test() {
new Transaction()
.info()
.info(InfoOptions.builder().section(InfoOptions.Section.CLUSTER).build());
Object[] result = client.exec(transaction).get(10, TimeUnit.SECONDS);
Object[] result = client.exec(transaction).get();

// sanity check
assertTrue(((String) result[0]).contains("# Stats"));
Expand All @@ -79,7 +80,7 @@ public void ping_tests() {
transaction.ping(Integer.toString(idx));
}
}
Object[] result = client.exec(transaction).get(10, TimeUnit.SECONDS);
Object[] result = client.exec(transaction).get();
for (int idx = 0; idx < numberOfPings; idx++) {
if ((idx % 2) == 0) {
assertEquals("PONG", result[idx]);
Expand All @@ -106,7 +107,7 @@ public void test_standalone_transactions() {

expectedResult = ArrayUtils.addAll(expectedResult, OK, OK, value, OK, null);

Object[] result = client.exec(transaction).get(10, TimeUnit.SECONDS);
Object[] result = client.exec(transaction).get();
assertArrayEquals(expectedResult, result);
}
}

0 comments on commit c33e0e3

Please sign in to comment.