Skip to content

Commit

Permalink
Fix IT failures
Browse files Browse the repository at this point in the history
Signed-off-by: zane-neo <[email protected]>
  • Loading branch information
zane-neo committed Jun 12, 2024
1 parent 9a753fd commit 7b0c4b7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 61 deletions.
52 changes: 6 additions & 46 deletions src/test/java/org/opensearch/integTest/BaseAgentToolsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.DeprecationHandler;
import org.opensearch.core.xcontent.MediaType;
Expand Down Expand Up @@ -235,51 +234,11 @@ protected void deleteModel(String modelId) {
makeRequest(client(), "DELETE", "/_plugins/_ml/models/" + modelId, null, (String) null, null);
}

protected void createIndexWithConfiguration(String indexName, String indexConfiguration) {
ResponseListener responseListener = new ResponseListener() {
@Override
public void onSuccess(Response response) {

}

@Override
public void onFailure(Exception exception) {
Response response = makeRequest(client(), "PUT", indexName, null, indexConfiguration, null);
Map<String, Object> responseInMap = parseResponseToMap(response);
assertEquals("true", responseInMap.get("acknowledged").toString());
assertEquals(indexName, responseInMap.get("index").toString());
}
};
adminClient().performRequestAsync(new Request("GET", indexName), responseListener);
}

public void deleteAllDataInIndex(String indexName) {
ResponseListener responseListener = new ResponseListener() {
@Override
public void onSuccess(Response response) {
String matchAllQuery = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " }\n" + "}";
Request request = new Request("POST", indexName + "/_delete_by_query?refresh");
request.setJsonEntity(matchAllQuery);
try {
Response res = adminClient().performRequest(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public void onFailure(Exception exception) {

}
};
adminClient().performRequestAsync(new Request("GET", indexName), responseListener);
}

protected void updateMappings(String indexName, String indexConfiguration) throws IOException {
Request request = new Request("PUT", indexName + "/_mapping");
request.setJsonEntity(indexConfiguration);
Response response = adminClient().performRequest(request);
System.out.println(String.format("update index mapping complete, http response is: %s", response.getStatusLine()));
protected void createIndexWithConfiguration(String indexName, String indexConfiguration) throws Exception {
Response response = makeRequest(client(), "PUT", indexName, null, indexConfiguration, null);
Map<String, Object> responseInMap = parseResponseToMap(response);
assertEquals("true", responseInMap.get("acknowledged").toString());
assertEquals(indexName, responseInMap.get("index").toString());
}

protected void createIngestPipelineWithConfiguration(String pipelineName, String body) throws Exception {
Expand Down Expand Up @@ -340,6 +299,7 @@ protected void addDocToIndex(String indexName, String docId, List<String> fieldN
assertEquals(RestStatus.CREATED, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
}

@SneakyThrows
protected void addDocToIndex(String indexName, String docId, String contents) {
Response response = makeRequest(client(), "POST", "/" + indexName + "/_doc/" + docId + "?refresh=true", null, contents, null);
assertEquals(RestStatus.CREATED, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testNeuralSparseSearchToolInFlowAgent_withIllegalEmbeddingField_then
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/opensearch/integTest/RAGToolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void testRAGToolWithNeuralSparseQuery_withIllegalEmbeddingField_thenThrow
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand All @@ -365,7 +365,7 @@ public void testRAGToolWithNeuralSparseQueryAndLLM_withIllegalEmbeddingField_the
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand All @@ -376,7 +376,7 @@ public void testRAGToolWithNeuralQuery_withIllegalEmbeddingField_thenThrowExcept
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand All @@ -387,7 +387,7 @@ public void testRAGToolWithNeuralQueryAndLLM_withIllegalEmbeddingField_thenThrow
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/opensearch/integTest/SearchAlertsToolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ public void setUp() {
@BeforeEach
@SneakyThrows
public void prepareTest() {
deleteSystemIndices();
}

@After
@SneakyThrows
public void tearDown() {
super.tearDown();
deleteExternalIndices();
deleteAllDataInIndex(ToolConstants.ALERTING_ALERTS_INDEX);
deleteSystemIndices();
}

// @SneakyThrows
// public void testSearchAlertsToolInFlowAgent_withNoSystemIndex() {
// String agentId = createAgent(registerAgentRequestBody);
// String agentInput = "{\"parameters\":{}}";
// String result = executeAgent(agentId, agentInput);
// assertEquals("Alerts=[]TotalAlerts=0", result);
// }
@SneakyThrows
public void testSearchAlertsToolInFlowAgent_withNoSystemIndex() {
String agentId = createAgent(registerAgentRequestBody);
String agentInput = "{\"parameters\":{}}";
String result = executeAgent(agentId, agentInput);
assertEquals("Alerts=[]TotalAlerts=0", result);
}

@SneakyThrows
public void testSearchAlertsToolInFlowAgent_withSystemIndex() {
Expand Down Expand Up @@ -154,7 +155,6 @@ public void testSearchAlertsToolInFlowAgent_multipleAlerts_complexParams() {
private void setupAlertingSystemIndices() {
createIndexWithConfiguration(ToolConstants.ALERTING_ALERTS_INDEX, alertsIndexMappings);
createIndexWithConfiguration(ToolConstants.ALERTING_CONFIG_INDEX, alertingConfigIndexMappings);
deleteAllDataInIndex(ToolConstants.ALERTING_ALERTS_INDEX);
}

private void ingestSampleAlert(String monitorId, String docId) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/opensearch/integTest/VectorDBToolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void testVectorDBToolInFlowAgent_withIllegalEmbeddingField_thenThrowExcep
org.hamcrest.MatcherAssert
.assertThat(
exception.getMessage(),
allOf(containsString("all shards failed"), containsString("SearchPhaseExecutionException"))
allOf(containsString("[neural_sparse] query only works on [rank_features] fields"), containsString("IllegalArgumentException"))
);
}

Expand Down

0 comments on commit 7b0c4b7

Please sign in to comment.