Skip to content

added check for open port before creating test server.#769

Merged
littleaj merged 2 commits into
masterfrom
fixJettyBindTest
Nov 12, 2018
Merged

added check for open port before creating test server.#769
littleaj merged 2 commits into
masterfrom
fixJettyBindTest

Conversation

@littleaj

@littleaj littleaj commented Nov 9, 2018

Copy link
Copy Markdown
Contributor

This makes the tests a bit more reliable.

@littleaj littleaj added this to the 2.2.1 milestone Nov 9, 2018
@littleaj littleaj self-assigned this Nov 9, 2018
@littleaj littleaj requested review from dhaval24 and grlima November 9, 2018 19:00

@dhaval24 dhaval24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @littleaj I think either I am confused and don't fully understand the purpose or may be you need to consider fixing the logic :). Please let me know either ways and I can unblock you.

@dhaval24 dhaval24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few best practice suggestions. It would be awesome if you can make those changes. Rest looks good.

private int Min = 1050;
private int Max = 15000;
private int portNumber = Min + (int)(Math.random() * ((Max - Min) + 1));
private final int Min = 1050;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@littleaj can you please adhere to camelCase for varable names here. I know you didn't made this variable but since you touched this part of the code better that we can clean up if possible.


public JettyTestServer() {
// try 256 times for ports
int initialPortNumber = Min + (int)(Math.random() * ((Max - Min) + 1));

@dhaval24 dhaval24 Nov 10, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A standard way / best practice in java to get random integer within the range is this:

import java.util.concurrent.ThreadLocalRandom;

// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);

Reference: https://stackoverflow.com/questions/363681/how-to-generate-random-integers-within-a-specific-range-in-java

We don't need to reproduce the results, so seed of random doesn't really matter.

@littleaj it would be great if you can change this one as bonus!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since this is test code, so I'm not really worried about this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool :) no worries. Please proceed with merging.

@littleaj littleaj merged commit d774bec into master Nov 12, 2018
@littleaj littleaj deleted the fixJettyBindTest branch November 12, 2018 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants