aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/chef/ChefMock.java28
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java14
2 files changed, 23 insertions, 19 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/chef/ChefMock.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/chef/ChefMock.java
index 1b2dad34b8d..bd19cfe6ce1 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/chef/ChefMock.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/chef/ChefMock.java
@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
/**
* @author mpolden
@@ -24,11 +23,14 @@ import java.util.stream.Collectors;
public class ChefMock implements Chef {
private final NodeResult result;
+ private final PartialNodeResult partialResult;
private final List<String> chefEnvironments;
public ChefMock() {
result = new NodeResult();
result.rows = new ArrayList<>();
+ partialResult = new PartialNodeResult();
+ partialResult.rows = new ArrayList<>();
chefEnvironments = new ArrayList<>();
chefEnvironments.add("hosted-verified-prod");
chefEnvironments.add("hosted-infra-cd");
@@ -59,8 +61,14 @@ public class ChefMock implements Chef {
return null;
}
- public void addSearchResult(ChefNode node) {
+ public ChefMock addSearchResult(ChefNode node) {
result.rows.add(node);
+ return this;
+ }
+
+ public ChefMock addPartialResult(List<PartialNode> partialNodes) {
+ partialResult.rows.addAll(partialNodes);
+ return this;
}
@Override
@@ -76,13 +84,15 @@ public class ChefMock implements Chef {
@Override
public PartialNodeResult partialSearchNodes(String query, List<AttributeMapping> returnAttributes) {
PartialNodeResult partialNodeResult = new PartialNodeResult();
- partialNodeResult.rows = result.rows.stream()
- .map(chefNode -> {
- Map<String, String> data = new HashMap<>();
- data.put("fqdn", chefNode.name);
- return new PartialNode(data);
- })
- .collect(Collectors.toList());
+ partialNodeResult.rows = new ArrayList<>();
+ partialNodeResult.rows.addAll(partialResult.rows);
+ result.rows.stream()
+ .map(chefNode -> {
+ Map<String, String> data = new HashMap<>();
+ data.put("fqdn", chefNode.name);
+ return new PartialNode(data);
+ })
+ .forEach(node -> partialNodeResult.rows.add(node));
return partialNodeResult;
}
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java
index e189a9243db..3364eed3066 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java
@@ -10,8 +10,7 @@ import com.yahoo.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.ControllerTester;
import com.yahoo.vespa.hosted.controller.MetricsMock;
import com.yahoo.vespa.hosted.controller.MetricsMock.MapContext;
-import com.yahoo.vespa.hosted.controller.api.integration.chef.AttributeMapping;
-import com.yahoo.vespa.hosted.controller.api.integration.chef.Chef;
+import com.yahoo.vespa.hosted.controller.api.integration.chef.ChefMock;
import com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder;
@@ -19,7 +18,6 @@ import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester;
import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mockito;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -38,9 +36,6 @@ import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobTy
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.anyListOf;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.when;
/**
* @author mortent
@@ -170,7 +165,7 @@ public class MetricsReporterTest {
private MetricsReporter createReporter(Clock clock, Controller controller, MetricsMock metricsMock,
SystemName system) {
- Chef client = Mockito.mock(Chef.class);
+ ChefMock chef = new ChefMock();
PartialNodeResult result;
try {
result = new ObjectMapper()
@@ -179,9 +174,8 @@ public class MetricsReporterTest {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
- when(client.partialSearchNodes(anyString(), anyListOf(AttributeMapping.class))).thenReturn(result);
-
- return new MetricsReporter(controller, metricsMock, client, clock, new JobControl(new MockCuratorDb()), system);
+ chef.addPartialResult(result.rows);
+ return new MetricsReporter(controller, metricsMock, chef, clock, new JobControl(new MockCuratorDb()), system);
}
private Map<MapContext, Map<String, Number>> getMetricsByHost(String hostname) {