-
Notifications
You must be signed in to change notification settings - Fork 466
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
Fix to prevent invalid ShardConsumer state transitions due to rejected executions #560
Fix to prevent invalid ShardConsumer state transitions due to rejected executions #560
Conversation
…task execution is rejected by the executor service.
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.
Few minor comments on the tests.
mockSuccessfulProcessing(null); | ||
|
||
// Failing the initialization task and all other attempts after that. | ||
doCallRealMethod() |
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.
Isn't this test supposed to test the behavior of the ShardConsumer on failures when executorservice is not able to handle the submissions of runnables? Testing multithreaded behavior in unit tests is generally not recommended. Would mocking the executorservice not work in this scenario?
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.
Multithreaded behavior is not tested here. Using directexecutor instead.
do { | ||
try { | ||
consumer.executeLifecycle(); | ||
Thread.sleep(100); |
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.
Avoid thread sleeps in unit tests.
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.
Done
// Suppress any exception like the scheduler. | ||
} | ||
} while (--arbitraryExecutionCount > 0); | ||
assertEquals(ShardConsumerState.INITIALIZING.consumerState().state(), consumer.currentState().state()); |
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.
You may want to validate the number of calls to the executorservice.
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.
Added the expectation on number of calls
mockSuccessfulProcessing(null); | ||
|
||
int arbitraryExecutionCount = 3; | ||
do { |
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.
Consider writing as regular while loop for readability
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.
Mostly looks good. Could you undo the import changes and format using the formatter in the repo.
do { | ||
try { | ||
consumer.executeLifecycle(); | ||
} catch (Exception e) { |
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.
Should the test not fail if an exception is thrown?
.when(failingService).execute(any()); | ||
|
||
int arbitraryExecutionCount = 5; | ||
do { |
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.
No need to change: Out of curiosity, specific reason for do..while instead of for loop?
.doThrow(new RejectedExecutionException()) | ||
.doThrow(new RejectedExecutionException()) | ||
.doThrow(new RejectedExecutionException()) | ||
.doAnswer(invocation -> directlyExecuteRunnable(invocation)) |
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.
Is it not possible to use ArgumentCaptor here?
Issue #, if available:
Description of changes:
The fix is to not propagate the RejectedExecutionException from ShardConsumer to the Scheduler and mark the execution as failure at the ShardConsumer. This will not allow successful state transition to happen.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.