Skip to content

Commit

Permalink
Update unit tests for java client (valkey-io#875)
Browse files Browse the repository at this point in the history
Update tests.

Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand authored Jan 31, 2024
1 parent 59f4b7a commit 07e6d43
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void teardown() {

@Test
@SneakyThrows
public void createClient_withConfig_successfullyReturnsRedisClient() {
public void createClient_with_config_successfully_returns_RedisClient() {

// setup
CompletableFuture<Void> connectToRedisFuture = new CompletableFuture<>();
Expand All @@ -72,7 +72,7 @@ public void createClient_withConfig_successfullyReturnsRedisClient() {

@SneakyThrows
@Test
public void createClient_errorOnConnectionThrowsExecutionException() {
public void createClient_error_on_connection_throws_ExecutionException() {
// setup
CompletableFuture<Void> connectToRedisFuture = new CompletableFuture<>();
ClosingException exception = new ClosingException("disconnected");
Expand All @@ -85,8 +85,7 @@ public void createClient_errorOnConnectionThrowsExecutionException() {
// exercise
CompletableFuture<RedisClient> result = CreateClient(config);

ExecutionException executionException =
assertThrows(ExecutionException.class, () -> result.get());
ExecutionException executionException = assertThrows(ExecutionException.class, result::get);

// verify
assertEquals(exception, executionException.getCause());
Expand Down
24 changes: 13 additions & 11 deletions java/client/src/test/java/glide/managers/CommandManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import glide.managers.models.Command;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -47,8 +48,8 @@ void init() {
}

@Test
public void submitNewCommand_returnObjectResult()
throws ExecutionException, InterruptedException {
@SneakyThrows
public void submitNewCommand_return_Object_result() {

// setup
long pointer = -1;
Expand All @@ -60,7 +61,7 @@ public void submitNewCommand_returnObjectResult()
when(channelHandler.write(any(), anyBoolean())).thenReturn(future);

// exercise
CompletableFuture result =
CompletableFuture<Object> result =
service.submitNewCommand(
command, new BaseCommandResponseResolver((ptr) -> ptr == pointer ? respObject : null));
Object respPointer = result.get();
Expand All @@ -70,15 +71,16 @@ public void submitNewCommand_returnObjectResult()
}

@Test
public void submitNewCommand_returnNullResult() throws ExecutionException, InterruptedException {
@SneakyThrows
public void submitNewCommand_return_Null_result() {
// setup
Response respPointerResponse = Response.newBuilder().build();
CompletableFuture<Response> future = new CompletableFuture<>();
future.complete(respPointerResponse);
when(channelHandler.write(any(), anyBoolean())).thenReturn(future);

// exercise
CompletableFuture result =
CompletableFuture<Object> result =
service.submitNewCommand(
command, new BaseCommandResponseResolver((p) -> new RuntimeException("")));
Object respPointer = result.get();
Expand All @@ -88,8 +90,8 @@ public void submitNewCommand_returnNullResult() throws ExecutionException, Inter
}

@Test
public void submitNewCommand_returnStringResult()
throws ExecutionException, InterruptedException {
@SneakyThrows
public void submitNewCommand_return_String_result() {

// setup
long pointer = 123;
Expand All @@ -102,7 +104,7 @@ public void submitNewCommand_returnStringResult()
when(channelHandler.write(any(), anyBoolean())).thenReturn(future);

// exercise
CompletableFuture result =
CompletableFuture<Object> result =
service.submitNewCommand(
command, new BaseCommandResponseResolver((p) -> p == pointer ? testString : null));
Object respPointer = result.get();
Expand All @@ -113,7 +115,7 @@ public void submitNewCommand_returnStringResult()
}

@Test
public void submitNewCommand_throwClosingException() {
public void submitNewCommand_throw_closing_exception() {

// setup
String errorMsg = "Closing";
Expand All @@ -129,7 +131,7 @@ public void submitNewCommand_throwClosingException() {
assertThrows(
ExecutionException.class,
() -> {
CompletableFuture result =
CompletableFuture<Object> result =
service.submitNewCommand(
command, new BaseCommandResponseResolver((ptr) -> new Object()));
result.get();
Expand Down Expand Up @@ -164,7 +166,7 @@ public void BaseCommandResponseResolver_handles_all_errors(
assertThrows(
ExecutionException.class,
() -> {
CompletableFuture result =
CompletableFuture<Object> result =
service.submitNewCommand(command, new BaseCommandResponseResolver((ptr) -> null));
result.get();
});
Expand Down
36 changes: 17 additions & 19 deletions java/client/src/test/java/glide/managers/ConnectionManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import connection_request.ConnectionRequestOuterClass.AuthenticationInfo;
import connection_request.ConnectionRequestOuterClass.ConnectionRequest;
import connection_request.ConnectionRequestOuterClass.ConnectionRetryStrategy;
import connection_request.ConnectionRequestOuterClass.TlsMode;
import glide.api.models.configuration.BackoffStrategy;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.ReadFrom;
Expand All @@ -32,6 +33,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import response.ResponseOuterClass;
import response.ResponseOuterClass.ConstantResponse;
import response.ResponseOuterClass.Response;

public class ConnectionManagerTest {
Expand All @@ -54,7 +56,7 @@ public class ConnectionManagerTest {
private static int REQUEST_TIMEOUT = 3;

@BeforeEach
public void setUp() throws ExecutionException, InterruptedException {
public void setUp() {
channel = mock(ChannelHandler.class);
ChannelFuture closeFuture = mock(ChannelFuture.class);
when(closeFuture.syncUninterruptibly()).thenReturn(closeFuture);
Expand All @@ -64,18 +66,17 @@ public void setUp() throws ExecutionException, InterruptedException {

@SneakyThrows
@Test
public void ConnectionRequestProtobufGeneration_DefaultRedisClientConfiguration_returns() {
public void connection_request_protobuf_generation_default_standalone_configuration() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
ConnectionRequest expectedProtobufConnectionRequest =
ConnectionRequest.newBuilder()
.setTlsMode(ConnectionRequestOuterClass.TlsMode.NoTls)
.setTlsMode(TlsMode.NoTls)
.setClusterModeEnabled(false)
.setReadFrom(ConnectionRequestOuterClass.ReadFrom.Primary)
.build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response =
Response.newBuilder().setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
Response response = Response.newBuilder().setConstantResponse(ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand All @@ -89,19 +90,18 @@ public void ConnectionRequestProtobufGeneration_DefaultRedisClientConfiguration_

@SneakyThrows
@Test
public void ConnectionRequestProtobufGeneration_DefaultRedisClusterClientConfiguration_returns() {
public void connection_request_protobuf_generation_default_cluster_configuration() {
// setup
RedisClusterClientConfiguration redisClusterClientConfiguration =
RedisClusterClientConfiguration.builder().build();
ConnectionRequest expectedProtobufConnectionRequest =
ConnectionRequest.newBuilder()
.setTlsMode(ConnectionRequestOuterClass.TlsMode.NoTls)
.setTlsMode(TlsMode.NoTls)
.setClusterModeEnabled(true)
.setReadFrom(ConnectionRequestOuterClass.ReadFrom.Primary)
.build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response =
Response.newBuilder().setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
Response response = Response.newBuilder().setConstantResponse(ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand All @@ -116,7 +116,7 @@ public void ConnectionRequestProtobufGeneration_DefaultRedisClusterClientConfigu

@SneakyThrows
@Test
public void ConnectionRequestProtobufGeneration_RedisClientAllFieldsSet_returns() {
public void connection_request_protobuf_generation_with_all_fields_set() {
// setup
RedisClientConfiguration redisClientConfiguration =
RedisClientConfiguration.builder()
Expand Down Expand Up @@ -146,7 +146,7 @@ public void ConnectionRequestProtobufGeneration_RedisClientAllFieldsSet_returns(
.setHost(DEFAULT_HOST)
.setPort(DEFAULT_PORT)
.build())
.setTlsMode(ConnectionRequestOuterClass.TlsMode.SecureTls)
.setTlsMode(TlsMode.SecureTls)
.setReadFrom(ConnectionRequestOuterClass.ReadFrom.PreferReplica)
.setClusterModeEnabled(false)
.setAuthenticationInfo(
Expand All @@ -161,8 +161,7 @@ public void ConnectionRequestProtobufGeneration_RedisClientAllFieldsSet_returns(
.setDatabaseId(DATABASE_ID)
.build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response =
Response.newBuilder().setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
Response response = Response.newBuilder().setConstantResponse(ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand All @@ -176,12 +175,11 @@ public void ConnectionRequestProtobufGeneration_RedisClientAllFieldsSet_returns(

@SneakyThrows
@Test
public void CheckRedisResponse_ConstantResponse_returnsSuccessfully() {
public void response_validation_on_constant_response_returns_successfully() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response =
Response.newBuilder().setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
Response response = Response.newBuilder().setConstantResponse(ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand All @@ -194,7 +192,7 @@ public void CheckRedisResponse_ConstantResponse_returnsSuccessfully() {
}

@Test
public void onConnection_emptyResponse_throwsClosingException() {
public void connection_on_empty_response_throws_ClosingException() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Expand All @@ -214,7 +212,7 @@ public void onConnection_emptyResponse_throwsClosingException() {
}

@Test
public void CheckRedisResponse_RequestError_throwsClosingException() {
public void connection_on_resp_pointer_throws_ClosingException() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Expand All @@ -240,7 +238,7 @@ public void CheckRedisResponse_RequestError_throwsClosingException() {
}

@Test
public void CheckRedisResponse_ClosingError_throwsClosingException() {
public void check_response_on_closing_error_throws_ClosingException() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Expand Down

0 comments on commit 07e6d43

Please sign in to comment.