-
Notifications
You must be signed in to change notification settings - Fork 798
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
Make calls to endpoint discovery non-blocking for asynchornous clients #5205
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e6099b8
Make calls to endpoint discovery non-blocking for asynchornous clients
anirudh9391 e7174a1
Remove code style changed
anirudh9391 53cd917
Added more tests and improved code style
anirudh9391 60d7eb2
Removed changes to existing method code style
anirudh9391 9139dc4
Remove unnecessary code
anirudh9391 9953d42
modify get method to use getKey
anirudh9391 2d93924
Add Unit Tests
anirudh9391 d6c2f58
Remove pom changes
anirudh9391 0b9e9b7
Added more tests
anirudh9391 eb594d7
Added Functional Test
anirudh9391 61c7756
Added service dependencies
anirudh9391 47382e4
Merge branch 'master' into anirudkr/remove-blocking-calls-ep
anirudh9391 77fc52e
Removed hacky test. Specified one time runnable integration test in p…
anirudh9391 195e6f3
Merge branch 'master' into anirudkr/remove-blocking-calls-ep
anirudh9391 34ec1ba
Added Functional tests
anirudh9391 9411986
Added timeout to test
anirudh9391 dd817b6
Remove Functional tests
anirudh9391 64fb889
Rebased changes
anirudh9391 dea8e9d
Modified test method to use assertThrownBy
anirudh9391 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
anirudh9391 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...java/software/amazon/awssdk/core/endpointdiscovery/EndpointDiscoveryRefreshCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.core.endpointdiscovery; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class EndpointDiscoveryRefreshCacheTest { | ||
|
||
private EndpointDiscoveryRefreshCache endpointDiscoveryRefreshCache; | ||
private EndpointDiscoveryCacheLoader mockClient; | ||
private static final URI testURI = URI.create("test_endpoint"); | ||
private static final String requestCacheKey = "request_cache_key"; | ||
private static final String accessKey = "access_cache_key"; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
this.mockClient= mock(EndpointDiscoveryCacheLoader.class); | ||
this.endpointDiscoveryRefreshCache = EndpointDiscoveryRefreshCache.create(mockClient); | ||
} | ||
|
||
@Test | ||
public void getAsync_notRequired_returns_CompletedFuture() throws ExecutionException, InterruptedException { | ||
when(mockClient.discoverEndpoint(any())).thenReturn(new CompletableFuture<>()); | ||
EndpointDiscoveryRequest request = EndpointDiscoveryRequest.builder() | ||
.required(false) | ||
.defaultEndpoint(testURI) | ||
.build(); | ||
assertThat(endpointDiscoveryRefreshCache.getAsync("key", request).isDone()).isEqualTo(true); | ||
assertThat(endpointDiscoveryRefreshCache.getAsync("key", request).get()).isEqualTo(testURI); | ||
|
||
} | ||
|
||
@Test | ||
public void getAsync_returns_CompletedFuture() throws ExecutionException, InterruptedException { | ||
|
||
when(mockClient.discoverEndpoint(any())).thenReturn(new CompletableFuture<>()); | ||
EndpointDiscoveryRequest request = EndpointDiscoveryRequest.builder() | ||
.required(true) | ||
.defaultEndpoint(testURI) | ||
.build(); | ||
CompletableFuture<URI> future = endpointDiscoveryRefreshCache.getAsync("key", request); | ||
assertThat(future.isDone()).isEqualTo(false); | ||
|
||
future.complete(testURI); | ||
|
||
assertThat(future.isDone()).isEqualTo(true); | ||
assertThat(future.get()).isEqualTo(testURI); | ||
} | ||
|
||
@Test | ||
public void getAsync_future_cancelled() { | ||
|
||
when(mockClient.discoverEndpoint(any())).thenReturn(new CompletableFuture<>()); | ||
EndpointDiscoveryRequest request = EndpointDiscoveryRequest.builder() | ||
.required(true) | ||
.defaultEndpoint(testURI) | ||
.build(); | ||
CompletableFuture<URI> future = endpointDiscoveryRefreshCache.getAsync("key", request); | ||
assertThat(future.isDone()).isEqualTo(false); | ||
|
||
future.cancel(true); | ||
assertThat(future.isCancelled()).isEqualTo(true); | ||
assertThrows(CancellationException.class, () -> future.get()); | ||
anirudh9391 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we propagate exception cancellation? What happens if endpoint discovery takes longer than the configured client execution timeout? Would the request fail properly?
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.
hmm.. So the cancellation Exception is going to be thrown here
This will be propogated upwards, unless you mean something else
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.
I am wrapping it around an EndpointDiscoveryFailedException
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.
I meant if users have client execution timeout enabled and if endpoint discovery takes longer than the configured timeout, the returned future will be cancelled, but will endpoint discovery future also be cancelled?
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.
I think we just need
CompletableFutureUtils.forwardExceptionTo(executeFuture, endpointFuture );
on line 277.Can we write a test to verify that?
Example: https://github.com/aws/aws-sdk-java-v2/blob/master/services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/CopyObjectHelperTest.java#L314
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.
Discussed offline. Doing this as a follow up item