From e5ab7c3deae6bcfcbd9299fa1c5ad8ee05ae5793 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Mon, 18 Mar 2024 16:58:52 -0700 Subject: [PATCH] adding integ tests for new exception written to state index Signed-off-by: Amit Galitzky --- .../FlowFrameworkRestTestCase.java | 14 ++++++++ .../rest/FlowFrameworkRestApiIT.java | 34 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java b/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java index 326d382ee..4acc80a0a 100644 --- a/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java +++ b/src/test/java/org/opensearch/flowframework/FlowFrameworkRestTestCase.java @@ -593,7 +593,21 @@ protected void getAndAssertWorkflowStatus( Map responseMap = entityAsMap(response); assertEquals(stateStatus.name(), (String) responseMap.get(CommonValue.STATE_FIELD)); assertEquals(provisioningStatus.name(), (String) responseMap.get(CommonValue.PROVISIONING_PROGRESS_FIELD)); + } + + /** + * Helper method to invoke the Get Workflow status Rest Action and get the error field + * @param client the rest client + * @param workflowId the workflow ID to get the status + * @return the error string + * @throws Exception if the request fails + */ + protected String getAndWorkflowStatusError(RestClient client, String workflowId) throws Exception { + Response response = getWorkflowStatus(client, workflowId, true); + assertEquals(RestStatus.OK, TestHelpers.restStatus(response)); + Map responseMap = entityAsMap(response); + return (String) responseMap.get(CommonValue.ERROR_FIELD); } /** diff --git a/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java b/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java index 8db37d83d..fb0ee879b 100644 --- a/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java +++ b/src/test/java/org/opensearch/flowframework/rest/FlowFrameworkRestApiIT.java @@ -401,9 +401,6 @@ public void testCreateAndProvisionIngestAndSearchPipeline() throws Exception { public void testDefaultCohereUseCase() throws Exception { - // Using a 3 step template to create a connector, register remote model and deploy model - Template template = TestHelpers.createTemplateFromFile("ingest-search-pipeline-template.json"); - // Hit Create Workflow API with original template Response response = createWorkflowWithUseCase(client(), "cohere-embedding_model_deploy"); assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response)); @@ -440,4 +437,35 @@ public void testDefaultCohereUseCase() throws Exception { assertEquals(3, resourcesCreated.size()); } + public void testDefaultSemanticSearchUseCaseWithFailureExpected() throws Exception { + + // Hit Create Workflow API with original template + Response response = createWorkflowWithUseCase(client(), "semantic_search"); + assertEquals(RestStatus.CREATED, TestHelpers.restStatus(response)); + + Map responseMap = entityAsMap(response); + String workflowId = (String) responseMap.get(WORKFLOW_ID); + getAndAssertWorkflowStatus(client(), workflowId, State.NOT_STARTED, ProvisioningProgress.NOT_STARTED); + + // Ensure Ml config index is initialized as creating a connector requires this, then hit Provision API and assert status + if (!indexExistsWithAdminClient(".plugins-ml-config")) { + assertBusy(() -> assertTrue(indexExistsWithAdminClient(".plugins-ml-config")), 40, TimeUnit.SECONDS); + response = provisionWorkflow(client(), workflowId); + } else { + 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" + ) + ); + + } + }