diff --git a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java index 8773715828b..5fa79bde72d 100644 --- a/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java +++ b/src/main/java/com/microsoft/graph/http/CoreHttpProvider.java @@ -31,6 +31,7 @@ import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,6 +59,7 @@ import okhttp3.Headers; import okhttp3.MediaType; import okhttp3.OkHttpClient; +import okhttp3.Protocol; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; @@ -356,21 +358,24 @@ private Result sendRequestInternal(final IHttpRe throws ClientException { try { + if(this.connectionConfig == null) { + this.connectionConfig = new DefaultConnectionConfig(); + } if(this.corehttpClient == null) { - OkHttpClient.Builder okBuilder = HttpClients.createDefault(new ICoreAuthenticationProvider() { + final ICoreAuthenticationProvider authProvider = new ICoreAuthenticationProvider() { @Override public Request authenticateRequest(Request request) { return request; } - }).newBuilder(); - if(this.connectionConfig == null) { - this.connectionConfig = new DefaultConnectionConfig(); - } - okBuilder.connectTimeout(connectionConfig.getConnectTimeout(), TimeUnit.MILLISECONDS); - okBuilder.readTimeout(connectionConfig.getReadTimeout(), TimeUnit.MILLISECONDS); - okBuilder.followRedirects(false); - okBuilder.retryOnConnectionFailure(false); - this.corehttpClient = okBuilder.build(); + }; + this.corehttpClient = HttpClients + .createDefault(authProvider) + .newBuilder() + .connectTimeout(connectionConfig.getConnectTimeout(), TimeUnit.MILLISECONDS) + .readTimeout(connectionConfig.getReadTimeout(), TimeUnit.MILLISECONDS) + .followRedirects(false) + .protocols(Arrays.asList(Protocol.HTTP_1_1)) //https://stackoverflow.com/questions/62031298/sockettimeout-on-java-11-but-not-on-java-8 + .build(); } if (authenticationProvider != null) { authenticationProvider.authenticateRequest(request); diff --git a/src/test/java/com/microsoft/graph/functional/BatchTests.java b/src/test/java/com/microsoft/graph/functional/BatchTests.java index 0af1d1b6c32..a0f1b7deb62 100644 --- a/src/test/java/com/microsoft/graph/functional/BatchTests.java +++ b/src/test/java/com/microsoft/graph/functional/BatchTests.java @@ -68,6 +68,7 @@ public void GetsABatchFromRequests() throws IOException{ assertEquals(200, batchResponse.code()); final MSBatchResponseContent responseContent = new MSBatchResponseContent(batchResponse); + batchResponse.close(); assertEquals(400, responseContent.getResponseById(userPostId).code()); //400:we're not providing enough properties for the call to go through assertEquals(200, responseContent.getResponseById(meGetId).code()); diff --git a/src/test/java/com/microsoft/graph/functional/UserTests.java b/src/test/java/com/microsoft/graph/functional/UserTests.java index 583450dc638..009c0b587c5 100644 --- a/src/test/java/com/microsoft/graph/functional/UserTests.java +++ b/src/test/java/com/microsoft/graph/functional/UserTests.java @@ -1,5 +1,6 @@ package com.microsoft.graph.functional; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -8,6 +9,9 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Ignore; @@ -31,7 +35,6 @@ import com.microsoft.graph.requests.extensions.IOrganizationCollectionPage; import com.microsoft.graph.requests.extensions.IUsedInsightCollectionPage; import com.microsoft.graph.requests.extensions.IUserCollectionPage; - @Ignore public class UserTests { IGraphServiceClient graphServiceClient = null; @@ -170,6 +173,27 @@ public void meMemberof() { IDirectoryObjectCollectionWithReferencesPage page = graphServiceClient.me().memberOf().buildRequest().get(); assertNotNull(page); } + @Test + public void getMeAndRetryOnThrottling() throws Exception { + ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); + try { + for(Integer i = 0; i < 2000; i++) { + exec.submit(new Runnable() { + @Override + public void run() { + final IUserCollectionPage users = graphServiceClient.users().buildRequest().get(); + assertNotNull(users); + final List currentPage = users.getCurrentPage(); + assertNotNull(currentPage); + assertNotEquals(0, currentPage.size()); + } + }); + } + exec.awaitTermination(5L, TimeUnit.MINUTES); + } finally { + exec.shutdown(); + } + } @Test public void emptyPostContentType() {