Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
  • Loading branch information
sarthakaggarwal97 committed Jan 25, 2024
1 parent ee427f3 commit 513c893
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/actions/run-bwc-suite/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ runs:
-Dtests.opensearch.username=${{ inputs.username }}
-Dtests.opensearch.password=${{ inputs.password }}
-Dbwc.version.previous=${{ steps.build-previous.outputs.built-version }}
-Dbwc.version.next=${{ steps.build-next.outputs.built-version }} -i --info --stacktrace
-Dbwc.version.next=${{ steps.build-next.outputs.built-version }} --debug
- uses: alehechka/upload-tartifact@v2
if: always()
Expand Down
4 changes: 2 additions & 2 deletions bwc-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ tasks.register("${baseName}#fullRestartClusterTask", StandaloneRestIntegTestTask
// A bwc test suite which runs all the bwc tasks combined.
task bwcTestSuite(type: StandaloneRestIntegTestTask) {
exclude '**/**' // Do not run any tests as part of this aggregate task
dependsOn tasks.named("${baseName}#mixedClusterTask")
// dependsOn tasks.named("${baseName}#mixedClusterTask")
// dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask")
// dependsOn tasks.named("${baseName}#fullRestartClusterTask")
dependsOn tasks.named("${baseName}#fullRestartClusterTask")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import javax.net.ssl.SSLEngine;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
Expand All @@ -31,12 +31,10 @@
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.reactor.ssl.TlsDetails;
import org.apache.hc.core5.ssl.SSLContextBuilder;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.Before;

import org.opensearch.client.Response;
import org.opensearch.client.ResponseException;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.cluster.metadata.IndexMetadata;
Expand All @@ -47,49 +45,27 @@
import org.opensearch.customcodecs.bwc.helper.RestHelper;
import org.opensearch.test.rest.OpenSearchRestTestCase;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_PER_ROUTE;
import static org.opensearch.client.RestClientBuilder.DEFAULT_MAX_CONN_TOTAL;

@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
public class CustomCodecsCompatibilityIT extends OpenSearchRestTestCase {

private ClusterType CLUSTER_TYPE;
private String CLUSTER_NAME;

private static RestClient testUserRestClient = null;

public void testCreateIndexWithZstdCodec() throws IOException {
System.out.println("RUNNING TEST");
// final String index = "custom-codecs-test-index" + UUID.randomUUID();
//
// // creating index
// createIndex(
// index,
// Settings.builder()
// .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
// .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
// .put("index.codec", randomFrom("zstd", "zstd_no_dict"))
// .put("index.codec.compression_level", randomIntBetween(1, 6))
// .build()
// );
//
// try {
// ensureGreen(index);
// } finally {
// deleteIndex(index);
// }
@Before
public void testSetup() throws IOException {
testUserRestClient = buildClient(super.restClientSettings(), super.getClusterHosts().toArray(new HttpHost[0]));
}

// @Override
// protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
// RestClientBuilder builder = RestClient.builder(hosts);
// configureHttpOrHttpsClient(builder, settings);
// builder.setStrictDeprecationMode(true);
// return builder.build();
// }

@Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureHttpOrHttpsClient(builder, settings);
builder.setStrictDeprecationMode(true);
return builder.build();
}

protected void configureHttpOrHttpsClient(RestClientBuilder builder, Settings settings) throws IOException {
configureClient(builder, settings);
Expand Down Expand Up @@ -166,35 +142,33 @@ protected final boolean preserveReposUponCompletion() {
@Override
protected final Settings restClientSettings() {
return Settings.builder()
.put(super.restClientSettings())
// increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to
// account for delayed shards
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
.build();
.put(super.restClientSettings())
// increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to
// account for delayed shards
.put(OpenSearchRestTestCase.CLIENT_SOCKET_TIMEOUT, "90s")
.build();
}



/**
* Tests backward compatibility by created a test user and role with DLS, FLS and masked field settings. Ingests
* data into a test index and runs a matchAll query against the same.
*/
// public void testDataIngestionAndSearchBackwardsCompatibility() throws Exception {
// String round = System.getProperty("tests.rest.bwcsuite_round");
// String index = "test_index";
// if (round.equals("old")) {
//// createTestRoleIfNotExists(TEST_ROLE);
//// createUserIfNotExists(TEST_USER, TEST_PASSWORD, TEST_ROLE);
// createIndexIfNotExists(index);
// }
// ingestData(index);
// searchMatchAll(index);
// }
public void testDataIngestionAndSearchBackwardsCompatibility() throws Exception {
String round = System.getProperty("tests.rest.bwcsuite_round");
String index = "test-custom-codec-index";
if (round.equals("old")) {
createIndexIfNotExists(index);
}
ingestData(index);
searchMatchAll(index);
}


/**
* Ingests data into the test index
*
* @param index index to ingest data into
*/

Expand All @@ -214,75 +188,63 @@ private void ingestData(String index) throws IOException {
bulkRequestBody.append(objectMapper.writeValueAsString(Song.randomSong().asJson()) + "\n");
}
List<Response> responses = RestHelper.requestAgainstAllNodes(
testUserRestClient,
"POST",
"_bulk?refresh=wait_for",
RestHelper.toHttpEntity(bulkRequestBody.toString())
testUserRestClient,
"POST",
"_bulk?refresh=wait_for",
RestHelper.toHttpEntity(bulkRequestBody.toString())
);
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
}
}

/**
* Runs a matchAll query against the test index
*
* @param index index to search
*/
private void searchMatchAll(String index) throws IOException {
String matchAllQuery = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " }\n" + "}";
int numberOfRequests = Randomness.get().nextInt(10);
while (numberOfRequests-- > 0) {
List<Response> responses = RestHelper.requestAgainstAllNodes(
testUserRestClient,
"POST",
index + "/_search",
RestHelper.toHttpEntity(matchAllQuery)
testUserRestClient ,
"POST",
index + "/_search",
RestHelper.toHttpEntity(matchAllQuery)
);
responses.forEach(r -> assertEquals(200, r.getStatusLine().getStatusCode()));
}
}

/**
* Checks if a resource at the specified URL exists
* @param url of the resource to be checked for existence
* @return true if the resource exists, false otherwise
*/

private boolean resourceExists(String url) throws IOException {
try {
RestHelper.get(adminClient(), url);
return true;
} catch (ResponseException e) {
if (e.getResponse().getStatusLine().getStatusCode() == 404) {
return false;
} else {
throw e;
}
}
}

/**
* Creates a test index if it does not exist already
*
* @param index index to create
*/

private void createIndexIfNotExists(String index) throws IOException {
String settings = "{\n"
+ " \"settings\": {\n"
+ " \"index\": {\n"
+ " \"number_of_shards\": 3,\n"
+ " \"number_of_replicas\": 1\n"
+ " }\n"
+ " }\n"
+ "}";
if (!resourceExists(index)) {
Response response = RestHelper.makeRequest(client(), "PUT", index, RestHelper.toHttpEntity(settings));
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));

if (indexExists(index)) {
return;
}

// creating index
createIndex(
index,
Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.codec", randomFrom("zstd", "zstd_no_dict"))
.put("index.codec.compression_level", randomIntBetween(1, 6))
.build()
);
ensureGreen(index);
}

@AfterClass
public static void cleanUp() throws IOException {
OpenSearchRestTestCase.closeClients();
IOUtils.close(testUserRestClient);
IOUtils.close();
}

}

0 comments on commit 513c893

Please sign in to comment.