summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2017-12-05 15:04:23 +0100
committerMartin Polden <mpolden@mpolden.no>2017-12-05 18:10:43 +0100
commit62339f63d53c0faad58880642643f6d386e85bc4 (patch)
treedb52f0012635b519d2898d9353aff9fc195fd7bb /controller-server
parentf9bc70f4b93c13cd98c7b4e31ad93252d0104320 (diff)
Clean up test code
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java37
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerProxyMock.java3
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/VersionStatusSerializerTest.java2
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerControllerTester.java12
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerTester.java10
5 files changed, 33 insertions, 31 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java
index 9228e83bbc6..bf7f19a996c 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java
@@ -22,7 +22,6 @@ import com.yahoo.vespa.serviceview.bindings.ApplicationView;
import com.yahoo.vespa.serviceview.bindings.ClusterView;
import com.yahoo.vespa.serviceview.bindings.ServiceView;
-import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
@@ -43,16 +42,14 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
private final Map<ApplicationId, Boolean> applicationActivated = new HashMap<>();
private final Map<String, EndpointStatus> endpoints = new HashMap<>();
private final Map<URI, Version> versions = new HashMap<>();
- private Version defaultVersion = new Version(6, 1, 0);
- /** The exception to throw on the next prepare run, or null to continue normally */
+ private Version defaultVersion = new Version(6, 1, 0);
private RuntimeException prepareException = null;
-
- private Optional<Version> lastPrepareVersion = Optional.empty();
+ private Version lastPrepareVersion = null;
/** The version given in the previous prepare call, or empty if no call has been made */
public Optional<Version> lastPrepareVersion() {
- return lastPrepareVersion;
+ return Optional.ofNullable(lastPrepareVersion);
}
/** Return map of applications that may have been activated */
@@ -60,6 +57,7 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
return Collections.unmodifiableMap(applicationActivated);
}
+ /** The exception to throw on the next prepare run, or null to continue normally */
public void throwOnNextPrepare(RuntimeException prepareException) {
this.prepareException = prepareException;
}
@@ -71,10 +69,16 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
public Map<URI, Version> versions() {
return versions;
}
+
+ /** Set the default config server version */
+ public void setDefaultVersion(Version version) {
+ this.defaultVersion = version;
+ }
@Override
- public PreparedApplication prepare(DeploymentId deployment, DeployOptions deployOptions, Set<String> rotationCnames, Set<Rotation> rotations, byte[] content) {
- lastPrepareVersion = deployOptions.vespaVersion.map(Version::new);
+ public PreparedApplication prepare(DeploymentId deployment, DeployOptions deployOptions, Set<String> rotationCnames,
+ Set<Rotation> rotations, byte[] content) {
+ lastPrepareVersion = deployOptions.vespaVersion.map(Version::new).orElse(null);
if (prepareException != null) {
RuntimeException prepareException = this.prepareException;
this.prepareException = null;
@@ -108,23 +112,20 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
public PrepareResponse prepareResponse() {
PrepareResponse prepareResponse = new PrepareResponse();
prepareResponse.message = "foo";
- prepareResponse.configChangeActions = new ConfigChangeActions(Collections.emptyList(), Collections.emptyList());
+ prepareResponse.configChangeActions = new ConfigChangeActions(Collections.emptyList(),
+ Collections.emptyList());
prepareResponse.tenant = new TenantId("tenant");
return prepareResponse;
}
};
}
-
- /** Set the default config server version */
- public void setDefaultVersion(Version version) { this.defaultVersion = version; }
@Override
public List<String> getNodeQueryHost(DeploymentId deployment, String type) {
if (applicationInstances.containsKey(deployment.applicationId())) {
return Collections.singletonList(applicationInstances.get(deployment.applicationId()));
- } else {
- return Collections.emptyList();
}
+ return Collections.emptyList();
}
@Override
@@ -151,7 +152,8 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
// Returns a canned example response
@Override
- public ApplicationView getApplicationView(String tenantName, String applicationName, String instanceName, String environment, String region) {
+ public ApplicationView getApplicationView(String tenantName, String applicationName, String instanceName,
+ String environment, String region) {
ApplicationView applicationView = new ApplicationView();
ClusterView cluster = new ClusterView();
cluster.name = "cluster1";
@@ -172,7 +174,8 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
// Returns a canned example response
@Override
- public Map<?,?> getServiceApiResponse(String tenantName, String applicationName, String instanceName, String environment, String region, String serviceName, String restPath) {
+ public Map<?,?> getServiceApiResponse(String tenantName, String applicationName, String instanceName,
+ String environment, String region, String serviceName, String restPath) {
Map<String,List<?>> root = new HashMap<>();
List<Map<?,?>> resources = new ArrayList<>();
Map<String,String> resource = new HashMap<>();
@@ -199,7 +202,7 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS
}
@Override
- public NodeList getNodeList(DeploymentId deployment) throws IOException {
+ public NodeList getNodeList(DeploymentId deployment) {
NodeList list = new NodeList();
list.nodes = new ArrayList<>();
NodeList.Node hostA = new NodeList.Node();
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerProxyMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerProxyMock.java
index cc915d4d9a1..02b33e4640a 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerProxyMock.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerProxyMock.java
@@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.controller;
import com.yahoo.component.AbstractComponent;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.vespa.hosted.controller.proxy.ConfigServerRestExecutor;
-import com.yahoo.vespa.hosted.controller.proxy.ProxyException;
import com.yahoo.vespa.hosted.controller.proxy.ProxyRequest;
import com.yahoo.vespa.hosted.controller.restapi.StringResponse;
@@ -21,7 +20,7 @@ public class ConfigServerProxyMock extends AbstractComponent implements ConfigSe
private volatile String requestBody = null;
@Override
- public HttpResponse handle(ProxyRequest proxyRequest) throws ProxyException {
+ public HttpResponse handle(ProxyRequest proxyRequest) {
lastReceived = proxyRequest;
// Copy request body as the input stream is drained once the request completes
requestBody = asString(proxyRequest.getData());
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/VersionStatusSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/VersionStatusSerializerTest.java
index 189b3a97a80..c668bde0d40 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/VersionStatusSerializerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/VersionStatusSerializerTest.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertEquals;
public class VersionStatusSerializerTest {
@Test
- public void testSerialization() throws Exception {
+ public void testSerialization() {
List<VespaVersion> vespaVersions = new ArrayList<>();
DeploymentStatistics statistics = new DeploymentStatistics(
Version.fromString("5.0"),
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerControllerTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerControllerTester.java
index fb0adcd3152..9f5de1e460b 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerControllerTester.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerControllerTester.java
@@ -45,18 +45,16 @@ import java.util.Optional;
public class ContainerControllerTester {
private final ContainerTester containerTester;
- private final Controller controller;
private final Upgrader upgrader;
public ContainerControllerTester(JDisc container, String responseFilePath) {
containerTester = new ContainerTester(container, responseFilePath);
- controller = (Controller)container.components().getComponent("com.yahoo.vespa.hosted.controller.Controller");
CuratorDb curatorDb = new MockCuratorDb();
curatorDb.writeUpgradesPerMinute(100);
- upgrader = new Upgrader(controller, Duration.ofDays(1), new JobControl(curatorDb), curatorDb);
+ upgrader = new Upgrader(controller(), Duration.ofDays(1), new JobControl(curatorDb), curatorDb);
}
- public Controller controller() { return controller; }
+ public Controller controller() { return containerTester.controller(); }
public Upgrader upgrader() { return upgrader; }
@@ -70,18 +68,18 @@ public class ContainerControllerTester {
public Application createApplication(String athensDomain, String tenant, String application) {
AthenzDomain domain1 = addTenantAthenzDomain(athensDomain, "mytenant");
- controller.tenants().addTenant(Tenant.createAthensTenant(new TenantId(tenant), domain1,
+ controller().tenants().addTenant(Tenant.createAthensTenant(new TenantId(tenant), domain1,
new Property("property1"),
Optional.of(new PropertyId("1234"))),
Optional.of(TestIdentities.userNToken));
ApplicationId app = ApplicationId.from(tenant, application, "default");
- return controller.applications().createApplication(app, Optional.of(TestIdentities.userNToken));
+ return controller().applications().createApplication(app, Optional.of(TestIdentities.userNToken));
}
public Application deploy(Application application, ApplicationPackage applicationPackage, Zone zone, long projectId) {
ScrewdriverId app1ScrewdriverId = new ScrewdriverId(String.valueOf(projectId));
GitRevision app1RevisionId = new GitRevision(new GitRepository("repo"), new GitBranch("master"), new GitCommit("commit1"));
- controller.applications().deployApplication(application.id(),
+ controller().applications().deployApplication(application.id(),
zone,
applicationPackage,
new DeployOptions(Optional.of(new ScrewdriverBuildJob(app1ScrewdriverId, app1RevisionId)), Optional.empty(), false, false));
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerTester.java
index c0e8b48f821..95810e90cdb 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerTester.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ContainerTester.java
@@ -43,14 +43,16 @@ public class ContainerTester {
public JDisc container() { return container; }
+ public Controller controller() {
+ return (Controller) container.components().getComponent(Controller.class.getName());
+ }
+
public void updateSystemVersion() {
- Controller controller = (Controller)container.components().getComponent("com.yahoo.vespa.hosted.controller.Controller");
- controller.updateVersionStatus(VersionStatus.compute(controller));
+ controller().updateVersionStatus(VersionStatus.compute(controller()));
}
public void updateSystemVersion(Version version) {
- Controller controller = (Controller)container.components().getComponent("com.yahoo.vespa.hosted.controller.Controller");
- controller.updateVersionStatus(VersionStatus.compute(controller, version));
+ controller().updateVersionStatus(VersionStatus.compute(controller(), version));
}
public void assertResponse(Supplier<Request> request, File responseFile) throws IOException {