Skip to content

Commit

Permalink
Fixed Exec return type for cluster client. Now returns Array or Null. (
Browse files Browse the repository at this point in the history
…#1019)

* Fixed Exec return type for cluster client. Now returns Array or Null.

* Added test for when watch transaction failure returns null.
  • Loading branch information
SanHalacogluImproving authored Feb 22, 2024
1 parent 736e636 commit 7c15277
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions java/client/src/main/java/glide/api/RedisClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ protected ClusterValue<Object> handleCustomCommandResponse(Route route, Response
@Override
public CompletableFuture<Object[]> exec(ClusterTransaction transaction) {
return commandManager.submitNewCommand(
transaction, Optional.empty(), this::handleArrayResponse);
transaction, Optional.empty(), this::handleArrayOrNullResponse);
}

@Override
public CompletableFuture<ClusterValue<Object>[]> exec(
ClusterTransaction transaction, Route route) {
return commandManager
.submitNewCommand(transaction, Optional.ofNullable(route), this::handleArrayResponse)
.submitNewCommand(transaction, Optional.ofNullable(route), this::handleArrayOrNullResponse)
.thenApply(
objects ->
Arrays.stream(objects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

import static glide.TransactionTestUtilities.transactionTest;
import static glide.TransactionTestUtilities.transactionTestResult;
import static glide.api.BaseClient.OK;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.RANDOM;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import glide.TestConfiguration;
Expand Down Expand Up @@ -50,6 +53,17 @@ public void custom_command_info() {
assertTrue(((String) result[0]).contains("# Stats"));
}

@Test
@SneakyThrows
public void WATCH_transaction_failure_returns_null() {
ClusterTransaction transaction = new ClusterTransaction();
transaction.get("key");
assertEquals(
OK, clusterClient.customCommand(new String[] {"WATCH", "key"}).get().getSingleValue());
assertEquals(OK, clusterClient.set("key", "foo").get());
assertNull(clusterClient.exec(transaction).get());
}

@Test
@SneakyThrows
public void info_simple_route_test() {
Expand Down

0 comments on commit 7c15277

Please sign in to comment.