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

Container inspect and start + unit tests #56

Merged
merged 5 commits into from
Mar 19, 2018
Merged

Container inspect and start + unit tests #56

merged 5 commits into from
Mar 19, 2018

Conversation

amihaiemil
Copy link
Owner

PR for #46 implemented and unit tested Container.inspect and Container.start. Left puzzle for continuing implementation.

@0crat
Copy link
Collaborator

0crat commented Mar 18, 2018

Job #56 is now in scope, role is REV

@coveralls
Copy link

coveralls commented Mar 18, 2018

Pull Request Test Coverage Report for Build 84

  • 16 of 19 (84.21%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+3.6%) to 81.553%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/main/java/com/amihaiemil/docker/RtDocker.java 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
src/main/java/com/amihaiemil/docker/RtDocker.java 1 42.86%
Totals Coverage Status
Change from base Build 76: 3.6%
Covered Lines: 84
Relevant Lines: 103

💛 - Coveralls

@amihaiemil
Copy link
Owner Author

@0crat assign @llorllale

@0crat
Copy link
Collaborator

0crat commented Mar 18, 2018

@0crat assign @llorllale (here)

@amihaiemil This pull request #56 is assigned to @llorllale/z, here is why. The budget is 15 minutes, see §4. Please, read §27 and when you decide to accept the changes, inform @amihaiemil/z (the architect) right in this ticket. If you decide that this PR should not be accepted ever, also inform the architect.

@0crat
Copy link
Collaborator

0crat commented Mar 18, 2018

Manual assignment of issues is discouraged, see §19: -5 points just awarded to @amihaiemil/z

@amihaiemil
Copy link
Owner Author

@llorllale I gave you the REV role. I think this will catch some mistakes I make and also help you learn the architecture better :D

final HttpResponse response = this.client.execute(start);
final int status = response.getStatusLine().getStatusCode();
if(status!= HttpStatus.SC_NO_CONTENT) {
throw new IllegalStateException(
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil why not throw IOException?

Copy link
Owner Author

Choose a reason for hiding this comment

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

@llorllale Because, as I understand it, IOException should be used only when there are real issues on the network. We have a puzzle for that, we would need an UnexpectedResponseException, which would provide the status and reason phrase to the user.

So, once that puzzle is fixed, this throw will be changed as well, it won't be IllegalStateException.

If we simply throw IOException the user won't know whether there was a real networking issue (e.g. timeout connection) or something else.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil It's a design decision. We are currently not declaring any other checked exception, so I assume this new UnexpectedResponseException would be runtime? I'd throw an IOException (or a subclass) because it's already in the API's contract.

I think this is a design call and that you have final say.

Copy link
Contributor

@llorllale llorllale left a comment

Choose a reason for hiding this comment

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

@amihaiemil see above

} else {
info = null;
}
inspect.releaseConnection();
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil see this. I think we should leave a puzzle for abstracting away all the low-level apache http handling stuff into a single point. Something like "Encapsulate HTTP connection/request/response handling" I guess. We'd gain:

  • Reduced risk per PR since we won't have to keep implementing/reviewing correct handling of HTTP resources
  • Reduce procedural code throughout the code base

@@ -25,12 +25,17 @@
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil you're leaving a puzzle for finishing implementation of the rest of the Container API, but I feel we need another one specifically for adding more test cases for start and inspect

final HttpResponse response = this.client.execute(start);
final int status = response.getStatusLine().getStatusCode();
if(status!= HttpStatus.SC_NO_CONTENT) {
throw new IllegalStateException(
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil It's a design decision. We are currently not declaring any other checked exception, so I assume this new UnexpectedResponseException would be runtime? I'd throw an IOException (or a subclass) because it's already in the API's contract.

I think this is a design call and that you have final say.

@amihaiemil
Copy link
Owner Author

@llorllale I wrote more unit tests and left a puzzle for integration tests.

About refactoring of HTTP calls, yes, should be done eventually (I also noticed we already have a little duplication, especially with reading the Json payload). But I am not sure what you have in mind about it, could you open an Issue and explain in more detail?

And yes, UnexpectedResponseException would be a RuntimException, mostly because users may be sure that the calls will be succesful (container exists, can be started etc), it makes no sense to polute their code with try/catch always.

@llorllale
Copy link
Contributor

@amihaiemil

it makes no sense to polute their code with try/catch always.

But Container.start() declares a checked exception (IOException)...

@amihaiemil
Copy link
Owner Author

@llorllale Yes, but IOException is another story; as I said above, that is for networking problems. Receiving a 404 response from Container.inspect() for instance, is not a networking problem, that's how the API works since the Container was not found anymore... we just don't know how to handle that situation so we throw an exception.

They try/catch for IOException, but it should be clear what is its purpose. If we make UnexpectedResponseException extend IOException, then they will have to check the type of IOException in every catch and make sure it's not actually a valid, but unexpected response. Makes sense now? :D

info = Json
.createReader(response.getEntity().getContent()).readObject();
} else {
info = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil why are we returning null? Why not throw an error? Or why not have the return type be Optional<JsonObject>?

I really think we should throw an error. At the very least, not return null in any case.

* RtContainer throws ISE if it cannot start.
* @throws Exception If something goes wrong.
*/
@Test(expected = IllegalStateException.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil RtContainer.start() missing tests on receiving 404 and 304 from the docker API

@llorllale
Copy link
Contributor

@amihaiemil left a couple more comments

Makes sense now?

I understood you from the start, we just happen to disagree, but that's OK.

@amihaiemil
Copy link
Owner Author

@llorllale fixed the null; throws ISE same as start(), for now. I also added more tests for those statuses :)

* @throws Exception If something goes wrong.
*/
@Test(expected = IllegalStateException.class)
public void startsWithServerError() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

@amihaiemil can you remove the Conditions on the startsWith*Error tests in order to remove some noise? Those conditions are already tested for in the startsOk test.

Copy link
Owner Author

Choose a reason for hiding this comment

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

@llorllale haha, you're good at this. Sure :)

@llorllale
Copy link
Contributor

@amihaiemil just one more minor comment and we're golden

@amihaiemil
Copy link
Owner Author

@rultor merge it

@rultor
Copy link
Collaborator

rultor commented Mar 19, 2018

@rultor merge it

@amihaiemil OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit ca2e586 into master Mar 19, 2018
@amihaiemil amihaiemil deleted the 46 branch March 19, 2018 18:26
@rultor
Copy link
Collaborator

rultor commented Mar 19, 2018

@rultor merge it

@amihaiemil Done! FYI, the full log is here (took me 2min)

@0crat
Copy link
Collaborator

0crat commented Mar 19, 2018

Order was finished: +15 points just awarded to @llorllale/z

@0crat
Copy link
Collaborator

0crat commented Mar 19, 2018

The job #56 is now out of scope

@0crat
Copy link
Collaborator

0crat commented Mar 19, 2018

Payment to ARC for a closed pull request, as in §28: +10 points just awarded to @amihaiemil/z

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.

None yet

6 participants