Skip to content

Commit

Permalink
Fixing default semantic use case integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <[email protected]>
  • Loading branch information
joshpalis committed Mar 22, 2024
1 parent fc96ebf commit 0c57add
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.commons.rest.SecureRestClientBuilder;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.DeprecationHandler;
Expand Down Expand Up @@ -706,4 +708,22 @@ protected GetPipelineResponse getPipelines() throws IOException {
return GetPipelineResponse.fromXContent(parser);
}
}

@SuppressWarnings("unchecked")
protected List<String> catPlugins() throws IOException {
Response response = TestHelpers.makeRequest(
client(),
"GET",
"_cat/plugins?s=component&h=name,component,version,description&format=json",
null,
"",
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, ""))
);
List<Object> pluginsList = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE,
response.getEntity().getContent()
).list();
return pluginsList.stream().map(o -> ((Map<String, Object>) o).get("component").toString()).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ public void testDefaultCohereUseCase() throws Exception {
}

public void testDefaultSemanticSearchUseCaseWithFailureExpected() throws Exception {

// Hit Create Workflow API with original template
Response response = createWorkflowWithUseCase(client(), "semantic_search");
assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response));
Expand All @@ -455,17 +454,22 @@ public void testDefaultSemanticSearchUseCaseWithFailureExpected() throws Excepti
response = provisionWorkflow(client(), workflowId);
}

// expecting a failure since there is no neural-search plugin in cluster to provide text-embedding processor
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
getAndAssertWorkflowStatus(client(), workflowId, State.FAILED, ProvisioningProgress.FAILED);

String error = getAndWorkflowStatusError(client(), workflowId);
assertTrue(
error.contains(
"org.opensearch.flowframework.exception.WorkflowStepException during step create_ingest_pipeline, restStatus: BAD_REQUEST"
)
);

// Distribution build contains all plugins, checking if plugins are part of the integration test cluster
List<String> plugins = catPlugins();
if (plugins.contains("opensearch-knn") && plugins.contains("neural-search")) {
getAndAssertWorkflowStatus(client(), workflowId, State.PROVISIONING, ProvisioningProgress.IN_PROGRESS);
} else {
// expecting a failure since there is no neural-search plugin in cluster to provide text-embedding processor
getAndAssertWorkflowStatus(client(), workflowId, State.FAILED, ProvisioningProgress.FAILED);
String error = getAndWorkflowStatusError(client(), workflowId);
assertTrue(
error.contains(
"org.opensearch.flowframework.exception.WorkflowStepException during step create_ingest_pipeline, restStatus: BAD_REQUEST"
)
);
}
}

}

0 comments on commit 0c57add

Please sign in to comment.