aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'configserver/src/test')
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java13
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java31
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantTest.java46
3 files changed, 38 insertions, 52 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index 90f0b5ee4e5..17cbe41fde5 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -27,6 +27,7 @@ import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -76,18 +77,26 @@ public class ApplicationRepositoryTest {
@Test
public void createAndPrepareAndActivate() throws IOException {
- PrepareResult result = createAndPrepareAndActivateApp();
+ PrepareResult result = deployApp();
assertTrue(result.configChangeActions().getRefeedActions().isEmpty());
assertTrue(result.configChangeActions().getRestartActions().isEmpty());
}
+ @Test
+ public void deleteUnusedTenants() throws IOException {
+ deployApp();
+ assertTrue(applicationRepository.removeUnusedTenants().isEmpty());
+ applicationRepository.remove(applicationId());
+ assertEquals(tenantName, applicationRepository.removeUnusedTenants().iterator().next());
+ }
+
private PrepareResult prepareAndActivateApp(File application) throws IOException {
FilesApplicationPackage appDir = FilesApplicationPackage.fromFile(application);
long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, appDir.getAppDir());
return applicationRepository.prepareAndActivate(tenant, sessionId, prepareParams(), false, false, Instant.now());
}
- private PrepareResult createAndPrepareAndActivateApp() throws IOException {
+ private PrepareResult deployApp() throws IOException {
File file = CompressedApplicationInputStreamTest.createTarFile();
return applicationRepository.deploy(CompressedApplicationInputStream.createFromCompressedStream(
new FileInputStream(file), ApplicationApiHandler.APPLICATION_X_GZIP),
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 0963e2ea024..35b22d19d6a 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
@@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server.http.v2;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.Clock;
@@ -11,7 +12,14 @@ import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.TenantName;
+import com.yahoo.vespa.config.server.ApplicationRepository;
+import com.yahoo.vespa.config.server.TestComponentRegistry;
+import com.yahoo.vespa.config.server.http.SessionHandlerTest;
+import com.yahoo.vespa.config.server.http.SessionResponse;
import com.yahoo.vespa.config.server.tenant.Tenant;
+import com.yahoo.vespa.config.server.tenant.TenantRepository;
+import com.yahoo.vespa.curator.mock.MockCurator;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -20,14 +28,23 @@ import com.yahoo.jdisc.http.HttpRequest.Method;
import com.yahoo.vespa.config.server.http.BadRequestException;
import com.yahoo.vespa.config.server.http.NotFoundException;
-public class TenantHandlerTest extends TenantTest {
+public class TenantHandlerTest {
+ private TenantRepository tenantRepository;
private TenantHandler handler;
private final TenantName a = TenantName.from("a");
@Before
public void setup() {
- handler = new TenantHandler(TenantHandler.testOnlyContext(), tenantRepository);
+ tenantRepository = new TenantRepository(new TestComponentRegistry.Builder().curator(new MockCurator()).build());
+ ApplicationRepository applicationRepository =
+ new ApplicationRepository(tenantRepository, new SessionHandlerTest.MockProvisioner(), Clock.systemUTC());
+ handler = new TenantHandler(TenantHandler.testOnlyContext(), tenantRepository, applicationRepository);
+ }
+
+ @After
+ public void closeTenantRepo() {
+ tenantRepository.close();
}
@Test
@@ -96,8 +113,8 @@ public class TenantHandlerTest extends TenantTest {
try {
handler.handleDELETE(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + a, Method.DELETE));
fail();
- } catch (BadRequestException e) {
- assertThat(e.getMessage(), is("Cannot delete tenant 'a', as it has active applications: [a.foo]"));
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage(), is("Cannot delete tenant 'a', it has active applications: [a.foo]"));
}
}
@@ -115,4 +132,10 @@ public class TenantHandlerTest extends TenantTest {
return (TenantCreateResponse) handler.handlePUT(testRequest);
}
+ private void assertResponseEquals(SessionResponse response, String payload) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ response.render(baos);
+ assertEquals(baos.toString("UTF-8"), payload);
+ }
+
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantTest.java
deleted file mode 100644
index 7814266f815..00000000000
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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 static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.concurrent.Executor;
-
-import com.yahoo.vespa.config.server.*;
-import com.yahoo.vespa.config.server.http.SessionResponse;
-import com.yahoo.vespa.config.server.tenant.TenantRepository;
-import org.junit.After;
-import org.junit.Before;
-
-/**
- * Supertype for tests in the multi tenant application API
- *
- * @author Vegard Havdal
- *
- */
-public class TenantTest extends TestWithCurator {
-
- protected TenantRepository tenantRepository;
-
- @Before
- public void setupTenants() {
- tenantRepository = createTenants();
- }
-
- @After
- public void closeTenants() {
- tenantRepository.close();
- }
-
- private TenantRepository createTenants() {
- return new TenantRepository(new TestComponentRegistry.Builder().curator(curator).build());
- }
-
- void assertResponseEquals(SessionResponse response, String payload) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- response.render(baos);
- assertEquals(baos.toString("UTF-8"), payload);
- }
-
-}