Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading