-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(operations): fix get index sizes integer wrap (#9450)
- Loading branch information
1 parent
0ea6145
commit 6a16935
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...rc/test/java/com/linkedin/metadata/timeseries/search/TimeseriesAspectServiceUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.linkedin.metadata.timeseries.search; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.NumericNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.linkedin.metadata.models.registry.EntityRegistry; | ||
import com.linkedin.metadata.search.elasticsearch.update.ESBulkProcessor; | ||
import com.linkedin.metadata.timeseries.TimeseriesAspectService; | ||
import com.linkedin.metadata.timeseries.elastic.ElasticSearchTimeseriesAspectService; | ||
import com.linkedin.metadata.timeseries.elastic.indexbuilder.TimeseriesAspectIndexBuilders; | ||
import com.linkedin.metadata.utils.elasticsearch.IndexConvention; | ||
import com.linkedin.timeseries.TimeseriesIndexSizeResult; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpEntity; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.RestClient; | ||
import org.opensearch.client.RestHighLevelClient; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test using mocks instead of integration for testing functionality not dependent on a real server | ||
* response | ||
*/ | ||
public class TimeseriesAspectServiceUnitTest { | ||
|
||
private final RestHighLevelClient _searchClient = mock(RestHighLevelClient.class); | ||
private final IndexConvention _indexConvention = mock(IndexConvention.class); | ||
private final TimeseriesAspectIndexBuilders _timeseriesAspectIndexBuilders = | ||
mock(TimeseriesAspectIndexBuilders.class); | ||
private final EntityRegistry _entityRegistry = mock(EntityRegistry.class); | ||
private final ESBulkProcessor _bulkProcessor = mock(ESBulkProcessor.class); | ||
private final RestClient _restClient = mock(RestClient.class); | ||
private final TimeseriesAspectService _timeseriesAspectService = | ||
new ElasticSearchTimeseriesAspectService( | ||
_searchClient, | ||
_indexConvention, | ||
_timeseriesAspectIndexBuilders, | ||
_entityRegistry, | ||
_bulkProcessor, | ||
0); | ||
|
||
private static final String INDEX_PATTERN = "indexPattern"; | ||
|
||
@Test | ||
public void testGetIndicesIntegerWrap() throws IOException { | ||
when(_indexConvention.getAllTimeseriesAspectIndicesPattern()).thenReturn(INDEX_PATTERN); | ||
when(_searchClient.getLowLevelClient()).thenReturn(_restClient); | ||
ObjectNode jsonNode = JsonNodeFactory.instance.objectNode(); | ||
ObjectNode indicesNode = JsonNodeFactory.instance.objectNode(); | ||
ObjectNode indexNode = JsonNodeFactory.instance.objectNode(); | ||
ObjectNode primariesNode = JsonNodeFactory.instance.objectNode(); | ||
ObjectNode storeNode = JsonNodeFactory.instance.objectNode(); | ||
NumericNode bytesNode = JsonNodeFactory.instance.numberNode(8078398031L); | ||
storeNode.set("size_in_bytes", bytesNode); | ||
primariesNode.set("store", storeNode); | ||
indexNode.set("primaries", primariesNode); | ||
indicesNode.set("someIndexName", indexNode); | ||
jsonNode.set("indices", indicesNode); | ||
|
||
Response response = mock(Response.class); | ||
HttpEntity responseEntity = mock(HttpEntity.class); | ||
when(response.getEntity()).thenReturn(responseEntity); | ||
when(responseEntity.getContent()) | ||
.thenReturn(IOUtils.toInputStream(jsonNode.toString(), StandardCharsets.UTF_8)); | ||
when(_restClient.performRequest(any(Request.class))).thenReturn(response); | ||
|
||
List<TimeseriesIndexSizeResult> results = _timeseriesAspectService.getIndexSizes(); | ||
|
||
Assert.assertEquals(results.get(0).getSizeInMb(), 8078.398031); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters