Skip to content

Commit

Permalink
Added test to cover getNumberOfDocumentsInIndex with 4 arguments
Browse files Browse the repository at this point in the history
Signed-off-by: rithin-pullela-aws <[email protected]>
  • Loading branch information
rithin-pullela-aws authored and peterzhuamazon committed Feb 12, 2025
1 parent e14923c commit e79bd57
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions plugin/src/test/java/org/opensearch/ml/utils/IndexUtilsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

package org.opensearch.ml.utils;

import java.util.List;

import org.junit.Ignore;
import org.opensearch.action.support.clustermanager.AcknowledgedResponse;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.search.SearchModule;
import org.opensearch.test.OpenSearchIntegTestCase;

import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -61,4 +66,32 @@ public void testGetNumberOfDocumentsInIndex_RegularIndex() {
indexUtils
.getNumberOfDocumentsInIndex(indexName, ActionListener.wrap(r -> { assertEquals((Long) count, r); }, e -> { assertNull(e); }));
}

public void testGetNumberOfDocumentsInIndex_SearchQuery() throws Exception {
String indexName = "test-2";
createIndex(indexName);
flush();

long count = 20;
for (int i = 0; i < count; i++) {
index(indexName, "_doc", i + "", ImmutableMap.of(randomAlphaOfLength(5), randomAlphaOfLength(5)));
}
flushAndRefresh(indexName);

NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(new SearchModule(Settings.EMPTY, List.of()).getNamedXContents());

String searchQuery = "{}";
IndexUtils indexUtils = new IndexUtils(client(), clusterService());

indexUtils
.getNumberOfDocumentsInIndex(
indexName,
searchQuery,
xContentRegistry,
ActionListener.wrap(r -> { assertEquals((Long) count, r); }, e -> {
assertNull(e);
})
);
}

}

0 comments on commit e79bd57

Please sign in to comment.