Skip to content

Commit

Permalink
fixes the cacheConfigRTFCollector UT (#713)
Browse files Browse the repository at this point in the history
Signed-off-by: Atharva Sharma <[email protected]>
  • Loading branch information
atharvasharma61 committed Sep 4, 2024
1 parent f97ed09 commit 84d7d1f
Showing 1 changed file with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
package org.opensearch.performanceanalyzer.collectors.telemetry;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import org.junit.After;
Expand All @@ -24,26 +22,21 @@
import org.opensearch.performanceanalyzer.commons.config.overrides.ConfigOverridesWrapper;
import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration;
import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController;
import org.opensearch.telemetry.metrics.Histogram;
import org.opensearch.telemetry.metrics.MetricsRegistry;
import org.opensearch.test.OpenSearchSingleNodeTestCase;

public class RTFCacheConfigMetricsCollectorTests extends OpenSearchSingleNodeTestCase {
private static final String TEST_INDEX = "test";
private RTFCacheConfigMetricsCollector rtfCacheConfigMetricsCollector;
private static MetricsRegistry metricsRegistry;
private static Histogram testHistogram;
private long startTimeInMills = 1153721339;

@Before
public void init() {
MetricsConfiguration.CONFIG_MAP.put(
RTFCacheConfigMetricsCollector.class, MetricsConfiguration.cdefault);
metricsRegistry = mock(MetricsRegistry.class);
testHistogram = mock(Histogram.class);
OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry);
when(metricsRegistry.createHistogram(anyString(), anyString(), anyString()))
.thenReturn(testHistogram);
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
OpenSearchResources.INSTANCE.setIndicesService(indicesService);
ConfigOverridesWrapper mockWrapper = mock(ConfigOverridesWrapper.class);
Expand All @@ -62,6 +55,7 @@ public void tearDown() throws Exception {
public void testCollectMetrics() throws IOException {
createIndex(TEST_INDEX);
rtfCacheConfigMetricsCollector.collectMetrics(startTimeInMills);
verify(testHistogram, atLeastOnce()).record(anyDouble(), any());
verify(metricsRegistry, atLeastOnce())
.createGauge(anyString(), anyString(), anyString(), any(), any());
}
}

0 comments on commit 84d7d1f

Please sign in to comment.