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

Added throwable logic and convenience methods. #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Added throwable logic and convenience methods. #69

wants to merge 3 commits into from

Conversation

nwertzberger
Copy link

@nwertzberger nwertzberger commented Jan 12, 2016

This will make sure that waitSafely throws any unchecked exceptions when it is called. This is super important for using testing libaries with this tool.


This change is Reviewable

@nwertzberger
Copy link
Author

I added in some tests to show when this waitSafely exception handling is so important.

I've also added a Promises convenience class, and a collection convenience method.

@nwertzberger nwertzberger changed the title Added throwable logic Added throwable logic and convenience methods. Jan 12, 2016
} else if (callables[i] instanceof DeferredFutureTask) {
promises[i] = when((DeferredFutureTask<?,?>) callables[i]);
} else if (callables[i] instanceof FutureTask) {
promises[i] = when((Runnable) callables[i]);
Copy link
Author

Choose a reason for hiding this comment

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

This cast was giving me trouble. It wouldn't let me do a FutureTask<?>, saying it gets type erased to Runnable.

This did not need to be different.
@nwertzberger
Copy link
Author

Any thoughts?

@saturnism
Copy link
Member

quick question - how will this handle multiple failures?

@nwertzberger
Copy link
Author

Once an exception has occurred, the code will exit from wherever it is and do what it did before. The only difference is that waitSafely will throw either the first or last exception (your choice).

The key here is that failure behaviors will not change. only the response of waitSafely due to failures.

@nwertzberger
Copy link
Author

Is this going to be accepted or not? This change is required to actually use this tool with mockito / most test suites that aren't throwing Error's. Because you eat the exceptions they normally throw.

@saturnism
Copy link
Member

hiya - apologies for the slowness on my side. i feel we can merge this in slowly if it was split into 3 PRs:

  1. Promises convenience methods - this is pretty useful and independent from many other things in the PR. we can merge this quickly if it was separate.
  2. dm.then(Collection<?>...) - would it be useful to strongly type it, then(Collection), and subsequently delegate to then(T ...) ? Having mixed objects in a Collection can be troublesome.
  3. finally, error handling - I'm still having a lot of reservations with saving throwables and throwing only in waitSafely. Due to the concurrent nature, errors should be handled in within thread whenever possible. what do you feel about pushing all the errors into a list, and add a way to retrieve it?

@nwertzberger
Copy link
Author

I'll have to reflect on that. I can definitely break things up. I really love this library, and, i'm using a fork of it (with this and a few other tweaks - i have quite a few convenience methods at this point) in some pretty rad production code.

I'll try to split up these convenience methods from the other one. Regarding the exception throwing, my thoughts are this:

In my production code, I'm not waiting if i'm using promises, so the waitSafely behavior has little concern from that point of view. It's in my tests where i need the percolation of those runtime exceptions in order to run mockito validate calls / all that. Having additional method calls after waitSafely would make a little bit more verbose, and i really need those exceptions to be thrown in order for my test tooling to catch those as failures.

I don't see any value in getting back more than one exception. If i actually wanted these exceptions, I'd have returned a failed promise.

@saturnism
Copy link
Member

Hiya - just got touch base - I'll try to get the Promises util in based on your patch.

In chatting w/ @aalmiray - we may want to explore test utilities that help w/ such cases. In my test cases, I'll catch the exception in the callbacks, and then either re-throw it or check a AtomicBoolean flag.

Finally, based on @aalmiray's suggestion, I'll look into a more generic uncaught error handler so that we can plugin different implementations in case there is an uncaught exception. By default, it'll log it. But when testing, we can potentially fail fast in the handler.

Thanks for your patience on this!

@saturnism saturnism mentioned this pull request Apr 30, 2016
@saturnism
Copy link
Member

@nwertzberger quick ping - will it be possible to send in a PR for just the Promises convenience method?

Thanks!

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

2 participants