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

Fix to prevent invalid ShardConsumer state transitions due to rejected executions #560

Conversation

ashwing
Copy link
Contributor

@ashwing ashwing commented Jun 24, 2019

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.

…task execution is rejected by the executor service.
Copy link
Contributor

@sahilpalvia sahilpalvia left a 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()
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

@micah-jaffe micah-jaffe Jun 25, 2019

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

Copy link
Contributor

@sahilpalvia sahilpalvia left a 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) {
Copy link
Contributor

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 {
Copy link
Contributor

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))
Copy link
Contributor

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?

@sahilpalvia sahilpalvia merged commit 9e2d6fa into awslabs:master Jul 8, 2019
@sahilpalvia sahilpalvia added this to the v2.2.2 milestone Aug 16, 2019
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.

4 participants