You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/17 03:34:39 UTC

[GitHub] [pulsar] yws-tracy opened a new pull request #14726: make `setMessageRoutingMode` method more readable

yws-tracy opened a new pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726


   <!--
   ### Contribution Checklist
     
     - Name the pull request in the form "[Issue XYZ][component] Title of the pull request", where *XYZ* should be replaced by the actual issue number.
       Skip *Issue XYZ* if there is no associated github issue for this pull request.
       Skip *component* if you are unsure about which is the best component. E.g. `[docs] Fix typo in produce method`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   *(If this PR fixes a github issue, please add `Fixes #<xyz>`.)*
   
   Fixes #<xyz>
   
   *(or if this PR is one task of a github issue, please add `Master Issue: #<xyz>` to link to the master issue.)*
   
   Master Issue: #<xyz>
   
   ### Motivation
   
   when I first read `setMessageRoutingMode`,  it's not readable, logic is not very clear,  I try to make it more readable and clear
   
   hope to be adopted, thanks
   
   ### Modifications
   
   split the check logic in `setMessageRoutingMode` method of  class `ProducerBuilderImpl` 
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly (if you have committer privilege).
   
   Need to update docs? 
   
   - [ ] `doc-required` 
     
     (If you need help on updating docs, create a doc issue)
     
   - [ ] `no-need-doc` 
     
     (Please explain why)
     
   - [ ] `doc` 
     
     (If this PR contains doc changes)
   
   
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on pull request #14726: make `setMessageRoutingMode` method more readable and supplement unit test for `messageRoutingMode`

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1078787264


   > 
   get, thanks!
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy removed a comment on pull request #14726: make `setMessageRoutingMode` method more readable and supplement unit test for `messageRoutingMode`

Posted by GitBox <gi...@apache.org>.
yws-tracy removed a comment on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1078787264


   > 
   get, thanks!
   


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on pull request #14726: make `setMessageRoutingMode` method more readable and optimize unit test for `messageRoutingMode`

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1084636597


   > > why cicd build failed? weird..... build ok in local env, can't it retry to run cicd?
   > 
   > You need rebase on latest master.
   
   could you help to review again ? thanks a lot


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1077651696


   why cicd build failed?  weird...


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] RobertIndie commented on a change in pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
RobertIndie commented on a change in pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#discussion_r830883331



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerBuilderImpl.java
##########
@@ -349,14 +349,24 @@ private ProducerBuilderImpl(PulsarClientImpl client, ProducerConfigurationData c
     private void setMessageRoutingMode() throws PulsarClientException {
         if (conf.getMessageRoutingMode() == null && conf.getCustomMessageRouter() == null) {
             messageRoutingMode(MessageRoutingMode.RoundRobinPartition);
-        } else if (conf.getMessageRoutingMode() == null && conf.getCustomMessageRouter() != null) {
+            return;
+        }
+        if (conf.getCustomMessageRouter() == null) {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() != MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is null, 'messageRoutingMode' should not be set as "
+                            + MessageRoutingMode.CustomPartition);
+        } else {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() == null
+                            || conf.getMessageRoutingMode() == MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is set, 'messageRoutingMode' should be set as "
+                            + MessageRoutingMode.CustomPartition);
             messageRoutingMode(MessageRoutingMode.CustomPartition);
-        } else if ((conf.getMessageRoutingMode() == MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() == null)
-                || (conf.getMessageRoutingMode() != MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() != null)) {
-            throw new PulsarClientException("When 'messageRouter' is set, 'messageRoutingMode' "
-                    + "should be set as " + MessageRoutingMode.CustomPartition);
+        }
+    }
+
+    private void checkMessageRoutingModeValid(boolean expression, String errorMessage) throws PulsarClientException {

Review comment:
       It doesn't make sense that there is no specific checking logic in `checkMessageRoutingModeValid`.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1073255956


   > unit
   
   
   
   > It‘s better to provide a unit test to make sure the logic stays the same.
   
   there is enough tests about messageRoutingMode, and I supplement the related unit test to ensure the logic is same


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] github-actions[bot] commented on pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1070240651


   @yws-tracy:Thanks for providing doc info!


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy commented on a change in pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
yws-tracy commented on a change in pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#discussion_r830922002



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerBuilderImpl.java
##########
@@ -349,14 +349,24 @@ private ProducerBuilderImpl(PulsarClientImpl client, ProducerConfigurationData c
     private void setMessageRoutingMode() throws PulsarClientException {
         if (conf.getMessageRoutingMode() == null && conf.getCustomMessageRouter() == null) {
             messageRoutingMode(MessageRoutingMode.RoundRobinPartition);
-        } else if (conf.getMessageRoutingMode() == null && conf.getCustomMessageRouter() != null) {
+            return;
+        }
+        if (conf.getCustomMessageRouter() == null) {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() != MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is null, 'messageRoutingMode' should not be set as "
+                            + MessageRoutingMode.CustomPartition);
+        } else {
+            checkMessageRoutingModeValid(conf.getMessageRoutingMode() == null
+                            || conf.getMessageRoutingMode() == MessageRoutingMode.CustomPartition,
+                    "When 'messageRouter' is set, 'messageRoutingMode' should be set as "
+                            + MessageRoutingMode.CustomPartition);
             messageRoutingMode(MessageRoutingMode.CustomPartition);
-        } else if ((conf.getMessageRoutingMode() == MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() == null)
-                || (conf.getMessageRoutingMode() != MessageRoutingMode.CustomPartition
-                && conf.getCustomMessageRouter() != null)) {
-            throw new PulsarClientException("When 'messageRouter' is set, 'messageRoutingMode' "
-                    + "should be set as " + MessageRoutingMode.CustomPartition);
+        }
+    }
+
+    private void checkMessageRoutingModeValid(boolean expression, String errorMessage) throws PulsarClientException {

Review comment:
       agree with u, and I renamed to  `checkMessageRoutingArgument` like` Preconditions.checkArgument`




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] yws-tracy edited a comment on pull request #14726: make `setMessageRoutingMode` method more readable and supplement unit test for `messageRoutingMode`

Posted by GitBox <gi...@apache.org>.
yws-tracy edited a comment on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1077651696


   why cicd build failed?   weird.....    build ok in local env,     can't  it  retry to run cicd?


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] Jason918 commented on pull request #14726: make `setMessageRoutingMode` method more readable and supplement unit test for `messageRoutingMode`

Posted by GitBox <gi...@apache.org>.
Jason918 commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1078579796


   
   > why cicd build failed? weird..... build ok in local env, can't it retry to run cicd?
   
   You need rebase on latest master.


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] github-actions[bot] commented on pull request #14726: make `setMessageRoutingMode` method more readable

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14726:
URL: https://github.com/apache/pulsar/pull/14726#issuecomment-1070230983


   @yws-tracy:Thanks for your contribution. For this PR, do we need to update docs?
   (The [PR template contains info about doc](https://github.com/apache/pulsar/blob/master/.github/PULL_REQUEST_TEMPLATE.md#documentation), which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org