Skip to content

Commit 2011b47

Browse files
committed
fix UT
Signed-off-by: shuangli-z <[email protected]>
1 parent cd00f21 commit 2011b47

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

common/src/test/java/org/opensearch/ml/common/indexInsight/FieldDescriptionTaskTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void testRunTask_MLConfigRetrievalFailure() {
142142
String statisticalContent = "{\"mapping\": {\"field1\": {\"type\": \"text\"}}}";
143143

144144
mockGetSuccess(sdkClient, statisticalContent);
145+
mockUpdateSuccess(sdkClient);
145146
mockMLConfigFailure(client, "Config not found");
146147

147148
task.runTask("tenant-id", listener);

common/src/test/java/org/opensearch/ml/common/indexInsight/LogRelatedIndexCheckTaskTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public void testRunTask_MLConfigRetrievalFailure() {
277277
mockSearchResponse();
278278
// Mock getAgentIdToRun
279279
mockMLConfigFailure(client, "Config not found");
280+
mockUpdateSuccess(sdkClient);
280281

281282
ActionListener<IndexInsight> listener = mock(ActionListener.class);
282283
task.runTask("tenant-id", listener);

common/src/test/java/org/opensearch/ml/common/indexInsight/StatisticalDataTaskTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.opensearch.action.search.SearchRequest;
3939
import org.opensearch.action.search.SearchResponse;
4040
import org.opensearch.cluster.metadata.MappingMetadata;
41+
import org.opensearch.common.settings.Settings;
42+
import org.opensearch.common.util.concurrent.ThreadContext;
4143
import org.opensearch.common.xcontent.XContentType;
4244
import org.opensearch.core.action.ActionListener;
4345
import org.opensearch.core.common.bytes.BytesReference;
@@ -52,6 +54,7 @@
5254
import org.opensearch.search.aggregations.bucket.sampler.InternalSampler;
5355
import org.opensearch.search.aggregations.metrics.InternalTopHits;
5456
import org.opensearch.search.builder.SearchSourceBuilder;
57+
import org.opensearch.threadpool.ThreadPool;
5558
import org.opensearch.transport.client.AdminClient;
5659
import org.opensearch.transport.client.Client;
5760
import org.opensearch.transport.client.IndicesAdminClient;
@@ -68,9 +71,14 @@ private Client setupBasicClientMocks() {
6871
Client client = mock(Client.class);
6972
AdminClient adminClient = mock(AdminClient.class);
7073
IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
74+
ThreadPool threadPool = mock(ThreadPool.class);
75+
Settings settings = Settings.builder().build();
76+
ThreadContext threadContext = new ThreadContext(settings);
7177

7278
when(client.admin()).thenReturn(adminClient);
7379
when(adminClient.indices()).thenReturn(indicesAdminClient);
80+
when(client.threadPool()).thenReturn(threadPool);
81+
when(threadPool.getThreadContext()).thenReturn(threadContext);
7482

7583
return client;
7684
}
@@ -184,6 +192,8 @@ public void testRunTask_WithEmptyMappings() {
184192

185193
when(getMappingsResponse.getMappings()).thenReturn(new HashMap<>());
186194
setupGetMappingsCall(client, getMappingsResponse);
195+
sdkClient = mock(SdkClient.class);
196+
mockUpdateSuccess(sdkClient);
187197

188198
StatisticalDataTask task = new StatisticalDataTask("test-index", client, sdkClient);
189199
task.runTask("tenant-id", listener);

0 commit comments

Comments
 (0)