aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-05-16 10:10:30 +0200
committerGitHub <noreply@github.com>2018-05-16 10:10:30 +0200
commit8026fff81e084e02e6dcee34d663348ddabbcc7e (patch)
treed2fcee42f5778739d4433d25e20001b25e3d4b6e
parent6cd386889df2cfa589602fe9926f1eac0c0fe519 (diff)
parentcea387edfcfe7b700a8eb927ddf618cb2dfb8269 (diff)
Merge pull request #5870 from vespa-engine/hmusum/refactor-test
Refactor tests
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java12
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java258
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java25
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java2
4 files changed, 110 insertions, 187 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index ab825f14b68..4f8d7818316 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -152,8 +152,18 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
public PrepareResult deploy(CompressedApplicationInputStream in, PrepareParams prepareParams,
boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) {
File tempDir = Files.createTempDir();
+ return deploy(decompressApplication(in, tempDir), prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now);
+ }
+
+ public PrepareResult deploy(File applicationPackage, PrepareParams prepareParams) {
+ return deploy(applicationPackage, prepareParams, false, false, Instant.now());
+ }
+
+ public PrepareResult deploy(File applicationPackage, PrepareParams prepareParams,
+ boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) {
+ File tempDir = Files.createTempDir();
ApplicationId applicationId = prepareParams.getApplicationId();
- long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), decompressApplication(in, tempDir));
+ long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationPackage);
cleanupApplicationDirectory(tempDir, logger);
Tenant tenant = tenantRepository.getTenant(applicationId.tenant());
return prepareAndActivate(tenant, sessionId, prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now);
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
index 0a193f7eedd..ce84cf4c280 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java
@@ -3,21 +3,14 @@ package com.yahoo.vespa.config.server.http.v2;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.cloud.config.ConfigserverConfig;
-import com.yahoo.config.application.api.ApplicationPackage;
-import com.yahoo.config.model.NullConfigModelRegistry;
-import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ApplicationName;
-import com.yahoo.config.provision.Provisioner;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.jdisc.Response;
-import com.yahoo.path.Path;
import com.yahoo.vespa.config.server.ApplicationRepository;
-import com.yahoo.vespa.config.server.GlobalComponentRegistry;
-import com.yahoo.vespa.config.server.SuperModelGenerationCounter;
import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.application.ApplicationConvergenceChecker;
import com.yahoo.vespa.config.server.application.HttpProxy;
@@ -25,22 +18,13 @@ import com.yahoo.vespa.config.server.http.HandlerTest;
import com.yahoo.vespa.config.server.http.HttpErrorResponse;
import com.yahoo.vespa.config.server.http.StaticResponse;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
-import com.yahoo.vespa.config.server.http.SimpleHttpFetcher;
-import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
import com.yahoo.vespa.config.server.provision.HostProvisionerProvider;
import com.yahoo.vespa.config.server.session.LocalSession;
-import com.yahoo.vespa.config.server.session.MockSessionZKClient;
-import com.yahoo.vespa.config.server.session.RemoteSession;
-import com.yahoo.vespa.config.server.session.SessionContext;
-import com.yahoo.vespa.config.server.session.SessionZooKeeperClient;
+import com.yahoo.vespa.config.server.session.PrepareParams;
import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantBuilder;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
-import com.yahoo.vespa.curator.mock.MockCurator;
-import com.yahoo.vespa.model.VespaModelFactory;
-import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import javax.ws.rs.client.Client;
@@ -48,7 +32,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.time.Clock;
-import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
@@ -69,14 +52,14 @@ public class ApplicationHandlerTest {
private static File testApp = new File("src/test/apps/app");
- private ApplicationHandler mockHandler;
private ListApplicationsHandler listApplicationsHandler;
private final static TenantName mytenantName = TenantName.from("mytenant");
private final static TenantName foobar = TenantName.from("foobar");
+ private final static ApplicationId applicationId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
private TenantRepository tenantRepository;
+ private ApplicationRepository applicationRepository;
private SessionHandlerTest.MockProvisioner provisioner;
private MockStateApiFactory stateApiFactory = new MockStateApiFactory();
- private final HttpProxy mockHttpProxy = mock(HttpProxy.class);
@Before
public void setup() {
@@ -85,136 +68,103 @@ public class ApplicationHandlerTest {
tenantRepository.addTenant(TenantBuilder.create(componentRegistry, mytenantName));
tenantRepository.addTenant(TenantBuilder.create(componentRegistry, foobar));
provisioner = new SessionHandlerTest.MockProvisioner();
- mockHandler = createMockApplicationHandler(provisioner,
- new ApplicationConvergenceChecker(stateApiFactory),
- mockHttpProxy);
+ applicationRepository = new ApplicationRepository(tenantRepository, provisioner, Clock.systemUTC());
listApplicationsHandler = new ListApplicationsHandler(ListApplicationsHandler.testOnlyContext(),
tenantRepository,
Zone.defaultZone());
}
- private ApplicationHandler createMockApplicationHandler(
- Provisioner provisioner,
- ApplicationConvergenceChecker convergeChecker,
- HttpProxy httpProxy) {
- return new ApplicationHandler(
- ApplicationHandler.testOnlyContext(),
- Zone.defaultZone(),
- new ApplicationRepository(tenantRepository,
- HostProvisionerProvider.withProvisioner(provisioner),
- convergeChecker,
- httpProxy,
- new ConfigserverConfig(new ConfigserverConfig.Builder())));
- }
-
- private ApplicationHandler createApplicationHandler(TenantRepository tenantRepository) {
- return new ApplicationHandler(
- ApplicationHandler.testOnlyContext(),
- Zone.defaultZone(),
- new ApplicationRepository(tenantRepository,
- HostProvisionerProvider.withProvisioner(provisioner),
- new ApplicationConvergenceChecker(stateApiFactory),
- new HttpProxy(new SimpleHttpFetcher()),
- new ConfigserverConfig(new ConfigserverConfig.Builder())));
- }
-
@Test
public void testDelete() throws Exception {
- Clock clock = Clock.systemUTC();
- ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- assertApplicationExists(mytenantName, null, Zone.defaultZone());
-
- long sessionId = 1;
{
// This block is a real test of the interplay of (most of) the components of the config server
// TODO: Extract it to ApplicationRepositoryTest, rewrite to bypass the HTTP layer and extend
// as login is moved from the HTTP layer into ApplicationRepository
- TenantRepository tenantRepository = addApplication(defaultId, sessionId);
- ApplicationHandler handler = createApplicationHandler(tenantRepository);
- Tenant mytenant = tenantRepository.getTenant(defaultId.tenant());
+
+ PrepareResult result = applicationRepository.deploy(testApp, prepareParams(applicationId));
+ long sessionId = result.sessionId();
+ Tenant mytenant = tenantRepository.getTenant(applicationId.tenant());
LocalSession applicationData = mytenant.getLocalSessionRepo().getSession(sessionId);
assertNotNull(applicationData);
assertNotNull(applicationData.getApplicationId());
assertFalse(provisioner.removed);
- deleteAndAssertOKResponse(handler, mytenant, defaultId);
+ deleteAndAssertOKResponse(mytenant, applicationId);
assertTrue(provisioner.removed);
assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
- assertThat(provisioner.lastApplicationId, is(defaultId));
+ assertThat(provisioner.lastApplicationId, is(applicationId));
assertNull(mytenant.getLocalSessionRepo().getSession(sessionId));
assertNull(mytenant.getRemoteSessionRepo().getSession(sessionId));
}
- sessionId++;
{
- addMockApplication(tenantRepository.getTenant(mytenantName), defaultId, sessionId, clock);
- deleteAndAssertOKResponseMocked(defaultId, true);
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
+ deleteAndAssertOKResponseMocked(applicationId, true);
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
ApplicationId fooId = new ApplicationId.Builder()
- .tenant(mytenantName)
- .applicationName("foo").instanceName("quux").build();
-
- sessionId++;
-
- addMockApplication(tenantRepository.getTenant(mytenantName), fooId, sessionId, clock);
- addMockApplication(tenantRepository.getTenant(foobar), fooId, sessionId, clock);
- assertApplicationExists(mytenantName, fooId, Zone.defaultZone());
- assertApplicationExists(foobar, fooId, Zone.defaultZone());
+ .tenant(foobar)
+ .applicationName("foo")
+ .instanceName("quux")
+ .build();
+ PrepareParams prepareParams2 = new PrepareParams.Builder().applicationId(fooId).build();
+ applicationRepository.deploy(testApp, prepareParams2);
+
+ assertApplicationExists(fooId, Zone.defaultZone());
deleteAndAssertOKResponseMocked(fooId, true);
- assertThat(provisioner.lastApplicationId.tenant(), is(mytenantName));
assertThat(provisioner.lastApplicationId, is(fooId));
- assertApplicationExists(mytenantName, null, Zone.defaultZone());
- assertApplicationExists(foobar, fooId, Zone.defaultZone());
+ assertApplicationExists(applicationId, Zone.defaultZone());
+
+ deleteAndAssertOKResponseMocked(applicationId, true);
}
- sessionId++;
{
ApplicationId baliId = new ApplicationId.Builder()
.tenant(mytenantName)
- .applicationName("bali").instanceName("quux").build();
- addMockApplication(tenantRepository.getTenant(mytenantName), baliId, sessionId, clock);
+ .applicationName("bali")
+ .instanceName("quux")
+ .build();
+ PrepareParams prepareParamsBali = new PrepareParams.Builder().applicationId(baliId).build();
+ applicationRepository.deploy(testApp, prepareParamsBali);
deleteAndAssertOKResponseMocked(baliId, true);
- assertApplicationExists(mytenantName, null, Zone.defaultZone());
}
}
@Test
public void testGet() throws Exception {
- long sessionId = 1;
- ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- addMockApplication(tenantRepository.getTenant(mytenantName), defaultId, sessionId, Clock.systemUTC());
- assertApplicationGeneration(defaultId, Zone.defaultZone(), 1, true);
- assertApplicationGeneration(defaultId, Zone.defaultZone(), 1, false);
+ long sessionId = applicationRepository.deploy(testApp, prepareParams(applicationId)).sessionId();
+ assertApplicationGeneration(applicationId, Zone.defaultZone(), sessionId, true);
+ assertApplicationGeneration(applicationId, Zone.defaultZone(), sessionId, false);
}
@Test
public void testRestart() throws Exception {
- long sessionId = 1;
- ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- addMockApplication(tenantRepository.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
assertFalse(provisioner.restarted);
- restart(application, Zone.defaultZone());
+ restart(applicationId, Zone.defaultZone());
assertTrue(provisioner.restarted);
- assertEquals(application, provisioner.lastApplicationId);
+ assertEquals(applicationId, provisioner.lastApplicationId);
}
@Test
public void testConverge() throws Exception {
- long sessionId = 1;
- ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- addMockApplication(tenantRepository.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
- converge(application, Zone.defaultZone());
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
+ converge(applicationId, Zone.defaultZone());
}
@Test
public void testClusterControllerStatus() throws Exception {
- long sessionId = 1;
- ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- addMockApplication(tenantRepository.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
String host = "foo.yahoo.com";
- String url = toUrlPath(application, Zone.defaultZone(), true) + "/clustercontroller/" + host + "/status/v1/clusterName1";
-
+ String url = toUrlPath(applicationId, Zone.defaultZone(), true) + "/clustercontroller/" + host + "/status/v1/clusterName1";
+ HttpProxy mockHttpProxy = mock(HttpProxy.class);
+ ApplicationRepository applicationRepository = new ApplicationRepository(tenantRepository,
+ HostProvisionerProvider.withProvisioner(provisioner),
+ new ApplicationConvergenceChecker(stateApiFactory),
+ mockHttpProxy,
+ new ConfigserverConfig(new ConfigserverConfig.Builder()));
+ ApplicationHandler mockHandler = createApplicationHandler(applicationRepository);
when(mockHttpProxy.get(any(), eq(host), eq("container-clustercontroller"), eq("clustercontroller-status/v1/clusterName1")))
.thenReturn(new StaticResponse(200, "text/html", "<html>...</html>"));
@@ -228,42 +178,11 @@ public class ApplicationHandlerTest {
}
@Test
- @Ignore
- public void testFailingProvisioner() throws Exception {
- provisioner = new SessionHandlerTest.FailingMockProvisioner();
- mockHandler = createMockApplicationHandler(
- provisioner,
- new ApplicationConvergenceChecker(stateApiFactory),
- new HttpProxy(new SimpleHttpFetcher()));
- final ApplicationId applicationId = ApplicationId.defaultId();
- addMockApplication(tenantRepository.getTenant(mytenantName), applicationId, 1, Clock.systemUTC());
- assertApplicationExists(mytenantName, applicationId, Zone.defaultZone());
- provisioner.activated = true;
-
- String url = "http://myhost:14000/application/v2/tenant/" + mytenantName + "/application/" + applicationId.application();
- deleteAndAssertResponse(mockHandler, url, 500, null, "{\"message\":\"Cannot remove application\"}", com.yahoo.jdisc.http.HttpRequest.Method.DELETE);
- assertApplicationExists(mytenantName, applicationId, Zone.defaultZone());
- Assert.assertTrue(provisioner.activated);
- }
-
- static void addMockApplication(Tenant tenant, ApplicationId applicationId, long sessionId, Clock clock) {
- tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
- ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
- tenant.getLocalSessionRepo().addSession(new SessionHandlerTest.MockSession(sessionId, app, applicationId));
- TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
- .modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))))
- .build();
- tenant.getRemoteSessionRepo().addSession(new RemoteSession(tenant.getName(), sessionId, componentRegistry, new MockSessionZKClient(app), clock));
- }
-
- @Test
public void testFileDistributionStatus() throws Exception {
- long sessionId = 1;
- ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build();
- addMockApplication(tenantRepository.getTenant(mytenantName), application, sessionId, Clock.systemUTC());
+ applicationRepository.deploy(testApp, prepareParams(applicationId));
Zone zone = Zone.defaultZone();
- HttpResponse response = fileDistributionStatus(application, zone);
+ HttpResponse response = fileDistributionStatus(applicationId, zone);
assertEquals(200, response.getStatus());
SessionHandlerTest.getRenderedString(response);
assertEquals("{\"hosts\":[{\"hostname\":\"mytesthost\",\"status\":\"UNKNOWN\",\"message\":\"error: Connection error(104)\",\"fileReferences\":[]}],\"status\":\"UNKNOWN\"}",
@@ -277,71 +196,31 @@ public class ApplicationHandlerTest {
SessionHandlerTest.getRenderedString(responseForUnknown));
}
- private static TenantRepository addApplication(ApplicationId applicationId, long sessionId) throws Exception {
- // This method is a good illustration of the spaghetti wiring resulting from no design
- // TODO: When this setup looks sane we have refactored sufficiently that there is a design
-
- TenantName tenantName = applicationId.tenant();
-
- Path tenantPath = TenantRepository.getTenantPath(tenantName);
- Path sessionPath = tenantPath.append(Tenant.SESSIONS).append(String.valueOf(sessionId));
-
- MockCurator curator = new MockCurator();
- GlobalComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
- .curator(curator)
- .modelFactoryRegistry(new ModelFactoryRegistry(
- Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))))
- .build();
-
- TenantRepository tenantRepository = new TenantRepository(componentRegistry); // Creates the application path element in zk
- tenantRepository.addTenant(tenantName);
- Tenant tenant = tenantRepository.getTenant(tenantName);
-
- tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
- ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
-
- SessionZooKeeperClient sessionClient = new SessionZooKeeperClient(curator, sessionPath);
- SessionContext context = new SessionContext(app,
- sessionClient,
- new File("/serverDb"),
- tenant.getApplicationRepo(),
- null,
- new SuperModelGenerationCounter(curator));
- tenant.getLocalSessionRepo().addSession(new LocalSession(tenantName, sessionId, null, context));
- sessionClient.writeApplicationId(applicationId); // TODO: Instead, use ApplicationRepository to deploy the application
-
- tenant.getRemoteSessionRepo().addSession(
- new RemoteSession(tenantName, sessionId,
- componentRegistry,
- sessionClient,
- Clock.systemUTC()));
- return tenantRepository;
- }
-
private void assertNotAllowed(com.yahoo.jdisc.http.HttpRequest.Method method) throws IOException {
String url = "http://myhost:14000/application/v2/tenant/" + mytenantName + "/application/default";
- deleteAndAssertResponse(mockHandler, url, Response.Status.METHOD_NOT_ALLOWED, HttpErrorResponse.errorCodes.METHOD_NOT_ALLOWED, "{\"error-code\":\"METHOD_NOT_ALLOWED\",\"message\":\"Method '" + method + "' is not supported\"}",
+ deleteAndAssertResponse(url, Response.Status.METHOD_NOT_ALLOWED, HttpErrorResponse.errorCodes.METHOD_NOT_ALLOWED, "{\"error-code\":\"METHOD_NOT_ALLOWED\",\"message\":\"Method '" + method + "' is not supported\"}",
method);
}
private void deleteAndAssertOKResponseMocked(ApplicationId applicationId, boolean fullAppIdInUrl) throws IOException {
long sessionId = tenantRepository.getTenant(applicationId.tenant()).getApplicationRepo().getSessionIdForApplication(applicationId);
- deleteAndAssertResponse(mockHandler, applicationId, Zone.defaultZone(), Response.Status.OK, null, fullAppIdInUrl);
+ deleteAndAssertResponse(applicationId, Zone.defaultZone(), Response.Status.OK, null, fullAppIdInUrl);
assertNull(tenantRepository.getTenant(applicationId.tenant()).getLocalSessionRepo().getSession(sessionId));
}
- private void deleteAndAssertOKResponse(ApplicationHandler handler, Tenant tenant, ApplicationId applicationId) throws IOException {
+ private void deleteAndAssertOKResponse(Tenant tenant, ApplicationId applicationId) throws IOException {
long sessionId = tenant.getApplicationRepo().getSessionIdForApplication(applicationId);
- deleteAndAssertResponse(handler, applicationId, Zone.defaultZone(), Response.Status.OK, null, true);
+ deleteAndAssertResponse(applicationId, Zone.defaultZone(), Response.Status.OK, null, true);
assertNull(tenant.getLocalSessionRepo().getSession(sessionId));
}
- private void deleteAndAssertResponse(ApplicationHandler handler, ApplicationId applicationId, Zone zone, int expectedStatus, HttpErrorResponse.errorCodes errorCode, boolean fullAppIdInUrl) throws IOException {
+ private void deleteAndAssertResponse(ApplicationId applicationId, Zone zone, int expectedStatus, HttpErrorResponse.errorCodes errorCode, boolean fullAppIdInUrl) throws IOException {
String expectedResponse = "{\"message\":\"Application '" + applicationId + "' deleted\"}";
- deleteAndAssertResponse(handler, toUrlPath(applicationId, zone, fullAppIdInUrl), expectedStatus, errorCode, expectedResponse, com.yahoo.jdisc.http.HttpRequest.Method.DELETE);
+ deleteAndAssertResponse(toUrlPath(applicationId, zone, fullAppIdInUrl), expectedStatus, errorCode, expectedResponse, com.yahoo.jdisc.http.HttpRequest.Method.DELETE);
}
- private void deleteAndAssertResponse(ApplicationHandler handler, String url, int expectedStatus, HttpErrorResponse.errorCodes errorCode, String expectedResponse, com.yahoo.jdisc.http.HttpRequest.Method method) throws IOException {
+ private void deleteAndAssertResponse(String url, int expectedStatus, HttpErrorResponse.errorCodes errorCode, String expectedResponse, com.yahoo.jdisc.http.HttpRequest.Method method) throws IOException {
+ ApplicationHandler handler = createApplicationHandler();
HttpResponse response = handler.handle(HttpRequest.createTestRequest(url, method));
if (expectedStatus == 200) {
HandlerTest.assertHttpStatusCodeAndMessage(response, 200, expectedResponse);
@@ -362,11 +241,12 @@ public class ApplicationHandlerTest {
}
private void assertApplicationGeneration(String url, long expectedGeneration) throws IOException {
- HttpResponse response = mockHandler.handle(HttpRequest.createTestRequest(url, com.yahoo.jdisc.http.HttpRequest.Method.GET));
+ HttpResponse response = createApplicationHandler().handle(HttpRequest.createTestRequest(url, com.yahoo.jdisc.http.HttpRequest.Method.GET));
HandlerTest.assertHttpStatusCodeAndMessage(response, 200, "{\"generation\":" + expectedGeneration + "}");
}
- private void assertApplicationExists(TenantName tenantName, ApplicationId applicationId, Zone zone) throws IOException {
+ private void assertApplicationExists(ApplicationId applicationId, Zone zone) throws IOException {
+ String tenantName = applicationId == null ? null : applicationId.tenant().value();
String expected = applicationId == null ? "[]" : "[\"http://myhost:14000/application/v2/tenant/" + tenantName + "/application/" + applicationId.application().value() +
"/environment/" + zone.environment().value() +
"/region/" + zone.region().value() +
@@ -379,23 +259,23 @@ public class ApplicationHandlerTest {
private void restart(ApplicationId application, Zone zone) throws IOException {
String restartUrl = toUrlPath(application, zone, true) + "/restart";
- HttpResponse response = mockHandler.handle(HttpRequest.createTestRequest(restartUrl, com.yahoo.jdisc.http.HttpRequest.Method.POST));
+ HttpResponse response = createApplicationHandler().handle(HttpRequest.createTestRequest(restartUrl, com.yahoo.jdisc.http.HttpRequest.Method.POST));
HandlerTest.assertHttpStatusCodeAndMessage(response, 200, "");
}
private void converge(ApplicationId application, Zone zone) throws IOException {
String convergeUrl = toUrlPath(application, zone, true) + "/serviceconverge";
- HttpResponse response = mockHandler.handle(HttpRequest.createTestRequest(convergeUrl, com.yahoo.jdisc.http.HttpRequest.Method.GET));
+ HttpResponse response = createApplicationHandler().handle(HttpRequest.createTestRequest(convergeUrl, com.yahoo.jdisc.http.HttpRequest.Method.GET));
HandlerTest.assertHttpStatusCodeAndMessage(response, 200, "");
}
private HttpResponse fileDistributionStatus(ApplicationId application, Zone zone) {
String restartUrl = toUrlPath(application, zone, true) + "/filedistributionstatus";
- return mockHandler.handle(HttpRequest.createTestRequest(restartUrl, com.yahoo.jdisc.http.HttpRequest.Method.GET));
+ return createApplicationHandler().handle(HttpRequest.createTestRequest(restartUrl, com.yahoo.jdisc.http.HttpRequest.Method.GET));
}
private static class MockStateApiFactory implements ApplicationConvergenceChecker.StateApiFactory {
- public boolean createdApi = false;
+ boolean createdApi = false;
@Override
public ApplicationConvergenceChecker.StateApi createStateApi(Client client, URI serviceUri) {
createdApi = true;
@@ -409,4 +289,16 @@ public class ApplicationHandlerTest {
}
}
+ private ApplicationHandler createApplicationHandler() {
+ return createApplicationHandler(applicationRepository);
+ }
+
+ private ApplicationHandler createApplicationHandler(ApplicationRepository applicationRepository) {
+ return new ApplicationHandler(ApplicationHandler.testOnlyContext(), Zone.defaultZone(), applicationRepository);
+ }
+
+ private PrepareParams prepareParams(ApplicationId applicationId) {
+ return new PrepareParams.Builder().applicationId(applicationId).build();
+ }
+
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java
index 0ac08bfcfb0..04b187f6b1d 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java
@@ -1,6 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;
+import com.yahoo.config.application.api.ApplicationPackage;
+import com.yahoo.config.model.NullConfigModelRegistry;
+import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.*;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
@@ -10,11 +13,18 @@ import com.yahoo.vespa.config.server.host.HostRegistries;
import com.yahoo.vespa.config.server.host.HostRegistry;
import com.yahoo.vespa.config.server.http.HandlerTest;
import com.yahoo.vespa.config.server.http.HttpErrorResponse;
+import com.yahoo.vespa.config.server.http.SessionHandlerTest;
+import com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry;
+import com.yahoo.vespa.config.server.session.MockSessionZKClient;
+import com.yahoo.vespa.config.server.session.RemoteSession;
+import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantBuilder;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
+import com.yahoo.vespa.model.VespaModelFactory;
import org.junit.Before;
import org.junit.Test;
+import java.io.File;
import java.io.IOException;
import java.time.Clock;
import java.util.Collections;
@@ -28,6 +38,7 @@ import static org.junit.Assert.assertThat;
*/
public class HostHandlerTest {
private static final String urlPrefix = "http://myhost:14000/application/v2/host/";
+ private static File testApp = new File("src/test/apps/app");
private HostHandler handler;
private final static TenantName mytenant = TenantName.from("mytenant");
@@ -36,6 +47,16 @@ public class HostHandlerTest {
private HostRegistries hostRegistries;
private HostHandler hostHandler;
+ static void addMockApplication(Tenant tenant, ApplicationId applicationId, long sessionId, Clock clock) {
+ tenant.getApplicationRepo().createPutApplicationTransaction(applicationId, sessionId).commit();
+ ApplicationPackage app = FilesApplicationPackage.fromFile(testApp);
+ tenant.getLocalSessionRepo().addSession(new SessionHandlerTest.MockSession(sessionId, app, applicationId));
+ TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
+ .modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(new VespaModelFactory(new NullConfigModelRegistry()))))
+ .build();
+ tenant.getRemoteSessionRepo().addSession(new RemoteSession(tenant.getName(), sessionId, componentRegistry, new MockSessionZKClient(app), clock));
+ }
+
@Before
public void setup() {
TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
@@ -63,14 +84,14 @@ public class HostHandlerTest {
assertThat(hostRegistries, is(hostHandler.hostRegistries));
long sessionId = 1;
ApplicationId id = ApplicationId.from(mytenant, ApplicationName.defaultName(), InstanceName.defaultName());
- ApplicationHandlerTest.addMockApplication(tenantRepository.getTenant(mytenant), id, sessionId, Clock.systemUTC());
+ addMockApplication(tenantRepository.getTenant(mytenant), id, sessionId, Clock.systemUTC());
assertApplicationForHost(hostname, mytenant, id, Zone.defaultZone());
}
@Test
public void require_that_handler_gives_error_for_unknown_hostname() throws Exception {
long sessionId = 1;
- ApplicationHandlerTest.addMockApplication(tenantRepository.getTenant(mytenant), ApplicationId.defaultId(), sessionId, Clock.systemUTC());
+ addMockApplication(tenantRepository.getTenant(mytenant), ApplicationId.defaultId(), sessionId, Clock.systemUTC());
final String hostname = "unknown";
assertErrorForHost(hostname,
Response.Status.NOT_FOUND,
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
index 6e56d3c30c3..0963e2ea024 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
@@ -91,7 +91,7 @@ public class TenantHandlerTest extends TenantTest {
int sessionId = 1;
ApplicationId app = ApplicationId.from(a, ApplicationName.from("foo"), InstanceName.defaultName());
- ApplicationHandlerTest.addMockApplication(tenant, app, sessionId, Clock.systemUTC());
+ HostHandlerTest.addMockApplication(tenant, app, sessionId, Clock.systemUTC());
try {
handler.handleDELETE(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + a, Method.DELETE));