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

Add EntityAsserts and HttpUtils. #994

Merged
merged 7 commits into from
Nov 4, 2015
Merged

Conversation

geomacy
Copy link
Contributor

@geomacy geomacy commented Oct 30, 2015

This are added to allow core code to make assertions on entities without
without having a dependency on TestNG.

For now, deprecate EntityTestUtils and HttpTestUtils, and in the future these
can be removed in favour of the new classes.

This are added to allow core code to make assertions on entities without
without having a dependency on TestNG.

For now, deprecate EntityTestUtils and HttpTestUtils, and in the future these
can be removed in favour of the new classes.


@Beta @SafeVarargs
public static <T> void assertAttributeNever(final Entity entity, final AttributeSensor<T> attribute, T... disallowed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we call this assertAttributeContinuallyNotEqualTo?

add javadoc noting that this loops checking the value, it does not currently set up a subscription so a disallowed value might come up very quickly and be missed. (we could fix this if needed.)

cleaner would be for this to call the next method, assertAttribute...(Map, ...), with null flags, or perhaps to introduce an assertAttributeContinually(..., Predicate) and build up a predicate of not(or(equalTo(disallowed[0]), equalTo(disallowed[1]), ...))

@ahgittin
Copy link
Contributor

ahgittin commented Nov 2, 2015

need tests for the http assertions i think.

apart from that this looks real good and only minor comments.

Renamed assertAttributeNever to assertAttributeContinuallyNotEqualTo (apache#994 (comment)).

Updates as noted to deserializingClassRenames.properties (apache#994 (diff))

Fix package name in comment in EntityTestUtils (apache#994 (diff))

Removed a TODO in EntityTestUtils (apache#994 (diff))

Renamed HttpUtils to HttpAsserts; moved methods that weren't assertions to HttpTool, which involved bringing it out of core and into the utils module (apache#994 (comment))
@geomacy
Copy link
Contributor Author

geomacy commented Nov 2, 2015

hi Alex et al. I have made the changes related to the comments by Alex in the commits above.

The only one I haven't yet done is to add unit tests for HttpUtils. I don't want to hold back the others so I propose to do this in a separate pull request. I will get on to the tests for HttpUtils tomorrow morning.

Note that to nicely divide up the HttpAsserts from the non assertion methods I have moved HttpTool out of core and into the utils module. This results in imports changing in numerous files, so change 03dbd28 looks scarier than it really is (47 changed files).

@ahgittin
Copy link
Contributor

ahgittin commented Nov 2, 2015

For backwards compatibility we need to leave an HttpTool class in the old place, and same for HttpToolResponse. I think these can just extend the newly created classes, so that any methods and creation still work. And add the usual @Deprecation markers to these classes.

@ahgittin
Copy link
Contributor

ahgittin commented Nov 2, 2015

very minor, good to go once those two last items are addressed

/**
* A utility class containing tests on Entities.
*
* @deprecated Prefer core assertions class org.apache.brooklyn.core.entity.EntityAsserts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include a "since 0.9.0" in the deprecated javadoc line. Same for anywhere else you've added @deprecated.

Added TrustingSslSocketFactory to deserializingClassRenames.properties (apache#994 (comment))

Added back an HttpTool and HttpToolResponse in the old location, with @deprecated markers, for backward compatibility (apache#994 (comment))

Added "since 0.9.0" to classes I have deprecated (apache#994 (comment))
@geomacy
Copy link
Contributor Author

geomacy commented Nov 4, 2015

Thanks @ahgittin and @aledsage for the comments. I have made some further updates which I think address them all, but let me know if I've missed anything.

@ahgittin
Copy link
Contributor

ahgittin commented Nov 4, 2015

looks great, merging

ahgittin added a commit to ahgittin/incubator-brooklyn that referenced this pull request Nov 4, 2015
@asfgit asfgit merged commit c466240 into apache:master Nov 4, 2015
final String simple = testUri("/simple");
HttpAsserts.assertUrlUnreachable(simple);
startAfter(2);
HttpAsserts.assertContentEventuallyMatches(ImmutableMap.of("timeout", "3s"), testUri("/simple"), "[Oo][Kk]");
Copy link
Member

Choose a reason for hiding this comment

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

Causes test failures on the apache jenkins CI. The servers there are quite overloaded so delays tend not to be exact, usually much longer.
Also tests which have explicit delays are usually marked as integration as those seconds easily add up. Is it possible to restructure the tests so that they don't need fixed sleeps?

Copy link
Member

Choose a reason for hiding this comment

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

@geomacy
Copy link
Contributor Author

geomacy commented Nov 5, 2015

The sleeps are there to allow the test HTTP server time to shut down. That's not required in all tests, so I could speed things up a bit by changing the test condition, but it is needed in some cases (for the 'eventually becomes unavailable' type tests). I could add a timeout to the shutdown, but it occurs to me that it might be better to mark these as integration tests, because

  • (a) they are not going to run any faster (they already take several minutes) , and
  • (b) the code under test is fairly 'low level' and not likely to break because of other code within Brooklyn changing

so it may not add a lot of value to run these tests on every build, and it will slow things down a bit.

What do you think?

@neykov
Copy link
Member

neykov commented Nov 5, 2015

Moving them to integration will address the immediate problem so +1.
At some point we will start running the integration tests on apache infrastructure (read - busy, we already do, but they are failing for a number of other reasons), so the same issue will crop up - but can deal with it then.


The code could be restructured such that it doesn't use waits at all:

  • tests which need non-running server be put in a separate test, which doesn't start the server by default
  • no sleep on server start, if the server doesn't come up immediately, then always use eventuallySucceeds
  • for the cases where there's xxxxAfter(5); succeedsEventually, could be changed to failsNow; task = succeedsEventuallyInAnotherTask; startNow(); task.get(). What could be a problem here is that connections to closed ports take a long time to timeout?
  • The only place where a fixed wait is really needed is tests which expect to fail and have a timeout, those go in integration.

All of the above said, I am perfectly fine with moving all tests to integration as is.

@geomacy
Copy link
Contributor Author

geomacy commented Nov 5, 2015

I will move them to integration now and add a note to restructure in future, but I will try to make that the near future while it's fresh in my head. Thanks.

geomacy added a commit to geomacy/incubator-brooklyn that referenced this pull request Nov 5, 2015
Later task will be to restructure to avoid sleeps where possible, see conversation at
apache#994 (comment).
* @deprecated since 0.9.0. Prefer org.apache.brooklyn.util.http.HttpTool
*/
@Deprecated
public class HttpTool extends org.apache.brooklyn.util.http.HttpTool {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't make the class backwards compatible because return types will be coming from the new package, while users of this will be expecting the old classes.
HttpTool is used frequently so better handle this gracefully (had a downstream project build failure). @geomacy Can you get the old implementation of HttpTool back here while keeping it marked as @Deprecated. Same for HttpToolResponse.

@geomacy
Copy link
Contributor Author

geomacy commented Nov 13, 2015

hi @neykov, sorry I had indeed missed this comment. Will make changes as you say.

@geomacy
Copy link
Contributor Author

geomacy commented Nov 13, 2015

Have added the changes in #1032

geomacy added a commit to geomacy/incubator-brooklyn that referenced this pull request Nov 16, 2015
johnmccabe pushed a commit to johnmccabe/TEMP-brooklyn-library that referenced this pull request Dec 10, 2015
Renamed assertAttributeNever to assertAttributeContinuallyNotEqualTo (apache/incubator-brooklyn#994 (comment)).

Updates as noted to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (diff))

Fix package name in comment in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Removed a TODO in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Renamed HttpUtils to HttpAsserts; moved methods that weren't assertions to HttpTool, which involved bringing it out of core and into the utils module (apache/incubator-brooklyn#994 (comment))
johnmccabe pushed a commit to johnmccabe/TEMP-brooklyn-server that referenced this pull request Dec 10, 2015
Renamed assertAttributeNever to assertAttributeContinuallyNotEqualTo (apache/incubator-brooklyn#994 (comment)).

Updates as noted to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (diff))

Fix package name in comment in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Removed a TODO in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Renamed HttpUtils to HttpAsserts; moved methods that weren't assertions to HttpTool, which involved bringing it out of core and into the utils module (apache/incubator-brooklyn#994 (comment))
johnmccabe pushed a commit to johnmccabe/TEMP-brooklyn-server that referenced this pull request Dec 10, 2015
Added TrustingSslSocketFactory to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (comment))

Added back an HttpTool and HttpToolResponse in the old location, with @deprecated markers, for backward compatibility (apache/incubator-brooklyn#994 (comment))

Added "since 0.9.0" to classes I have deprecated (apache/incubator-brooklyn#994 (comment))
johnmccabe pushed a commit to johnmccabe/TEMP-brooklyn-server that referenced this pull request Dec 10, 2015
Later task will be to restructure to avoid sleeps where possible, see conversation at
apache/incubator-brooklyn#994 (comment).
asfgit pushed a commit to apache/brooklyn-library that referenced this pull request Feb 1, 2016
Renamed assertAttributeNever to assertAttributeContinuallyNotEqualTo (apache/incubator-brooklyn#994 (comment)).

Updates as noted to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (diff))

Fix package name in comment in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Removed a TODO in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Renamed HttpUtils to HttpAsserts; moved methods that weren't assertions to HttpTool, which involved bringing it out of core and into the utils module (apache/incubator-brooklyn#994 (comment))
asfgit pushed a commit to apache/brooklyn-server that referenced this pull request Feb 1, 2016
Renamed assertAttributeNever to assertAttributeContinuallyNotEqualTo (apache/incubator-brooklyn#994 (comment)).

Updates as noted to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (diff))

Fix package name in comment in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Removed a TODO in EntityTestUtils (apache/incubator-brooklyn#994 (diff))

Renamed HttpUtils to HttpAsserts; moved methods that weren't assertions to HttpTool, which involved bringing it out of core and into the utils module (apache/incubator-brooklyn#994 (comment))
asfgit pushed a commit to apache/brooklyn-server that referenced this pull request Feb 1, 2016
Added TrustingSslSocketFactory to deserializingClassRenames.properties (apache/incubator-brooklyn#994 (comment))

Added back an HttpTool and HttpToolResponse in the old location, with @deprecated markers, for backward compatibility (apache/incubator-brooklyn#994 (comment))

Added "since 0.9.0" to classes I have deprecated (apache/incubator-brooklyn#994 (comment))
asfgit pushed a commit to apache/brooklyn-server that referenced this pull request Feb 1, 2016
Later task will be to restructure to avoid sleeps where possible, see conversation at
apache/incubator-brooklyn#994 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants