-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Add transaction requests for standalone and cluster-mode #70
Java: Add transaction requests for standalone and cluster-mode #70
Conversation
… response (#59) * Add cluster client and routes support for cluster client. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR feedback and add tests. Signed-off-by: Yury-Fridlyand <[email protected]> * Minor javadoc update. Signed-off-by: Yury-Fridlyand <[email protected]> * Minor javadoc fix Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR review comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR review comments. Signed-off-by: Yury-Fridlyand <[email protected]> * Address PR review comments. Signed-off-by: Yury-Fridlyand <[email protected]> --------- Signed-off-by: Yury-Fridlyand <[email protected]>
java/client/src/main/java/glide/connectors/handlers/ChannelHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
9a16d86
to
6d308d2
Compare
Signed-off-by: Yury-Fridlyand <[email protected]>
java/client/src/main/java/glide/api/commands/StringCommands.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Carbonetto <[email protected]>
…o_api_transactions
Signed-off-by: Andrew Carbonetto <[email protected]>
java/client/src/main/java/glide/api/models/configuration/Route.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Carbonetto <[email protected]>
command, | ||
RequestType.CUSTOM_COMMAND, | ||
args, | ||
Optional.ofNullable(route), | ||
response -> | ||
route.isSingleNodeRoute() | ||
? ClusterValue.ofSingleValue(handleObjectResponse(response)) | ||
: ClusterValue.ofMultiValue((Map<String, Object>) handleObjectResponse(response))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are not actually casting the keys in to strings with this (Map<String, Object>) , at runtime they will still remain as type Object not string. We may need to cast keys individually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test this and update the examples in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please groom all javadocs to follow our standard we recently discussed.
- Do you want to rebase on top of IT branch and add ITs?
- Please address all comments posted in Add GET/SET/INFO/PING commands #66 here.
java/client/src/main/java/glide/api/commands/ClusterBaseCommands.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncomment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated... these tests became fairly simple.
java/client/src/test/java/glide/api/RedisClusterClientClusterTransactionTests.java
Outdated
Show resolved
Hide resolved
java/client/src/test/java/glide/api/RedisClusterClientTest.java
Outdated
Show resolved
Hide resolved
java/client/src/test/java/glide/managers/CommandManagerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add IT tests for this.
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
1ea0060
to
150e0fd
Compare
…o_api_transactions
Signed-off-by: Andrew Carbonetto <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to change the test approach:
- in UT test that
client.command
causes the correct protobuf request. This will engage frontend-write client part and provide enough code coverage - all rest - in IT
String key = "testKey"; | ||
String value = "testValue"; | ||
CompletableFuture<Void> testResponse = mock(CompletableFuture.class); | ||
when(testResponse.get()).thenReturn(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is no-op. A mock always returns null for all calls unless reconfigured.
but null != void
when(testResponse.get()).thenReturn(null); | |
when(testResponse.get()).thenReturn(Void); |
Is it possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference, really.
CompletableFuture<ClusterValue<String>> response = service.info(route); | ||
|
||
// verify | ||
assertEquals(testResponse, response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Andrew Carbonetto <[email protected]>
@@ -69,18 +69,18 @@ public ChannelHandler( | |||
/** | |||
* Complete a protobuf message and write it to the channel (to UDS). | |||
* | |||
* @param request Incomplete request, function completes it by setting callback ID | |||
* @param requestBuilder Incomplete request, function completes it by setting callback ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
@Getter | ||
public abstract class BaseTransaction<T extends BaseTransaction<T>> { | ||
/** Command class to send a single request to Redis. */ | ||
Transaction.Builder transactionBuilder = Transaction.newBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with List<Pair<RequestType, String[]>> and in the prepareRedisRequest, convert the list to a Transaction.Builder.
@@ -73,7 +73,7 @@ public void createClient_with_config_successfully_returns_RedisClient() { | |||
|
|||
@SneakyThrows | |||
@Test | |||
public void createClient_error_on_connection_throws_ExecutionException() { | |||
public void createClient_throws_ExecutionException() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
CompletableFuture<Object> testResponse = mock(CompletableFuture.class); | ||
when(testResponse.get()).thenReturn(value); | ||
when(commandManager.submitNewCommand(any(), any())).thenReturn(testResponse); | ||
|
||
ArgumentCaptor<RedisRequestOuterClass.RedisRequest.Builder> captor = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
String key = "testKey"; | ||
String value = "testValue"; | ||
CompletableFuture<Void> testResponse = mock(CompletableFuture.class); | ||
when(testResponse.get()).thenReturn(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference, really.
// setup | ||
String key = "testKey"; | ||
String value = "testValue"; | ||
CompletableFuture<Void> testResponse = mock(CompletableFuture.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to real object and complete it with null.
response -> | ||
route.isSingleNodeRoute() | ||
? ClusterValue.ofSingleValue(handleObjectResponse(response)) | ||
: ClusterValue.ofMultiValue((Map<String, Object>) handleObjectResponse(response))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Object[]> exec(ClusterTransaction transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to test this:
- Is this a list of ClusterValue[], OR
- Is this a ClusterValue(Object[])
} | ||
|
||
@Override | ||
public CompletableFuture<Object[]> exec(ClusterTransaction transaction, Route route) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -20,23 +22,31 @@ public interface Route { | |||
boolean isSingleNodeRoute(); | |||
} | |||
|
|||
@RequiredArgsConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase
@@ -40,7 +40,6 @@ public static EventLoopGroup createOrGetNettyThreadPool( | |||
() -> new EpollEventLoopGroup(threadCount, new DefaultThreadFactory(name, true))); | |||
} | |||
// TODO support IO-Uring and NIO | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@SneakyThrows | ||
@ParameterizedTest | ||
@EnumSource(RequestType.class) | ||
public void submitNewCommand_covers_all_mapRequestTypes(RequestType requestType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this test
Description:
Adds transactions for both standalone and cluster clients. This allows users to specify a route (for cluster clients) and a pipeline of commands in a Transaction object. The object is then passed to Redis through the
submitNewCommand(Transaction)
call.This PR also adds get/set/ping/info calls to the standalone, cluster, and transactions.
Examples: