-
Notifications
You must be signed in to change notification settings - Fork 641
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
[ISSUE #4602] when wechat send message api response errcode is not zero, the wechat sink connector does not throw IllegalAccessException #4603
Conversation
@@ -166,9 +166,9 @@ private void sendMessage(ConnectRecord record) { | |||
throw new IOException("message response is null."); | |||
} | |||
|
|||
if (messageResponse.getErrocode() != 0) { | |||
if (messageResponse.getErrcode() != 0) { | |||
throw new IllegalAccessException(String.format("Send message to weCom error! errorCode=%s, errorMessage=%s", |
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 change "weCom" to "wechat".
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.
ok, thank for your reveiw,
weChatSinkConnector.put(records); | ||
verify(okHttpClient, times(times + 1)).newCall(any(Request.class)); | ||
verify(okHttpClient, times(2)).newCall(any(Request.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.
Is it better to use JUnit's assertThrows() to assert exceptions at this point?
这时候使用JUnit的assertThrows()断言异常是不是更好一点?
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.
weChatSinkConnector.sendMessage() method throw IllegalAccessException then weChatSinkConnector.put() catch the exception, i want to test weChatSinkConnector.sendMessage() ,but it is a private method ,i used reflect api to invoke the weChatSinkConnector.sendMessage() and then throw InvocationTargetException, IllegalAccessException has been transfer to InvocationTargetException, so the code will like this
i think it looks a little strange
WeChatSinkConnector.sendMessage()方法抛出IllegalAccessException然后weChatSinkConnector.put()捕捉异常,我想测试weChatSinkConnector.sendMessage(),但它是一个私有方法,我使用反射API调用weChatSinkConnector.sendMessage(),然后抛出InvocationTargetException,IllegalAccessException已经传递给InvocationTargetException,所以代码将如下所示。
我觉得它看起来有点奇怪
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.
any idea for test private method, i konw powermock can test private method, it is a good idea to use it? @pandaapo
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 used reflect api to invoke the weChatSinkConnector.sendMessage() and then throw InvocationTargetException, IllegalAccessException has been transfer to InvocationTargetException, ... i think it looks a little strange
It may seem a bit strange, but I don't have a better idea at the moment. I personally disagree with PowerMockito, as it is not as restrained as Mockito, but it's just my personal opinion. You can choose to use reflection, PowerMockito, or directly test abnormal put() to indirectly test abnormal sendMessage(), or write a public sendMessageOnlyForTest() that calls sendMessage() in WeChatSinkConnector and test this method.
确实这样会有点奇怪,但是我目前也没有更好的主意。对于PowerMockito,我个人不太认同,它不像Mockito更加克制,但只是我个人观点。您可以自己选择使用反射,或者PowerMockito,或者直接测试put()异常情况来间接测试sendMessage()异常情况,或者写个调用sendMessage()的公开的sendMessageOnlyForTest()在WeChatSinkConnector中,然后测试这个方法。
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.
ok, i choose to use JUnit's assertThrows()
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.
You can add this Sink Connector to the list in this document. https://github.com/apache/eventmesh/tree/master/eventmesh-connectors#connector-status
already done, please review |
I saw that you did this work in another PR. You can close that PR and make modifications directly in this PR. |
…erver again to fix org.mockito.exceptions.misusing.UnnecessaryStubbingException
weChatSinkConnector.put(records); | ||
verify(okHttpClient, times(2)).newCall(any(Request.class)); | ||
|
||
WeChatSinkConnector.ACCESS_TOKEN_CACHE.invalidate(WeChatSinkConnector.ACCESS_TOKEN_CACHE_KEY); |
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 am thinking about the necessity of this line of code. It seems that you did not actually interact with WeChat in your test, so you should not be using this token.
我在思考这行代码的必要性。您的测试中好像并不会真的与wechat交互,应该用不到该token吧。
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.
first u should use app id and app secret to get a token, then use token to send message. so i mock a get token response and store the token in cache, in testSendMessageToWeChat() method, the mock token repsone is used, and then in testSendMessageToWeChatAbnormally() method, the mock token repsone will not be used, because token has been stored in cache and then will throw a org.mockito.exceptions.misusing.UnnecessaryStubbingException. the test result like this
testSendMessageToWeChat() passed, testSendMessageToWeChatAbnormally() failed
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.
Finally, are you willing to write a document for your connector (#4601 (comment)) to facilitate user understanding and use. If you are willing, you can do it in this PR or in a new PR in the future.
最后,请问是否愿意给您的这个Connector写一下文档 (#4601 (comment) ),方便用户理解和使用。如果您愿意,可以在该PR中做,也可以以后在新的PR中做。
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.
LGTM
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4603 +/- ##
============================================
+ Coverage 16.93% 16.95% +0.01%
- Complexity 1693 1695 +2
============================================
Files 788 788
Lines 29420 29420
Branches 2539 2539
============================================
+ Hits 4983 4987 +4
+ Misses 23972 23969 -3
+ Partials 465 464 -1 ☔ View full report in Codecov by Sentry. |
i prefer in a new PR to do this |
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.
LGTM
@pandaapo hello, i found some commit in this PR used wrong email, so i want to close this PR, an create a new one |
Fixes #4602
Motivation
fix bug when wecaht api response fail
Modifications
rename org.apache.eventmesh.connector.wechat.sink.connector.TemplateMessageResponse#errocode
to org.apache.eventmesh.connector.wechat.sink.connector.TemplateMessageResponse#errcode
add abnormal test case