spacemonkd commented on code in PR #1448:
URL: https://github.com/apache/ratis/pull/1448#discussion_r3613589384


##########
ratis-server/src/test/java/org/apache/ratis/ReadOnlyRequestTests.java:
##########
@@ -218,6 +236,20 @@ static int retrieve(RaftClientReply reply) {
     return 
Integer.parseInt(reply.getMessage().getContent().toString(StandardCharsets.UTF_8));
   }
 
+  static long getCount(RaftServer.Division server) {
+    return ((CounterStateMachine) server.getStateMachine()).getCount();
+  }
+
+  static <T> CompletableFuture<T> readOnlyAsync(
+      RaftServer.Division server, Supplier<CompletableFuture<T>> query) throws 
IOException {
+    return server.readOnlyAsync(ClientId.randomId(), 
RaftClientRequest.readRequestType().getRead(), query);

Review Comment:
   Just one suggestion. 
   As far as I understand from the code `ClientId.randomId()` is not used at 
all for the default path. It goes  straight to `checkLeaderStateForReadOnly` 
and then `supplyReadOnly`.
   
   Maybe we can overload the Division interface with something like:
   ```
    default <T> CompletableFuture<T> 
readOnlyAsync(Supplier<CompletableFuture<T>> query) throws IOException {
        return readOnlyAsync(ClientId.randomId(), 
ReadRequestTypeProto.getDefaultInstance(), query);
      }
   ```
   so that callers can avoid importing `ClientId` and `RaftClientRequest`?
   Right now it is only one call site so it is fine I guess, but if we have 
more callers this might be a better way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to