-
Notifications
You must be signed in to change notification settings - Fork 93
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
Conversation
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) { |
There was a problem hiding this comment.
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]), ...))
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))
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). |
For backwards compatibility we need to leave an |
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. |
There was a problem hiding this comment.
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))
looks great, merging |
final String simple = testUri("/simple"); | ||
HttpAsserts.assertUrlUnreachable(simple); | ||
startAfter(2); | ||
HttpAsserts.assertContentEventuallyMatches(ImmutableMap.of("timeout", "3s"), testUri("/simple"), "[Oo][Kk]"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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? |
Moving them to integration will address the immediate problem so +1. The code could be restructured such that it doesn't use waits at all:
All of the above said, I am perfectly fine with moving all tests to integration as is. |
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. |
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 { |
There was a problem hiding this comment.
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
.
hi @neykov, sorry I had indeed missed this comment. Will make changes as you say. |
Have added the changes in #1032 |
…ibility. This is in relation to the issue noted at apache#994 (comment) and apache#1032 (comment)
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))
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))
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))
Later task will be to restructure to avoid sleeps where possible, see conversation at apache/incubator-brooklyn#994 (comment).
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))
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))
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))
Later task will be to restructure to avoid sleeps where possible, see conversation at apache/incubator-brooklyn#994 (comment).
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.