Skip to content

Commit

Permalink
adding IT and UT
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed Mar 15, 2024
1 parent 74f58bc commit 9078d04
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public enum DefaultUseCases {
"local_neural_sparse_search",
"defaults/local-sparse-search-defaults.json",
"substitutionTemplates/neural-sparse-local-template.json"
),
/** defaults file and substitution ready template for cohere embedding model */ // TODO: not finalized
COHERE_EMBEDDING_MODEL_DEPLOY_SEMANTIC_SEARCH(
"cohere-embedding_model_deploy_semantic_search",
"defaults/cohere-embedding-defaults.json",
"substitutionTemplates/deploy-remote-model-template-v1.json"
);

private final String useCaseName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ protected Response createWorkflow(RestClient client, Template template) throws E
return TestHelpers.makeRequest(client, "POST", WORKFLOW_URI + "?validation=off", Collections.emptyMap(), template.toJson(), null);
}

/**
* Helper method to invoke the Create Workflow Rest Action without validation
* @param client the rest client
* @param useCase the usecase to create
* @throws Exception if the request fails
* @return a rest response
*/
protected Response createWorkflowWithUseCase(RestClient client, String useCase) throws Exception {
return TestHelpers.makeRequest(
client,
"POST",
WORKFLOW_URI + "?validation=off&use_case=" + useCase,
Collections.emptyMap(),
"{}",
null
);
}

/**
* Helper method to invoke the Create Workflow Rest Action with provision
* @param client the rest client
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.flowframework.common;

import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.test.OpenSearchTestCase;

public class DefaultUseCasesTests extends OpenSearchTestCase {

@Override
public void setUp() throws Exception {
super.setUp();
}

public void testGetDefaultsFileByValidUseCaseName() throws FlowFrameworkException {
String defaultsFile = DefaultUseCases.getDefaultsFileByUseCaseName("open_ai_embedding_model_deploy");
assertEquals("defaults/open-ai-embedding-defaults.json", defaultsFile);
}

public void testGetDefaultsFileByInvalidUseCaseName() throws FlowFrameworkException {
FlowFrameworkException e = assertThrows(
FlowFrameworkException.class,
() -> DefaultUseCases.getDefaultsFileByUseCaseName("invalid_use_case")
);
}

public void testGetSubstitutionTemplateByValidUseCaseName() throws FlowFrameworkException {
String templateFile = DefaultUseCases.getSubstitutionReadyFileByUseCaseName("open_ai_embedding_model_deploy");
assertEquals("substitutionTemplates/deploy-remote-model-template.json", templateFile);
}

public void testGetSubstitutionTemplateByInvalidUseCaseName() throws FlowFrameworkException {
FlowFrameworkException e = assertThrows(
FlowFrameworkException.class,
() -> DefaultUseCases.getSubstitutionReadyFileByUseCaseName("invalid_use_case")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,45 @@ 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));

Map<String, Object> 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);
}

assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
getAndAssertWorkflowStatus(client(), workflowId, State.PROVISIONING, ProvisioningProgress.IN_PROGRESS);

// Wait until provisioning has completed successfully before attempting to retrieve created resources
List<ResourceCreated> resourcesCreated = getResourcesCreated(client(), workflowId, 30);

List<String> expectedStepNames = List.of("create_connector", "register_remote_model", "deploy_model");

List workflowStepNames = resourcesCreated.stream()
.peek(resourceCreated -> assertNotNull(resourceCreated.resourceId()))
.map(ResourceCreated::workflowStepName)
.collect(Collectors.toList());
for (String expectedName : expectedStepNames) {
assertTrue(workflowStepNames.contains(expectedName));
}

// This template should create 5 resources, connector_id, registered model_id, deployed model_id and pipelineId
assertEquals(3, resourcesCreated.size());
}

}

0 comments on commit 9078d04

Please sign in to comment.