Skip to content

Commit

Permalink
Switch to postJson and remove shuffle
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Nov 3, 2023
1 parent caa026c commit 0ce56e7
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
package org.opensearch.security.http;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.nimbusds.jose.util.StandardCharset;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -29,7 +25,6 @@
import org.opensearch.test.framework.cluster.TestRestClient;
import org.opensearch.test.framework.cluster.TestRestClient.HttpResponse;

import java.util.Collections;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
Expand Down Expand Up @@ -59,7 +54,7 @@ public void testBulkAndCacheInvalidationMixed() throws Exception {
String indexName = "test-index";
final String invalidateCachePath = "_plugins/_security/api/cache";
final String nodesPath = "_nodes";
final String bulkPath = "/_bulk";
final String bulkPath = "_bulk";
final String document = ("{ \"index\": { \"_index\": \"" + indexName + "\" }}\n{ \"foo\": \"bar\" }\n").repeat(5);
final int parallelism = 5;
final int totalNumberOfRequests = 30;
Expand All @@ -78,9 +73,7 @@ public void testBulkAndCacheInvalidationMixed() throws Exception {

allRequests.addAll(AsyncActions.generate(() -> {
countDownLatch.await();
final HttpPost post = new HttpPost(client.getHttpServerUri() + bulkPath);
post.setEntity(new ByteArrayEntity(document.getBytes(StandardCharset.UTF_8), ContentType.APPLICATION_JSON));
return client.executeRequest(post);
return client.postJson(bulkPath, document);
}, parallelism, totalNumberOfRequests));

allRequests.addAll(AsyncActions.generate(() -> {
Expand All @@ -90,7 +83,6 @@ public void testBulkAndCacheInvalidationMixed() throws Exception {

// Make sure all requests start at the same time
countDownLatch.countDown();
Collections.shuffle(allRequests);

AsyncActions.getAll(allRequests, 30, TimeUnit.SECONDS).forEach((response) -> { response.assertStatusCode(HttpStatus.SC_OK); });
}
Expand Down

0 comments on commit 0ce56e7

Please sign in to comment.