Skip to content

Comments

DefaultAzureArmNetworkCreator improvements#742

Merged
asfgit merged 1 commit intoapache:masterfrom
aledsage:pr739-minor-tidy
Jun 23, 2017
Merged

DefaultAzureArmNetworkCreator improvements#742
asfgit merged 1 commit intoapache:masterfrom
aledsage:pr739-minor-tidy

Conversation

@aledsage
Copy link
Contributor

  • Don’t use RETURNS_DEEP_STUBS as causes non-deterministic test failure
    on my dev machine (ClassCastException when calling thenReturn(...)!)
  • Tidy logging
  • Assert create() calls are made
  • Minor renames (e.g. _PREFIX to indicate DEFAULT_RESOURCE_GROUP constant is just the naming prefix)

Note the aim of the logging improvements is to ensure there is just one log.info message per provision request to say we're messing with the user's templateOptions, and one info message if we're creating default resource group, and one info message if creating default network/subnet. If we don't touch the user's config then we just log at debug.

Copy link
Contributor

@Graeme-Miller Graeme-Miller left a comment

Choose a reason for hiding this comment

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

Just one comment to address

assertEquals(templateOptions.get("unrelated-key"), "unrelated-value");
}

protected ConfigBag runVanilla(Map<?, ?> additionalConfig, boolean resoureGroupExists) 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.

I can see why you've created a generic vanilla test here (looks like it cuts down on code repetition), but I think that it introduces a couple of problems:
*) Makes the tests more difficult to understand (the runVanilla method itself is longer than an individual test used to be due to the necessity of adding if blocks to cope with different resource group cases)
*) Makes the tests more difficult to maintain (if the mock calls change for one of the tests, you have to modify the generic test and understand what all the other tests that rely on it expect it to do)

The tests themselves were pretty short before and as such I don't see a justification for this change. I would suggest reverting this to repeating the code per test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I first wrote the runVanilla method, it was exactly the same length as your existing test method - everything was duplicated in the two methods, with the only difference being one line at the start (to set up config) and one line at the end (to assert the config was still there). The tests are logically identical: the behaviour should be the same if you pass extra templateOptions or not. Therefore having a runVanilla(Map<?,?> additoinalConfig) makes sense I think.

The more controversial thing is then when adding boolean resourceGroupExists (which was previously untested). I could have duplicated the method - no strong feelings.

I think we can make our tests less brittle by being more relaxed about what we assert. For example verify(subnetApi, times(2)).get(TEST_SUBNET_NAME) - do we really care that it's exactly twice, or do we just care that it's atLeastOnce()?

I'll split it into two separate test methods, with duplication, as you suggest.


@Test
public void testIpOptionsInTemplate() {
public void testIpOptionsInTemplate() 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.

do these throw exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My personal option is that it's always a good idea for test methods to declare throws Exception. We're not writing the tests to assert that the signature of the method throws only specific checked exceptions (or no checked exception). Therefore not including the throws Exception just makes it more likely that subsequent refactoring might cause tests to fail to compile (which is annoying, as it might well have nothing to do with the tests it impacts). That's my opinion from past experience. In Brooklyn, it matters a lot less because we use unchecked exceptions a lot.

@aledsage
Copy link
Contributor Author

@Graeme-Miller incorporated review comments. Note that I've deleted some of the verify assertions. For example, I don't think it's worth calling verify(azureComputeApi).getVirtualNetworkApi(TEST_RESOURCE_GROUP) if we subsequently do verify(virtualNetworkApi) because the only way to get the virtualNetworkApi instance was to call the former method.

@aledsage
Copy link
Contributor Author

p.s. I'll squash together my two commits before we merge this! So please ping me with any other suggested changes, or if you think it's good to merge.

@Graeme-Miller
Copy link
Contributor

lgtm thanks @aledsage

* Don’t use RETURNS_DEEP_STUBS as causes non-deterministic test failure
  on my dev machine (ClassCastException when calling `thenReturn(...)`!)
* Tidy logging
* Assert create() calls are made
* Minor renames (e.g. _PREFIX to indicate DEFAULT_RESOURCE_GROUP
  constant is just the naming prefix)
@aledsage
Copy link
Contributor Author

Squashed into single commit; merging as soon as jenkins build finishes again.

@neykov
Copy link
Member

neykov commented Jun 22, 2017

LGTM, also see the comments I just added to #739

@asfgit asfgit merged commit 55b4460 into apache:master Jun 23, 2017
asfgit pushed a commit that referenced this pull request Jun 23, 2017
@aledsage
Copy link
Contributor Author

Merged.

@neykov (cc @Graeme-Miller) thanks for pointer to your comments in (the already merged) #739. We should address those separately, in a new PR.

@aledsage aledsage deleted the pr739-minor-tidy branch June 23, 2017 11:23
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.

4 participants