-
Notifications
You must be signed in to change notification settings - Fork 29
- fixes retry/redirect options customization #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
118dc26
- fixes retry/redirect options customization
Asky-GH d86d453
- fixes retry/redirect options customization
Asky-GH 804f36b
- adds unit tests for default retry and redirect options values
baywet ba0d5fd
- adds unit test on getHttpReqest method to test for default retry an…
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
src/test/java/com/microsoft/graph/httpcore/middlewareoption/RedirectOptionsTest.java
This file contains hidden or 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,33 @@ | ||
| package com.microsoft.graph.httpcore.middlewareoption; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import okhttp3.Response; | ||
|
|
||
| public class RedirectOptionsTest { | ||
| @Test | ||
| public void constructorDefensiveProgramming() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RedirectOptions(RedirectOptions.MAX_REDIRECTS +1, null); | ||
| }); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RedirectOptions(-1, null); | ||
| }); | ||
| } | ||
| @Test | ||
| public void defaultShouldRedirectValue() { | ||
| RedirectOptions options = new RedirectOptions(); | ||
| assertEquals(options.shouldRedirect(), RedirectOptions.DEFAULT_SHOULD_REDIRECT); | ||
| } | ||
| @Test | ||
| public void defaultShouldRedirectIsTrue() { | ||
| Response response = mock(Response.class); | ||
| assertTrue(RedirectOptions.DEFAULT_SHOULD_REDIRECT.shouldRedirect(response)); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/test/java/com/microsoft/graph/httpcore/middlewareoption/RetryOptionsTest.java
This file contains hidden or 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,32 @@ | ||
| package com.microsoft.graph.httpcore.middlewareoption; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class RetryOptionsTest { | ||
| @Test | ||
| public void constructorDefensiveProgramming() { | ||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RetryOptions(null, RetryOptions.MAX_RETRIES +1, 0); | ||
| }); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RetryOptions(null, RetryOptions.MAX_RETRIES, RetryOptions.MAX_DELAY +1); | ||
| }); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RetryOptions(null, RetryOptions.MAX_RETRIES, -1); | ||
| }); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, () -> { | ||
| new RetryOptions(null, -1, RetryOptions.MAX_DELAY); | ||
| }); | ||
| } | ||
| @Test | ||
| public void defaultShouldRetryValue() { | ||
| RetryOptions options = new RetryOptions(); | ||
| assertEquals(options.shouldRetry(), RetryOptions.DEFAULT_SHOULD_RETRY); | ||
| } | ||
| } |
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.
Is this required for giving the flexibility to custom handler implementations?
In the default implementation of
RetryHandlerandRedirectHandler, the constructors end up calling the default option constructors if they arenull. Default constructors of options are already using these default values. This piece of code seems equivalent to: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.
Hi @zengin
The changes you are suggesting work effectively the same as the current code of the library. If you take a look at CoreHttpProvider's line 245:
RedirectHandler's line 133:
and RetryHandler's line 179:
you can see that mRedirectOptions and mRetryOption will never be used. Thus it is impossible to customize them so to speak globaly.
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.
Thanks for clarifying.