You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "devCod3r (via GitHub)" <gi...@apache.org> on 2023/07/27 18:01:53 UTC

[PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

devCod3r opened a new pull request, #4298:
URL: https://github.com/apache/eventmesh/pull/4298

   Fixes #4268
   
   ### Motivation
   
   Replaced the if-else statements with switch.
   Issue #4268
   
   ### Modifications
   
   Replaced the if-else statements with switch.
   
   ### Documentation
   
   - Does this pull request introduce a new feature?
   - Ans: No
   - If a feature is not applicable for documentation, explain why?
   - Ans: Only replaced the if-else statements with switch.
   


-- 
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: dev-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "pandaapo (via GitHub)" <gi...@apache.org>.
pandaapo commented on PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298#issuecomment-1669379434

   @devCod3r This pr brought a bug. Refer the https://github.com/apache/eventmesh/pull/4298#discussion_r1276985757. If you are willing, you can post a new issue and pr to fix the bug.


-- 
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: issues-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "silentchildh (via GitHub)" <gi...@apache.org>.
silentchildh commented on code in PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298#discussion_r1276985757


##########
eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java:
##########
@@ -89,16 +87,16 @@ private CloudEvent deserializeHttpProtocol(String requestCode,
         org.apache.eventmesh.common.protocol.http.header.Header header,
         Body body) throws ProtocolHandleException {
 
-        if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
+        switch (RequestCode.valueOf(requestCode)) {

Review Comment:
   `valueOf` method is to transfer an Enum constant specified name to return an  Enum constant.So It can not transfer `requestCode` as specified name to get any Enum constant.
   ![image](https://github.com/apache/eventmesh/assets/122422744/ba9f26f7-74fa-43f6-93be-8553809ca3e3)
   
   So as the same as #4270.It causes client to fail to connect to the runtime server.
   ![image](https://github.com/apache/eventmesh/assets/122422744/a1b43423-c607-4dfb-a9e4-b0b712e66251)
   
   



-- 
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: issues-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "lrhkobe (via GitHub)" <gi...@apache.org>.
lrhkobe merged PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298


-- 
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: dev-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "Alonexc (via GitHub)" <gi...@apache.org>.
Alonexc commented on PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298#issuecomment-1654875292

   This method already exists in this class, and the valueOf() method can be changed to get():
   ![image](https://github.com/apache/eventmesh/assets/91315508/9750d65b-897e-4c17-bc75-97f12c605ba7)
   


-- 
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: issues-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298#issuecomment-1654847337

   ## [Codecov](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#4298](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (0b5dd43) into [master](https://app.codecov.io/gh/apache/eventmesh/commit/c18ef05f5207a2d1b6e992ab4e6f1a9b54e021ce?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (c18ef05) will **increase** coverage by `0.02%`.
   > Report is 9 commits behind head on master.
   > The diff coverage is `20.00%`.
   
   > :exclamation: Current head 0b5dd43 differs from pull request most recent head 77839f6. Consider uploading reports for the commit 77839f6 to get more accurate results
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #4298      +/-   ##
   ============================================
   + Coverage     16.87%   16.89%   +0.02%     
   - Complexity     1426     1428       +2     
   ============================================
     Files           593      593              
     Lines         26068    26056      -12     
     Branches       2396     2396              
   ============================================
   + Hits           4398     4402       +4     
   + Misses        21229    21214      -15     
   + Partials        441      440       -1     
   ```
   
   
   | [Files Changed](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...time/admin/handler/DeleteWebHookConfigHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvRGVsZXRlV2ViSG9va0NvbmZpZ0hhbmRsZXIuamF2YQ==) | `26.66% <ø> (ø)` | |
   | [...time/admin/handler/InsertWebHookConfigHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvSW5zZXJ0V2ViSG9va0NvbmZpZ0hhbmRsZXIuamF2YQ==) | `26.66% <ø> (ø)` | |
   | [.../admin/handler/QueryRecommendEventMeshHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUXVlcnlSZWNvbW1lbmRFdmVudE1lc2hIYW5kbGVyLmphdmE=) | `92.59% <ø> (ø)` | |
   | [...e/admin/handler/QueryWebHookConfigByIdHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUXVlcnlXZWJIb29rQ29uZmlnQnlJZEhhbmRsZXIuamF2YQ==) | `26.66% <0.00%> (ø)` | |
   | [...ndler/QueryWebHookConfigByManufacturerHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUXVlcnlXZWJIb29rQ29uZmlnQnlNYW51ZmFjdHVyZXJIYW5kbGVyLmphdmE=) | `28.57% <0.00%> (ø)` | |
   | [...e/admin/handler/RedirectClientByIpPortHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVkaXJlY3RDbGllbnRCeUlwUG9ydEhhbmRsZXIuamF2YQ==) | `34.04% <0.00%> (+2.66%)` | :arrow_up: |
   | [...dmin/handler/RedirectClientBySubSystemHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVkaXJlY3RDbGllbnRCeVN1YlN5c3RlbUhhbmRsZXIuamF2YQ==) | `9.09% <ø> (ø)` | |
   | [.../runtime/admin/handler/RejectAllClientHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVqZWN0QWxsQ2xpZW50SGFuZGxlci5qYXZh) | `12.50% <ø> (ø)` | |
   | [...ime/admin/handler/RejectClientByIpPortHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVqZWN0Q2xpZW50QnlJcFBvcnRIYW5kbGVyLmphdmE=) | `9.30% <ø> (ø)` | |
   | [.../admin/handler/RejectClientBySubSystemHandler.java](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXJ1bnRpbWUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2V2ZW50bWVzaC9ydW50aW1lL2FkbWluL2hhbmRsZXIvUmVqZWN0Q2xpZW50QnlTdWJTeXN0ZW1IYW5kbGVyLmphdmE=) | `8.33% <ø> (ø)` | |
   | ... and [14 more](https://app.codecov.io/gh/apache/eventmesh/pull/4298?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
   
   ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/apache/eventmesh/pull/4298/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
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: issues-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org


Re: [PR] [ISSUE #4268] Used switch to replace the if-else [CloudEventsProtocolAdaptor] (eventmesh)

Posted by "Alonexc (via GitHub)" <gi...@apache.org>.
Alonexc commented on code in PR #4298:
URL: https://github.com/apache/eventmesh/pull/4298#discussion_r1276986991


##########
eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java:
##########
@@ -89,16 +87,16 @@ private CloudEvent deserializeHttpProtocol(String requestCode,
         org.apache.eventmesh.common.protocol.http.header.Header header,
         Body body) throws ProtocolHandleException {
 
-        if (String.valueOf(RequestCode.MSG_BATCH_SEND.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_BATCH_SEND_V2.getRequestCode()).equals(requestCode)) {
-            return SendMessageBatchV2ProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_SYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else if (String.valueOf(RequestCode.MSG_SEND_ASYNC.getRequestCode()).equals(requestCode)) {
-            return SendMessageRequestProtocolResolver.buildEvent(header, body);
-        } else {
-            throw new ProtocolHandleException(String.format("unsupported requestCode: %s", requestCode));
+        switch (RequestCode.valueOf(requestCode)) {

Review Comment:
   Sorry, my mistake here, the valueof here returns the enum constant for the specified string value, here it is judged by the `requestCode`, so it won't match up by doing so.
   You might consider writing a method in the `RequestCode` class that returns the corresponding Enum type constant based on the `requestCode`.



-- 
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: issues-unsubscribe@eventmesh.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org