Skip to content

Commit

Permalink
Complete coverage with integration tests, straight scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Aug 20, 2024
1 parent 0a4e38c commit 9b10744
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ public RedisFuture<List<JsonValue<K, V>>> jsonGet(K key, JsonGetArgs options, Js
}

@Override
public RedisFuture<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {
public RedisFuture<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {
return dispatch(jsonCommandBuilder.jsonMerge(key, jsonPath, value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ public Flux<JsonValue<K, V>> jsonGet(K key, JsonGetArgs options, JsonPath... jso
}

@Override
public Mono<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {
public Mono<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {
return createMono(() -> jsonCommandBuilder.jsonMerge(key, jsonPath, value));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/RedisJsonCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Command<K, V, List<JsonValue<K, V>>> jsonGet(K key, JsonGetArgs options, JsonPat
return createCommand(JSON_GET, new JsonValueListOutput<>(codec), args);
}

Command<K, V, Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {
Command<K, V, String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value) {

notNullKey(key);

Expand All @@ -183,7 +183,7 @@ Command<K, V, Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value

args.add(value.asByteBuffer().array());

return createCommand(JSON_MERGE, new BooleanOutput<>(codec), args);
return createCommand(JSON_MERGE, new StatusOutput<>(codec), args);
}

Command<K, V, List<JsonValue<K, V>>> jsonMGet(JsonPath jsonPath, K... keys) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public interface RedisJsonAsyncCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
RedisFuture<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
RedisFuture<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public interface RedisJsonReactiveCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
Mono<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
Mono<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/api/sync/RedisJsonCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public interface RedisJsonCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
Boolean jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
String jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public interface NodeSelectionJsonAsyncCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
AsyncExecutions<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
AsyncExecutions<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public interface NodeSelectionJsonCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
Executions<Boolean> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
Executions<String> jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import io.lettuce.core.json.arguments.JsonSetArgs
* @author Tihomir Mateev
* @see <a href="https://redis.io/docs/latest/develop/data-types/json/">Redis JSON</a>
* @since 6.5
* @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi
* @generated by io.lettuce.apigenerator.CreateKotlinCoroutinesApi
*/
@ExperimentalLettuceCoroutinesApi
interface RedisJsonCoroutinesCommands<K : Any, V : Any> {
Expand Down Expand Up @@ -176,11 +176,11 @@ interface RedisJsonCoroutinesCommands<K : Any, V : Any> {
* @param key the key holding the JSON document.
* @param jsonPath the [JsonPath] pointing to the value to merge.
* @param value the [JsonValue] to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue<K, V>): Boolean?
suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue<K, V>): String?

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class RedisJsonCoroutinesCommandsImpl<K : Any, V : Any>(internal val op
override suspend fun jsonGet(key: K, options: JsonGetArgs, vararg jsonPaths: JsonPath): List<JsonValue<K, V>> =
ops.jsonGet(key, options, *jsonPaths).asFlow().toList()

override suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue<K, V>): Boolean? =
override suspend fun jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue<K, V>): String? =
ops.jsonMerge(key, jsonPath, value).awaitFirstOrNull()

override suspend fun jsonMGet(jsonPath: JsonPath, vararg keys: K): List<JsonValue<K, V>> =
Expand Down
4 changes: 2 additions & 2 deletions src/main/templates/io/lettuce/core/api/RedisJsonCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public interface RedisJsonCommands<K, V> {
* @param key the key holding the JSON document.
* @param jsonPath the {@link JsonPath} pointing to the value to merge.
* @param value the {@link JsonValue} to merge.
* @return Boolean true if the merge was successful, false otherwise.
* @return String "OK" if the set was successful, error if the operation failed.
* @since 6.5
* @see <A href="https://tools.ietf.org/html/rfc7396">RFC7396</a>
*/
Boolean jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);
String jsonMerge(K key, JsonPath jsonPath, JsonValue<K, V> value);

/**
* Return the values at path from multiple key arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.lettuce.core.json.JsonPath;
import io.lettuce.core.json.JsonValue;
import io.lettuce.core.json.arguments.JsonSetArgs;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterAll;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -26,17 +27,17 @@
@Testcontainers
public class RedisContainerIntegrationTests {

@Container
public GenericContainer redisContainer = new GenericContainer(image).withExposedPorts(6379).withReuse(true);;

private static DockerImageName image = DockerImageName.parse("redis/redis-stack:latest");

@Container
public static GenericContainer redisContainer = new GenericContainer(image).withExposedPorts(6379).withReuse(true);;

private static RedisClient client;

protected static RedisCommands<String, String> redis;

@BeforeEach
public void prepare() throws IOException {
@BeforeAll
public static void setup() {
if (!redisContainer.isRunning()) {
redisContainer.start();
}
Expand All @@ -47,7 +48,10 @@ public void prepare() throws IOException {

client = RedisClient.create(redisURI);
redis = client.connect().sync();
}

@BeforeEach
public void prepare() throws IOException {
redis.flushall();

Path path = Paths.get("src/test/resources/bike-inventory.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void shouldCorrectlyConstructJsonGet() {

@Test
void shouldCorrectlyConstructJsonMerge() {
Command<String, String, Boolean> command = builder.jsonMerge(MY_KEY, MY_PATH, ELEMENT);
Command<String, String, String> command = builder.jsonMerge(MY_KEY, MY_PATH, ELEMENT);
ByteBuf buf = Unpooled.directBuffer();
command.encode(buf);

Expand Down
Loading

0 comments on commit 9b10744

Please sign in to comment.