diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index a79c12cab3..28b59dedfb 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -599,7 +599,7 @@ public CompletableFuture xadd(@NonNull String key, Map v @Override public CompletableFuture xadd( - @NonNull String key, Map values, StreamAddOptions options) { + @NonNull String key, @NonNull Map values, @NonNull StreamAddOptions options) { String[] arguments = ArrayUtils.addAll( ArrayUtils.addFirst(options.toArgs(), key), diff --git a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java index 837d19ec85..2dde99d820 100644 --- a/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/StreamBaseCommands.java @@ -34,13 +34,17 @@ public interface StreamBaseCommands { * @see redis.io for details. * @param key The key of the stream. * @param values field-value pairs to be added to the entry. - * @param options options. + * @param options Stream add options. * @return The id of the added entry, or null if options.makeStream is * set to false and no stream with the matching key exists. * @example *
{@code
-     * String streamId = client.xadd("key", Map.of("name", "Sara", "surname", "OConnor").get();
-     * System.out.println("Stream: " + streamId);
+     * // Stream options to not make the stream if "key" is not a stream, as use stream id of "sid"
+     * StreamAddOptions options = StreamAddOptions.builder().id("sid").makeStream(Boolean.FALSE).build();
+     * String streamId = client.xadd("key", Map.of("name", "Sara", "surname", "OConnor"), options).get();
+     * if (streamId != null) {
+     *     assert streamId.equals("sid");
+     * }
      * }
*/ CompletableFuture xadd(String key, Map values, StreamAddOptions options); diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index e2c1be936e..eea175265d 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -1262,7 +1262,7 @@ public T xadd(String key, Map values) { * @see redis.io for details. * @param key The key of the stream. * @param values field-value pairs to be added to the entry. - * @param options options. + * @param options Stream add options. * @return Command Response - The id of the added entry, or null if * options.makeStream is set to false and no stream with the matching * key exists. diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index bc4b51695f..3d5ece3a25 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -1680,53 +1680,13 @@ public void xadd_returns_success() { assertEquals(returnId, payload); } - @SneakyThrows - @Test - public void xadd_with_nomakestream_maxlen_options_returns_success() { - // setup - String key = "testKey"; - Map fieldValues = new LinkedHashMap<>(); - fieldValues.put("testField1", "testValue1"); - fieldValues.put("testField2", "testValue2"); - StreamAddOptions options = - StreamAddOptions.builder() - .id("id") - .makeStream(false) - .trim(new StreamAddOptions.Maxlen(true, 5L)) - .build(); - - String[] arguments = - new String[] { - key, - NO_MAKE_STREAM_REDIS_API, - TRIM_MAXLEN_REDIS_API, - TRIM_EXACT_REDIS_API, - Long.toString(5L), - "id" - }; - arguments = ArrayUtils.addAll(arguments, convertMapToKeyValueStringArray(fieldValues)); - - String returnId = "testId"; - - CompletableFuture testResponse = mock(CompletableFuture.class); - when(testResponse.get()).thenReturn(returnId); - - // match on protobuf request - when(commandManager.submitNewCommand(eq(XAdd), eq(arguments), any())) - .thenReturn(testResponse); - - // exercise - CompletableFuture response = service.xadd(key, fieldValues, options); - String payload = response.get(); - - // verify - assertEquals(testResponse, response); - assertEquals(returnId, payload); - } - private static List getStreamAddOptions() { return List.of( Arguments.of( + Pair.of( + // no TRIM option + StreamAddOptions.builder().id("id").makeStream(Boolean.FALSE).build(), + new String[] {"testKey", NO_MAKE_STREAM_REDIS_API, "id"}), Pair.of( // MAXLEN with LIMIT StreamAddOptions.builder() @@ -1792,14 +1752,14 @@ private static List getStreamAddOptions() { @SneakyThrows @ParameterizedTest @MethodSource("getStreamAddOptions") - public void xadd_with_options_returns_success(Pair input) { + public void xadd_with_options_returns_success(Pair optionAndArgs) { // setup String key = "testKey"; Map fieldValues = new LinkedHashMap<>(); fieldValues.put("testField1", "testValue1"); fieldValues.put("testField2", "testValue2"); String[] arguments = - ArrayUtils.addAll(input.getRight(), convertMapToKeyValueStringArray(fieldValues)); + ArrayUtils.addAll(optionAndArgs.getRight(), convertMapToKeyValueStringArray(fieldValues)); String returnId = "testId"; CompletableFuture testResponse = mock(CompletableFuture.class); @@ -1810,7 +1770,7 @@ public void xadd_with_options_returns_success(Pair i .thenReturn(testResponse); // exercise - CompletableFuture response = service.xadd(key, fieldValues, input.getLeft()); + CompletableFuture response = service.xadd(key, fieldValues, optionAndArgs.getLeft()); String payload = response.get(); // verify