Skip to content

Commit

Permalink
Rework tests and update javadocs.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Feb 21, 2024
1 parent f2b55b5 commit 97bb467
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@ public interface ServerManagementBaseCommands {
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* raised.
* @example
* <pre>
* String response = client.configRewrite().get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configRewrite();

/**
* Reset the statistics reported by Redis using the <code>INFO</code> and <code>LATENCY HISTOGRAM
* </code> commands.
* Reset the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>
* String response = client.configResetStat().get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configResetStat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,33 @@ public interface ServerManagementClusterCommands {
CompletableFuture<ClusterValue<String>> info(InfoOptions options, Route route);

/**
* Rewrite the configuration file with the current configuration.
* Rewrite the configuration file with the current configuration.<br>
* The command will be routed automatically to all nodes.
*
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* raised.
* @example
* <pre>
* String response = client.configRewrite().get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configRewrite();

/**
* Reset the statistics reported by Redis using the <code>INFO</code> and <code>LATENCY HISTOGRAM
* </code> commands.
* Reset the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.<br>
* The command will be routed automatically to all nodes.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>
* String response = client.configResetStat().get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configResetStat();

Expand All @@ -98,17 +111,28 @@ public interface ServerManagementClusterCommands {
* defined.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* raised.
* @example
* <pre>
* String response = client.configRewrite(ALL_PRIMARIES).get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configRewrite(Route route);

/**
* Resets the statistics reported by Redis using the <code>INFO</code> and <code>LATENCY HISTOGRAM
* </code> commands.
* Reset the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @param route Routing configuration for the command. Client will route the command to the nodes
* defined.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>
* String response = client.configResetStat(ALL_PRIMARIES).get();
* assert response.equals("OK")
* </pre>
*/
CompletableFuture<String> configResetStat(Route route);
}
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ public T configRewrite() {
}

/**
* Reset the statistics reported by Redis using the <code>INFO</code> and <code>LATENCY HISTOGRAM
* </code> commands.
* Reset the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
Expand Down
112 changes: 75 additions & 37 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Stream;
import lombok.SneakyThrows;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import redis_request.RedisRequestOuterClass.RequestType;

public class RedisClientTest {

Expand Down Expand Up @@ -93,6 +87,26 @@ public void customCommand_returns_success() {
assertEquals(value, payload);
}

@SneakyThrows
@Test
public void ping_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn("PONG");

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(Ping), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.ping();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals("PONG", payload);
}

@SneakyThrows
@Test
public void ping_with_message_returns_success() {
Expand Down Expand Up @@ -211,6 +225,25 @@ public void set_with_SetOptions_OnlyIfDoesNotExist_returns_success() {
assertEquals(value, response.get());
}

@SneakyThrows
@Test
public void info_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
String testPayload = "Key: Value";
when(testResponse.get()).thenReturn(testPayload);
when(commandManager.<String>submitNewCommand(eq(Info), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.info();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(testPayload, payload);
}

@SneakyThrows
@Test
public void info_with_multiple_InfoOptions_returns_success() {
Expand Down Expand Up @@ -299,37 +332,6 @@ public void mset_returns_success() {
CompletableFuture<String> response = service.mset(keyValueMap);
}

private static Stream<Arguments> getCommandsWithoutArgs() {
return Map.<RequestType, Function<RedisClient, CompletableFuture<String>>>of(
ConfigRewrite, RedisClient::configRewrite,
ConfigResetStat, RedisClient::configResetStat,
Info, RedisClient::info,
Ping, RedisClient::ping)
.entrySet()
.stream()
.map(e -> Arguments.of(e.getKey(), e.getValue()));
}

@SneakyThrows
@ParameterizedTest(name = "{0} returns success")
@MethodSource("getCommandsWithoutArgs")
public void no_arg_command_returns_success(
RequestType requestType, Function<RedisClient, CompletableFuture<String>> command) {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);
when(commandManager.<String>submitNewCommand(eq(requestType), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = command.apply(service);
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void incr_returns_success() {
Expand Down Expand Up @@ -617,4 +619,40 @@ public void scard_returns_success() {
assertEquals(testResponse, response);
assertEquals(value, payload);
}

@SneakyThrows
@Test
public void configRewrite_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);
when(commandManager.<String>submitNewCommand(eq(ConfigRewrite), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configRewrite();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void configResetStat_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);
when(commandManager.<String>submitNewCommand(eq(ConfigResetStat), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configResetStat();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}
}
Loading

0 comments on commit 97bb467

Please sign in to comment.