44import com .microsoft .graph .core .CoreConstants ;
55import com .microsoft .graph .core .content .BatchRequestContent ;
66import com .microsoft .graph .core .models .BatchRequestStep ;
7+ import com .microsoft .kiota .HttpMethod ;
78import com .microsoft .kiota .RequestInformation ;
89import com .microsoft .kiota .authentication .AnonymousAuthenticationProvider ;
910import okhttp3 .MediaType ;
1213import org .junit .jupiter .api .Test ;
1314
1415import java .io .IOException ;
16+ import java .io .InputStream ;
17+ import java .net .URI ;
18+ import java .nio .charset .StandardCharsets ;
19+ import java .util .ArrayList ;
1520import java .util .Arrays ;
21+ import java .util .List ;
22+ import java .io .ByteArrayInputStream ;
1623
1724import static org .junit .jupiter .api .Assertions .assertEquals ;
25+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
1826
1927class BatchRequestBuilderTest {
2028
@@ -36,4 +44,26 @@ void BatchRequestBuilder_DefaultBuilderTest() throws IOException {
3644 assertEquals (client .getRequestAdapter (), batchRequestBuilder .getRequestAdapter ());
3745
3846 }
47+ @ Test
48+ void BatchContentDoesNotDeadlockOnLargeContent () throws IOException {
49+ final BaseClient client = new BaseClient (new AnonymousAuthenticationProvider (), "https://localhost" );
50+ final BatchRequestContent batchRequestContent = new BatchRequestContent (client );
51+ final List <InputStream > streamsToClose = new ArrayList <>();
52+ for (int i = 0 ; i < 20 ; i ++) {
53+ final RequestInformation requestInformation = new RequestInformation ();
54+ requestInformation .httpMethod = HttpMethod .POST ;
55+ requestInformation .setUri (URI .create ("https://graph.microsoft.com/v1.0/me/" ));
56+ final String payload = "{\" displayName\" : \" Test\" , \" lastName\" : \" User\" , \" mailNickname\" : \" testuser\" , \" userPrincipalName\" : \" testUser\" , \" passwordProfile\" : {\" forceChangePasswordNextSignIn\" : true, \" password\" : \" password\" }, \" accountEnabled\" : true}" ;
57+ final InputStream content = new ByteArrayInputStream (payload .getBytes (StandardCharsets .UTF_8 ));
58+ streamsToClose .add (content );
59+ requestInformation .setStreamContent (content , CoreConstants .MimeTypeNames .APPLICATION_JSON );
60+ batchRequestContent .addBatchRequestStep (requestInformation );
61+ }
62+ BatchRequestBuilder batchRequestBuilder = new BatchRequestBuilder (client .getRequestAdapter ());
63+ RequestInformation requestInformation = batchRequestBuilder .toPostRequestInformation (batchRequestContent );
64+ assertNotNull (requestInformation );
65+ for (final InputStream inputStream : streamsToClose ) {
66+ inputStream .close ();
67+ }
68+ }
3969}
0 commit comments