Skip to content

Commit e731df3

Browse files
author
Nakul Sabharwal
committed
Reordered should retry parameters
1 parent fbe12a7 commit e731df3

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ public MSBatchRequestStep(String requestId, Request request, List<String> arrayO
1414
throw new IllegalArgumentException("Request Id cannot be null.");
1515
if(request == null)
1616
new IllegalArgumentException("Request cannot be null.");
17-
if(request.url() == null)
18-
throw new IllegalArgumentException("Request url cannot be null.");
19-
if(request.method() == null)
20-
throw new IllegalArgumentException("Request method cannot be null.");
21-
17+
2218
this.requestId = requestId;
2319
this.request = request;
2420
this.arrayOfDependsOnIds = arrayOfDependsOnIds;

src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class RedirectHandler implements Interceptor{
2727
* Initialize using default redirect options, default IShouldRedirect and max redirect value
2828
*/
2929
public RedirectHandler() {
30-
this.mRedirectOptions = new RedirectOptions();
30+
this(null);
3131
}
3232

3333
/*
@@ -109,8 +109,8 @@ public Response intercept(Chain chain) throws IOException {
109109

110110
while(true) {
111111
response = chain.proceed(request);
112-
boolean shouldRedirect = redirectOptions.shouldRedirect().shouldRedirect(response)
113-
&& isRedirected(request, response, requestsCount, redirectOptions);
112+
boolean shouldRedirect = isRedirected(request, response, requestsCount, redirectOptions)
113+
&& redirectOptions.shouldRedirect().shouldRedirect(response);
114114
if(!shouldRedirect) break;
115115

116116
Request followup = getRedirect(request, response);

src/main/java/com/microsoft/graph/httpcore/RetryHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ boolean retryRequest(Response response, int executionCount, Request request, Ret
5656
if(retryOptions != null) {
5757
shouldRetryCallback = retryOptions.shouldRetry();
5858
}
59-
// Call should retry callback
60-
if(shouldRetryCallback != null && !shouldRetryCallback.shouldRetry(response, executionCount, request, retryOptions.delay())) {
61-
return false;
62-
}
6359

6460
boolean shouldRetry = false;
6561
// Status codes 429 503 504
6662
int statusCode = response.code();
6763
// Only requests with payloads that are buffered/rewindable are supported.
6864
// Payloads with forward only streams will be have the responses returned
6965
// without any retry attempt.
70-
shouldRetry = (executionCount <= retryOptions.maxRetries()) && checkStatus(statusCode) && isBuffered(response, request);
66+
shouldRetry =
67+
(executionCount <= retryOptions.maxRetries())
68+
&& checkStatus(statusCode) && isBuffered(response, request)
69+
&& shouldRetryCallback != null
70+
&& shouldRetryCallback.shouldRetry(retryOptions.delay(), executionCount, request, response);
7171

7272
if(shouldRetry) {
7373
long retryInterval = getRetryAfter(response, retryOptions.delay(), executionCount);
@@ -86,8 +86,9 @@ long getRetryAfter(Response response, long delay, int executionCount) {
8686
if(retryAfterHeader != null) {
8787
retryDelay = Long.parseLong(retryAfterHeader);
8888
} else {
89-
retryDelay = (long)Math.pow(2.0, (double)executionCount) * DELAY_MILLISECONDS;
89+
retryDelay = (long)((Math.pow(2.0, (double)executionCount)-1)*0.5);
9090
retryDelay = executionCount < 2 ? retryDelay : retryDelay + delay + (long)Math.random();
91+
retryDelay *= DELAY_MILLISECONDS;
9192
}
9293
return Math.min(retryDelay, RetryOptions.MAX_DELAY);
9394
}
@@ -99,7 +100,7 @@ boolean checkStatus(int statusCode) {
99100

100101
boolean isBuffered(Response response, Request request) {
101102
String methodName = request.method();
102-
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE"))
103+
if(methodName.equalsIgnoreCase("GET") || methodName.equalsIgnoreCase("DELETE") || methodName.equalsIgnoreCase("HEAD") || methodName.equalsIgnoreCase("OPTIONS"))
103104
return true;
104105

105106
boolean isHTTPMethodPutPatchOrPost = methodName.equalsIgnoreCase("POST") ||

src/main/java/com/microsoft/graph/httpcore/middlewareoption/IShouldRetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import okhttp3.Response;
55

66
public interface IShouldRetry {
7-
boolean shouldRetry(Response response, int executionCount, Request request, long delay);
7+
boolean shouldRetry(long delay, int executionCount, Request request,Response response);
88
}

src/main/java/com/microsoft/graph/httpcore/middlewareoption/RetryOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class RetryOptions implements IMiddlewareControl {
77
private IShouldRetry mShouldretry;
88
public static final IShouldRetry DEFAULT_SHOULD_RETRY = new IShouldRetry() {
99
@Override
10-
public boolean shouldRetry(Response response, int executionCount, Request request, long delay) {
10+
public boolean shouldRetry(long delay, int executionCount, Request request, Response response) {
1111
return true;
1212
}
1313
};

src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testRetryHandlerWithRetryOptions() {
4747
@Test
4848
public void testRetryHandlerWithCustomRetryOptions() {
4949
IShouldRetry shouldRetry = new IShouldRetry() {
50-
public boolean shouldRetry(Response response, int executionCount, Request request, long delay){
50+
public boolean shouldRetry(long delay, int executionCount, Request request,Response response){
5151
return false;
5252
}
5353
};

0 commit comments

Comments
 (0)