Skip to content
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

[FLINK-4053] Return value from Connection should be checked against null #2128

Closed
wants to merge 4 commits into from

Conversation

mushketyk
Copy link
Contributor

Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the How To Contribute guide.
In addition to going through the list, please provide a meaningful description of your changes.

  • General
    • The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
    • The pull request addresses only one issue
    • Each commit in the PR has a meaningful commit message (including the JIRA id)
  • Documentation
    • Documentation has been added for new functionality
    • Old documentation affected by the pull request has been updated
    • JavaDoc for public methods has been added
  • Tests & Build
    • Functionality added by the pull request is covered by tests
    • mvn clean verify has been executed successfully locally or a Travis build has passed

* @throws IOException if failed to open RabbitMQ channel
* @throws RuntimeException if connection object returned null channel
*/
public static Channel createChannel(Connection connection) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a separate class and static method is a bit overkill for a null check.

@mushketyk
Copy link
Contributor Author

I wanted to avoid this bit of duplication, but I have no strong preferences for that. Will remove this static method.

}

@Test
public void throwExceptionIfChannenIsNull() throws Exception {
Copy link
Contributor

@zentol zentol Jun 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ChannelIsNull

@mushketyk
Copy link
Contributor Author

@zentol I've fixed my PR according to your comments.

@@ -76,6 +76,9 @@ public void open(Configuration config) throws Exception {
try {
connection = factory.newConnection();
channel = connection.createChannel();
if (channel == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know under which circumstances this can occur and/or what a user can do to resolve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand in RabbitMQ every real TCP connection has a number of virtual connections implemented on top of it. If we request a channel and it's not available "createChannel" returns null.
I've updated the exception message to reflect that.

I don't think this generally will be an issue, since we only request one channel for a connection, but it would be beneficial to throw an exception with an appropriate message instead of a NullPointerException in case if anything goes wrong.

@zentol
Copy link
Contributor

zentol commented Jun 27, 2016

I tihnk this looks good.

One remark for future contributions though: I think some of your tests are too specific.
These include openCallDeclaresQueue, throwExceptionIfChannelIsNull and invokePublishBytesToQueue.

Effectively you are not testing functionality but putting a lock on every single line of the implementation.

We will now get a test failure (which should mean that the functionality is broken) if we change the exception message (or even handle it completely), use a different basicPublish method (or pass different arguments) or pass different queueDeclare arguments.

@mushketyk
Copy link
Contributor Author

@zentol I see your point. Do you suggest to remove these tests?

@mushketyk
Copy link
Contributor Author

@zentol Should I update this PR somehow?

@zentol
Copy link
Contributor

zentol commented Jul 1, 2016

Thank your for reminding me, i forgot about this PR a bit :(

The PR is fine imo, +1 to merge.

@mushketyk
Copy link
Contributor Author

Hi all. If this is fine and useful, could someone please merge this?

@zentol
Copy link
Contributor

zentol commented Jul 15, 2016

merging

@asfgit asfgit closed this in a0c3b87 Jul 15, 2016
@mushketyk
Copy link
Contributor Author

Thank you @zentol !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants