Skip to content

Conversation

@alasdairhodge
Copy link
Contributor

Provides general-purpose blocking wait on any entity predicate. Example:

    Entities.waitFor(
        machineEntity,
        EntityPredicates.attributeEqualTo(MACHINE_STATE, MachineState.REBOOTING),
        Duration.FIVE_SECONDS);

@bostko
Copy link
Contributor

bostko commented Mar 8, 2017

LGTM

Copy link
Contributor

@geomacy geomacy left a comment

Choose a reason for hiding this comment

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

Looks good, have made a couple of suggestions.

Also, for the sake of DRY, if you are introducing this would it not be best to update the implementation of waitForServiceUp to use this new method?

A question - why merge this to 0.9.x? Can/should this not also go into master? In which case maybe merge it there then backport?

.backoffTo(Duration.ONE_SECOND)
.rethrowException();

if (!repeater.run()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about making this capture any exception with runKeepingError so that the throw below could set it as a cause? Also then you can change the message below to refer to whatever the actual error was, rather than assuming it's a timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Timeout is indicated by the run method returning false, rather than via an exception. Since we set rethrowException, anything thrown by the passed Callable will be rethrown on timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the subject of exceptions, I toyed with the idea of throwing TimeoutException instead of IllegalStateException, but am opting for consistency/backwards compatibility with the existing waitForServiceUp methods. (The standard TimeoutException is checked.)


try {
Entities.waitFor(entity, applicationIdEqualTo(app.getApplicationId() + "-wrong"), timeout);
Assert.fail();
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer org.apache.brooklyn.test.Asserts#shouldHaveFailedPreviously()

Assert.fail();

} catch (Exception e) {
// expected timeout
Copy link
Contributor

Choose a reason for hiding this comment

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

Do an assertion on the exception so you're sure it's really what you expected, using one of the Asserts.expectedFailureContains... variants.

Copy link
Contributor Author

@alasdairhodge alasdairhodge left a comment

Choose a reason for hiding this comment

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

Great suggestions, @geomacy; I'll update and push

return predicate.apply(subject);
}
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't really sure where to stick this utility method; there are other Callable related methods here, so it seemed as good a place as any.

@alasdairhodge alasdairhodge force-pushed the generalised-entities-wait-for branch from 61f8fc0 to fc8ec90 Compare March 8, 2017 11:10
@alasdairhodge
Copy link
Contributor Author

@geomacy FYI, I've fixed-up my original commits and force-pushed. I'll should probably close this and issue a fresh PR against master as you suggest.

@alasdairhodge
Copy link
Contributor Author

Closing in favour of #584 against master.

@alasdairhodge alasdairhodge deleted the generalised-entities-wait-for branch March 9, 2017 13:16
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.

3 participants