Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
use @mock annotation for codebase consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-sun-77 committed Dec 3, 2020
1 parent f2ee351 commit 7eea5eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors;

import static org.mockito.MockitoAnnotations.initMocks;

import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.NodeDetailsCollector.NodeDetailsStatus;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.overrides.ConfigOverridesWrapper;
Expand All @@ -23,16 +25,20 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.Mock;

public class NodeDetailsCollectorTests extends ESTestCase {
private static final String NODE_ID = "testNode";
private NodeDetailsCollector collector;
private ConfigOverridesWrapper configOverrides;
private ThreadPool threadPool;

@Mock
private ConfigOverridesWrapper configOverrides;

@Before
public void init() {
initMocks(this);

DiscoveryNode testNode = new DiscoveryNode(NODE_ID, ESTestCase.buildNewFakeTransportAddress(), Collections
.emptyMap(),
DiscoveryNodeRole.BUILT_IN_ROLES, Version.CURRENT);
Expand All @@ -42,7 +48,6 @@ public void init() {
ESResources.INSTANCE.setClusterService(clusterService);

MetricsConfiguration.CONFIG_MAP.put(NodeDetailsCollector.class, MetricsConfiguration.cdefault);
configOverrides = Mockito.mock(ConfigOverridesWrapper.class);
collector = new NodeDetailsCollector(configOverrides);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors;

import static org.mockito.MockitoAnnotations.initMocks;

import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PerformanceAnalyzerController;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.ShardStatsValue;
Expand All @@ -27,21 +29,25 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

public class NodeStatsFixedShardsMetricsCollectorTests extends ESSingleNodeTestCase {
private static final String TEST_INDEX = "test";
private static long startTimeInMills = 1153721339;
private NodeStatsFixedShardsMetricsCollector collector;

@Mock
private PerformanceAnalyzerController controller;
private long startTimeInMills = 1153721339;

@Before
public void init() {
initMocks(this);

IndicesService indicesService = getInstanceFromNode(IndicesService.class);
ESResources.INSTANCE.setIndicesService(indicesService);

MetricsConfiguration.CONFIG_MAP.put(NodeStatsAllShardsMetricsCollector.class, MetricsConfiguration.cdefault);
controller = Mockito.mock(PerformanceAnalyzerController.class);
collector = new NodeStatsFixedShardsMetricsCollector(controller);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors;

import static org.junit.Assert.assertEquals;
import static org.mockito.MockitoAnnotations.initMocks;

import com.amazon.opendistro.elasticsearch.performanceanalyzer.CustomMetricsLocationTestBase;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources;
Expand Down Expand Up @@ -44,7 +45,8 @@ public class ThreadPoolMetricsCollectorTests extends CustomMetricsLocationTestBa

@Before
public void init() {
mockThreadPool = Mockito.mock(ThreadPool.class);
initMocks(this);

ESResources.INSTANCE.setThreadPool(mockThreadPool);
System.setProperty("performanceanalyzer.metrics.log.enabled", "False");
MetricsConfiguration.CONFIG_MAP.put(ThreadPoolMetricsCollector.class, MetricsConfiguration.cdefault);
Expand Down

0 comments on commit 7eea5eb

Please sign in to comment.