Skip to content

Commit

Permalink
Handle exceptions gracefully when delete non-existent resources durin…
Browse files Browse the repository at this point in the history
…g integ test resource clean up (#1154)

* Handle exceptions gracefully when delete non-existent resources during integ test resource clean up

Signed-off-by: Weijia Zhao <zweijia@amazon.com>

* Clean up test resource dynamically after each test case

Signed-off-by: Weijia Zhao <zweijia@amazon.com>

* Code clean up

Signed-off-by: Weijia Zhao <zweijia@amazon.com>

* Fixing failing bwc tests

Signed-off-by: Weijia Zhao <zweijia@amazon.com>

* Revert bwc test resource cleanup logic

Signed-off-by: Weijia Zhao <zweijia@amazon.com>

---------

Signed-off-by: Weijia Zhao <zweijia@amazon.com>
  • Loading branch information
weijia-aws authored Feb 10, 2025
1 parent e8ed3a4 commit 7dc84b5
Show file tree
Hide file tree
Showing 26 changed files with 3,761 additions and 4,146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ protected final Settings restClientSettings() {
.build();
}

@Override
protected boolean shouldCleanUpResources() {
// All NEW CLUSTER tests depend on resources created in OLD CLUSTER test cases
// Before NEW CLUSTER tests run, all OLD CLUSTER test cases will be run first
// We only want to clean up resources in NEW CLUSTER tests, also we don't want to clean up after each test case finishes
// this is because the cleanup method will pull every resource and delete, which will impact other tests
// Overriding the method in base class so that resources won't be accidentally clean up
return false;
}

protected static final boolean isRunningAgainstOldCluster() {
return Boolean.parseBoolean(System.getProperty(RESTART_UPGRADE_OLD_CLUSTER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ protected final Settings restClientSettings() {
.build();
}

@Override
protected boolean shouldCleanUpResources() {
// All UPGRADE tests depend on resources created in OLD and MIXED test cases
// Before UPGRADE tests run, all OLD and MIXED test cases will be run first
// We only want to clean up resources in upgrade tests, also we don't want to clean up after each test case finishes
// this is because the cleanup method will pull every resource and delete, which will impact other tests
// Overriding the method in base class so that resources won't be accidentally clean up
return false;
}

protected enum ClusterType {
OLD,
MIXED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,84 +48,68 @@ public void setUp() throws Exception {
@SneakyThrows
public void testNeuralQueryEnricherProcessor_whenNoModelIdPassed_thenSuccess() {
String modelId = null;
try {
initializeIndexIfNotExist(index);
modelId = prepareModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralQueryBuilder neuralQueryBuilder = NeuralQueryBuilder.builder()
.fieldName(TEST_KNN_VECTOR_FIELD_NAME_1)
.queryText("Hello World")
.k(1)
.build();
Map<String, Object> response = search(index, neuralQueryBuilder, 2);
assertFalse(response.isEmpty());
} finally {
wipeOfTestResources(index, ingest_pipeline, modelId, search_pipeline);
}
initializeIndexIfNotExist(index);
modelId = prepareModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralQueryBuilder neuralQueryBuilder = NeuralQueryBuilder.builder()
.fieldName(TEST_KNN_VECTOR_FIELD_NAME_1)
.queryText("Hello World")
.k(1)
.build();
Map<String, Object> response = search(index, neuralQueryBuilder, 2);
assertFalse(response.isEmpty());
}

@SneakyThrows
public void testNeuralQueryEnricherProcessor_whenNoModelIdPassedInNeuralSparseQuery_thenSuccess() {
String modelId = null;
try {
initializeIndexIfNotExist(sparseIndex);
modelId = prepareSparseEncodingModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.SPARSE_ENCODING);
updateIndexSettings(sparseIndex, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder();
neuralSparseQueryBuilder.fieldName(TEST_RANK_FEATURES_FIELD_NAME_1);
neuralSparseQueryBuilder.queryText("hello");
Map<String, Object> response = search(sparseIndex, neuralSparseQueryBuilder, 2);
assertFalse(response.isEmpty());
} finally {
wipeOfTestResources(sparseIndex, ingest_pipeline, modelId, search_pipeline);
}
initializeIndexIfNotExist(sparseIndex);
modelId = prepareSparseEncodingModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.SPARSE_ENCODING);
updateIndexSettings(sparseIndex, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder();
neuralSparseQueryBuilder.fieldName(TEST_RANK_FEATURES_FIELD_NAME_1);
neuralSparseQueryBuilder.queryText("hello");
Map<String, Object> response = search(sparseIndex, neuralSparseQueryBuilder, 2);
assertFalse(response.isEmpty());
}

@SneakyThrows
public void testNeuralQueryEnricherProcessor_whenGetEmptyQueryBody_thenSuccess() {
try {
initializeIndexIfNotExist(index);
createSearchRequestProcessor(null, search_pipeline);
createPipelineProcessor(null, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
Request request = new Request("POST", "/" + index + "/_search");
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
String responseBody = EntityUtils.toString(response.getEntity());
Map<String, Object> responseInMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), responseBody, false);
assertFalse(responseInMap.isEmpty());
assertEquals(3, ((Map) responseInMap.get("hits")).size());
} finally {
wipeOfTestResources(index, ingest_pipeline, null, search_pipeline);
}
initializeIndexIfNotExist(index);
createSearchRequestProcessor(null, search_pipeline);
createPipelineProcessor(null, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
Request request = new Request("POST", "/" + index + "/_search");
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
String responseBody = EntityUtils.toString(response.getEntity());
Map<String, Object> responseInMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), responseBody, false);
assertFalse(responseInMap.isEmpty());
assertEquals(3, ((Map) responseInMap.get("hits")).size());
}

@SneakyThrows
public void testNeuralQueryEnricherProcessor_whenHybridQueryBuilderAndNoModelIdPassed_thenSuccess() {
String modelId = null;
try {
initializeIndexIfNotExist(index);
modelId = prepareModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralQueryBuilder neuralQueryBuilder = NeuralQueryBuilder.builder()
.fieldName(TEST_KNN_VECTOR_FIELD_NAME_1)
.queryText("Hello World")
.k(1)
.build();
HybridQueryBuilder hybridQueryBuilder = new HybridQueryBuilder();
hybridQueryBuilder.add(neuralQueryBuilder);
Map<String, Object> response = search(index, hybridQueryBuilder, 2);
initializeIndexIfNotExist(index);
modelId = prepareModel();
createSearchRequestProcessor(modelId, search_pipeline);
createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.TEXT_EMBEDDING);
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline));
NeuralQueryBuilder neuralQueryBuilder = NeuralQueryBuilder.builder()
.fieldName(TEST_KNN_VECTOR_FIELD_NAME_1)
.queryText("Hello World")
.k(1)
.build();
HybridQueryBuilder hybridQueryBuilder = new HybridQueryBuilder();
hybridQueryBuilder.add(neuralQueryBuilder);
Map<String, Object> response = search(index, hybridQueryBuilder, 2);

assertFalse(response.isEmpty());
} finally {
wipeOfTestResources(index, ingest_pipeline, modelId, search_pipeline);
}
assertFalse(response.isEmpty());
}

@SneakyThrows
Expand Down
Loading

0 comments on commit 7dc84b5

Please sign in to comment.