From 3c707280cd331823643c9affa1b58ffbc5fa8a41 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 31 Jul 2024 15:03:05 -0400 Subject: [PATCH] fix: deadlock for batch request content once it passes a certain size Signed-off-by: Vincent Biret --- .../core/content/BatchRequestContent.java | 10 +++---- .../requests/BatchRequestBuilderTest.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/microsoft/graph/core/content/BatchRequestContent.java b/src/main/java/com/microsoft/graph/core/content/BatchRequestContent.java index 2a0f511f..9b1072fb 100644 --- a/src/main/java/com/microsoft/graph/core/content/BatchRequestContent.java +++ b/src/main/java/com/microsoft/graph/core/content/BatchRequestContent.java @@ -161,7 +161,7 @@ public BatchRequestContent createNewBatchFromFailedRequests (@Nonnull Map streamsToClose = new ArrayList<>(); + for (int i = 0; i < 20; i++) { + final RequestInformation requestInformation = new RequestInformation(); + requestInformation.httpMethod = HttpMethod.POST; + requestInformation.setUri(URI.create("https://graph.microsoft.com/v1.0/me/")); + final String payload = "{\"displayName\": \"Test\", \"lastName\": \"User\", \"mailNickname\": \"testuser\", \"userPrincipalName\": \"testUser\", \"passwordProfile\": {\"forceChangePasswordNextSignIn\": true, \"password\": \"password\"}, \"accountEnabled\": true}"; + final InputStream content = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); + streamsToClose.add(content); + requestInformation.setStreamContent(content, CoreConstants.MimeTypeNames.APPLICATION_JSON); + batchRequestContent.addBatchRequestStep(requestInformation); + } + BatchRequestBuilder batchRequestBuilder = new BatchRequestBuilder(client.getRequestAdapter()); + RequestInformation requestInformation = batchRequestBuilder.toPostRequestInformation(batchRequestContent); + assertNotNull(requestInformation); + for (final InputStream inputStream : streamsToClose) { + inputStream.close(); + } + } }