summaryrefslogtreecommitdiffstats
path: root/configserver/src
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-08-03 11:27:03 +0200
committerHarald Musum <musum@verizonmedia.com>2020-08-03 11:27:03 +0200
commit4122984cc17c91582b16cc742e27345103aee10a (patch)
treeb2449e44f38f62c16f8fb8353a8d330ef5bdca24 /configserver/src
parent7b3e179d41e2679878bf2754a4cbd0aa3c32bbb1 (diff)
Simplify tests (stop using low-level code to setup test environment)
Diffstat (limited to 'configserver/src')
-rw-r--r--configserver/src/test/apps/content/schemas/music.sd50
-rw-r--r--configserver/src/test/apps/content/services.xml38
-rw-r--r--configserver/src/test/apps/content2/schemas/music.sd50
-rw-r--r--configserver/src/test/apps/content2/services.xml38
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java64
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java64
6 files changed, 247 insertions, 57 deletions
diff --git a/configserver/src/test/apps/content/schemas/music.sd b/configserver/src/test/apps/content/schemas/music.sd
new file mode 100644
index 00000000000..7670e78f22b
--- /dev/null
+++ b/configserver/src/test/apps/content/schemas/music.sd
@@ -0,0 +1,50 @@
+# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# A basic search definition - called music, should be saved to music.sd
+search music {
+
+ # It contains one document type only - called music as well
+ document music {
+
+ field title type string {
+ indexing: summary | index # How this field should be indexed
+ # index-to: title, default # Create two indexes
+ weight: 75 # Ranking importancy of this field, used by the built in nativeRank feature
+ }
+
+ field artist type string {
+ indexing: summary | attribute | index
+ # index-to: artist, default
+
+ weight: 25
+ }
+
+ field year type int {
+ indexing: summary | attribute
+ }
+
+ # Increase query
+ field popularity type int {
+ indexing: summary | attribute
+ }
+
+ field url type uri {
+ indexing: summary | index
+ }
+
+ }
+
+ rank-profile default inherits default {
+ first-phase {
+ expression: nativeRank(title,artist) + attribute(popularity)
+ }
+
+ }
+
+ rank-profile textmatch inherits default {
+ first-phase {
+ expression: nativeRank(title,artist)
+ }
+
+ }
+
+}
diff --git a/configserver/src/test/apps/content/services.xml b/configserver/src/test/apps/content/services.xml
new file mode 100644
index 00000000000..509d7786be0
--- /dev/null
+++ b/configserver/src/test/apps/content/services.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<services version="1.0">
+
+ <admin version="2.0">
+ <adminserver hostalias="node1"/>
+ <logserver hostalias="node1" />
+ </admin>
+
+ <content version="1.0">
+ <redundancy>2</redundancy>
+ <documents>
+ <document type="music" mode="index"/>
+ </documents>
+ <nodes>
+ <node hostalias="node1" distribution-key="0"/>
+ </nodes>
+
+ </content>
+
+ <container version="1.0">
+ <document-processing compressdocuments="true">
+ <chain id="ContainerWrapperTest">
+ <documentprocessor id="com.yahoo.vespa.config.AppleDocProc"/>
+ </chain>
+ </document-processing>
+
+ <config name="project.specific">
+ <value>someval</value>
+ </config>
+
+ <nodes>
+ <node hostalias="node1" />
+ </nodes>
+
+ </container>
+
+</services>
diff --git a/configserver/src/test/apps/content2/schemas/music.sd b/configserver/src/test/apps/content2/schemas/music.sd
new file mode 100644
index 00000000000..7670e78f22b
--- /dev/null
+++ b/configserver/src/test/apps/content2/schemas/music.sd
@@ -0,0 +1,50 @@
+# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# A basic search definition - called music, should be saved to music.sd
+search music {
+
+ # It contains one document type only - called music as well
+ document music {
+
+ field title type string {
+ indexing: summary | index # How this field should be indexed
+ # index-to: title, default # Create two indexes
+ weight: 75 # Ranking importancy of this field, used by the built in nativeRank feature
+ }
+
+ field artist type string {
+ indexing: summary | attribute | index
+ # index-to: artist, default
+
+ weight: 25
+ }
+
+ field year type int {
+ indexing: summary | attribute
+ }
+
+ # Increase query
+ field popularity type int {
+ indexing: summary | attribute
+ }
+
+ field url type uri {
+ indexing: summary | index
+ }
+
+ }
+
+ rank-profile default inherits default {
+ first-phase {
+ expression: nativeRank(title,artist) + attribute(popularity)
+ }
+
+ }
+
+ rank-profile textmatch inherits default {
+ first-phase {
+ expression: nativeRank(title,artist)
+ }
+
+ }
+
+}
diff --git a/configserver/src/test/apps/content2/services.xml b/configserver/src/test/apps/content2/services.xml
new file mode 100644
index 00000000000..509d7786be0
--- /dev/null
+++ b/configserver/src/test/apps/content2/services.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<services version="1.0">
+
+ <admin version="2.0">
+ <adminserver hostalias="node1"/>
+ <logserver hostalias="node1" />
+ </admin>
+
+ <content version="1.0">
+ <redundancy>2</redundancy>
+ <documents>
+ <document type="music" mode="index"/>
+ </documents>
+ <nodes>
+ <node hostalias="node1" distribution-key="0"/>
+ </nodes>
+
+ </content>
+
+ <container version="1.0">
+ <document-processing compressdocuments="true">
+ <chain id="ContainerWrapperTest">
+ <documentprocessor id="com.yahoo.vespa.config.AppleDocProc"/>
+ </chain>
+ </document-processing>
+
+ <config name="project.specific">
+ <value>someval</value>
+ </config>
+
+ <nodes>
+ <node hostalias="node1" />
+ </nodes>
+
+ </container>
+
+</services>
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java
index 97085416073..8bf5215a696 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java
@@ -1,7 +1,6 @@
// 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.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
@@ -12,6 +11,8 @@ import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.application.OrchestratorMock;
import com.yahoo.vespa.config.server.http.ContentHandlerTestBase;
+import com.yahoo.vespa.config.server.session.LocalSession;
+import com.yahoo.vespa.config.server.session.PrepareParams;
import com.yahoo.vespa.config.server.session.Session;
import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
@@ -30,47 +31,42 @@ import static org.junit.Assert.assertThat;
* @author Ulf Lilleengen
*/
public class ApplicationContentHandlerTest extends ContentHandlerTestBase {
+
+ private static final File testApp = new File("src/test/apps/content");
+ private static final File testApp2 = new File("src/test/apps/content2");
+
private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
private final Clock clock = componentRegistry.getClock();
+ private final TenantName tenantName1 = TenantName.from("mofet");
+ private final TenantName tenantName2 = TenantName.from("bla");
+ private final String baseServer = "http://foo:1337";
+
+ private final ApplicationId appId1 = new ApplicationId.Builder().tenant(tenantName1).applicationName("foo").instanceName("quux").build();
+ private final ApplicationId appId2 = new ApplicationId.Builder().tenant(tenantName2).applicationName("foo").instanceName("quux").build();
+
+ private TenantRepository tenantRepository;
+ private ApplicationRepository applicationRepository;
private ApplicationHandler handler;
- private TenantName tenantName1 = TenantName.from("mofet");
- private TenantName tenantName2 = TenantName.from("bla");
- private String baseServer = "http://foo:1337";
-
- private ApplicationId idTenant1 = new ApplicationId.Builder()
- .tenant(tenantName1)
- .applicationName("foo").instanceName("quux").build();
- private ApplicationId idTenant2 = new ApplicationId.Builder()
- .tenant(tenantName2)
- .applicationName("foo").instanceName("quux").build();
- private MockLocalSession session2;
@Before
public void setupHandler() {
- TenantRepository tenantRepository = new TenantRepository(componentRegistry, false);
+ tenantRepository = new TenantRepository(componentRegistry, false);
tenantRepository.addTenant(tenantName1);
tenantRepository.addTenant(tenantName2);
- session2 = new MockLocalSession(2, FilesApplicationPackage.fromFile(new File("src/test/apps/content")));
- Tenant tenant1 = tenantRepository.getTenant(tenantName1);
- tenant1.getSessionRepository().addLocalSession(session2);
- tenant1.getApplicationRepo().createApplication(idTenant1);
- tenant1.getApplicationRepo().createPutTransaction(idTenant1, 2).commit();
+ applicationRepository = new ApplicationRepository(tenantRepository,
+ new MockProvisioner(),
+ new OrchestratorMock(),
+ clock);
- MockLocalSession session3 = new MockLocalSession(3, FilesApplicationPackage.fromFile(new File("src/test/apps/content2")));
- Tenant tenant2 = tenantRepository.getTenant(tenantName2);
- tenant2.getSessionRepository().addLocalSession(session3);
- tenant2.getApplicationRepo().createApplication(idTenant2);
- tenant2.getApplicationRepo().createPutTransaction(idTenant2, 3).commit();
+ applicationRepository.deploy(testApp, prepareParams(appId1));
+ applicationRepository.deploy(testApp2, prepareParams(appId2));
handler = new ApplicationHandler(ApplicationHandler.testOnlyContext(),
Zone.defaultZone(),
- new ApplicationRepository(tenantRepository,
- new MockProvisioner(),
- new OrchestratorMock(),
- clock));
- pathPrefix = createPath(idTenant1, Zone.defaultZone());
+ applicationRepository);
+ pathPrefix = createPath(appId1, Zone.defaultZone());
baseUrl = baseServer + pathPrefix;
}
@@ -103,16 +99,17 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase {
@Test
public void require_that_multiple_tenants_are_handled() throws IOException {
assertContent("/test.txt", "foo\n");
- pathPrefix = createPath(idTenant2, Zone.defaultZone());
+ pathPrefix = createPath(appId2, Zone.defaultZone());
baseUrl = baseServer + pathPrefix;
assertContent("/test.txt", "bar\n");
}
@Test
public void require_that_get_does_not_set_write_flag() throws IOException {
- session2.status = Session.Status.PREPARE;
+ Tenant tenant1 = tenantRepository.getTenant(tenantName1);
+ LocalSession session = applicationRepository.getActiveLocalSession(tenant1, appId1);
assertContent("/test.txt", "foo\n");
- assertThat(session2.status, is(Session.Status.PREPARE));
+ assertThat(session.getStatus(), is(Session.Status.ACTIVATE));
}
private void assertNotFound(HttpRequest request) {
@@ -126,4 +123,9 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase {
HttpRequest request = HttpRequest.createTestRequest(baseUrl + path, method);
return handler.handle(request);
}
+
+ 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/SessionContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java
index 20d9be080e9..3ab56d3869a 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java
@@ -1,10 +1,11 @@
// 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.model.application.provider.FilesApplicationPackage;
+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.container.jdisc.HttpResponse;
-import com.yahoo.io.IOUtils;
import com.yahoo.jdisc.Response;
import com.yahoo.jdisc.http.HttpRequest;
import com.yahoo.text.Utf8;
@@ -13,6 +14,8 @@ import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.application.OrchestratorMock;
import com.yahoo.vespa.config.server.http.ContentHandlerTestBase;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
+import com.yahoo.vespa.config.server.session.PrepareParams;
+import com.yahoo.vespa.config.server.tenant.Tenant;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import org.junit.Before;
import org.junit.Ignore;
@@ -22,7 +25,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.nio.file.Files;
+import java.time.Clock;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
@@ -32,21 +35,31 @@ import static org.junit.Assert.assertThat;
* @author Ulf Lilleengen
*/
public class SessionContentHandlerTest extends ContentHandlerTestBase {
- private static final TenantName tenant = TenantName.from("contenttest");
+ private static final TenantName tenantName = TenantName.from("contenttest");
+ private static final File testApp = new File("src/test/apps/content");
private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
private TenantRepository tenantRepository;
private SessionContentHandler handler = null;
-
+ private long sessionId;
+
@Before
- public void setupHandler() throws Exception {
+ public void setupHandler() {
tenantRepository = new TenantRepository(componentRegistry, false);
- tenantRepository.addTenant(tenant);
- tenantRepository.getTenant(tenant).getSessionRepository().addLocalSession(new MockLocalSession(1L, FilesApplicationPackage.fromFile(createTestApp())));
+ tenantRepository.addTenant(tenantName);
+
+ ApplicationRepository applicationRepository = new ApplicationRepository(tenantRepository,
+ new SessionHandlerTest.MockProvisioner(),
+ new OrchestratorMock(),
+ Clock.systemUTC());
+ applicationRepository.deploy(testApp, new PrepareParams.Builder().applicationId(applicationId()).build());
+ Tenant tenant = tenantRepository.getTenant(tenantName);
+ sessionId = applicationRepository.getActiveLocalSession(tenant, applicationId()).getSessionId();
+
handler = createHandler();
- pathPrefix = "/application/v2/tenant/" + tenant + "/session/";
- baseUrl = "http://foo:1337/application/v2/tenant/" + tenant + "/session/1/content/";
+ pathPrefix = "/application/v2/tenant/" + tenantName + "/session/";
+ baseUrl = "http://foo:1337/application/v2/tenant/" + tenantName + "/session/" + sessionId + "/content/";
}
@Test
@@ -69,14 +82,14 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
@Test
public void require_that_nonexistent_session_returns_not_found() {
- HttpResponse response = doRequest(HttpRequest.Method.GET, "/test.txt", 2);
+ HttpResponse response = doRequest(HttpRequest.Method.GET, "/test.txt", 9999);
assertNotNull(response);
assertThat(response.getStatus(), is(Response.Status.NOT_FOUND));
}
protected HttpResponse put(String path, String content) {
ByteArrayInputStream data = new ByteArrayInputStream(Utf8.toBytes(content));
- return doRequest(HttpRequest.Method.PUT, path, 1, data);
+ return doRequest(HttpRequest.Method.PUT, path, sessionId, data);
}
@Test
@@ -94,13 +107,13 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
@Test
public void require_that_nonexistent_file_returns_not_found_when_deleted() throws IOException {
- assertDeleteFile(Response.Status.NOT_FOUND, "/test2.txt", "{\"error-code\":\"NOT_FOUND\",\"message\":\"Session 1 does not contain a file 'test2.txt'\"}");
+ assertDeleteFile(Response.Status.NOT_FOUND, "/test2.txt", "{\"error-code\":\"NOT_FOUND\",\"message\":\"Session " + sessionId + " does not contain a file 'test2.txt'\"}");
}
@Test
public void require_that_files_can_be_deleted() throws IOException {
assertDeleteFile(Response.Status.OK, "/test.txt");
- assertDeleteFile(Response.Status.NOT_FOUND, "/test.txt", "{\"error-code\":\"NOT_FOUND\",\"message\":\"Session 1 does not contain a file 'test.txt'\"}");
+ assertDeleteFile(Response.Status.NOT_FOUND, "/test.txt", "{\"error-code\":\"NOT_FOUND\",\"message\":\"Session " + sessionId + " does not contain a file 'test.txt'\"}");
assertDeleteFile(Response.Status.BAD_REQUEST, "/newtest", "{\"error-code\":\"BAD_REQUEST\",\"message\":\"File 'newtest' is not an empty directory\"}");
assertDeleteFile(Response.Status.OK, "/newtest/testfile.txt");
assertDeleteFile(Response.Status.OK, "/newtest");
@@ -109,10 +122,10 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
@Test
public void require_that_status_is_given_for_new_files() throws IOException {
assertStatus("/test.txt?return=status",
- "{\"status\":\"new\",\"md5\":\"d3b07384d113edec49eaa6238ad5ff00\",\"name\":\"http://foo:1337" + pathPrefix + "1/content/test.txt\"}");
+ "{\"status\":\"new\",\"md5\":\"d3b07384d113edec49eaa6238ad5ff00\",\"name\":\"http://foo:1337" + pathPrefix + sessionId + "/content/test.txt\"}");
assertWriteFile("/test.txt", "Mycontent");
assertStatus("/test.txt?return=status",
- "{\"status\":\"changed\",\"md5\":\"01eabd73c69d78d0009ec93cd62d7f77\",\"name\":\"http://foo:1337" + pathPrefix + "1/content/test.txt\"}");
+ "{\"status\":\"changed\",\"md5\":\"01eabd73c69d78d0009ec93cd62d7f77\",\"name\":\"http://foo:1337" + pathPrefix + sessionId + "/content/test.txt\"}");
}
private void assertWriteFile(String path, String content) throws IOException {
@@ -121,11 +134,11 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
assertThat(response.getStatus(), is(Response.Status.OK));
assertContent(path, content);
assertThat(SessionHandlerTest.getRenderedString(response),
- is("{\"prepared\":\"http://foo:1337" + pathPrefix + "1/prepared\"}"));
+ is("{\"prepared\":\"http://foo:1337" + pathPrefix + sessionId + "/prepared\"}"));
}
private void assertDeleteFile(int statusCode, String filePath) throws IOException {
- assertDeleteFile(statusCode, filePath, "{\"prepared\":\"http://foo:1337" + pathPrefix + "1/prepared\"}");
+ assertDeleteFile(statusCode, filePath, "{\"prepared\":\"http://foo:1337" + pathPrefix + sessionId + "/prepared\"}");
}
private void assertDeleteFile(int statusCode, String filePath, String expectedResponse) throws IOException {
@@ -140,17 +153,11 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
assertNotNull(response);
assertThat(response.getStatus(), is(Response.Status.OK));
assertThat(SessionHandlerTest.getRenderedString(response),
- is("{\"prepared\":\"http://foo:1337" + pathPrefix + "1/prepared\"}"));
- }
-
- private File createTestApp() throws IOException {
- File testApp = Files.createTempDirectory("session-content-handler-test-app").toFile();
- IOUtils.copyDirectory(new File("src/test/apps/content"), testApp);
- return testApp;
+ is("{\"prepared\":\"http://foo:1337" + pathPrefix + sessionId + "/prepared\"}"));
}
protected HttpResponse doRequest(HttpRequest.Method method, String path) {
- return doRequest(method, path, 1);
+ return doRequest(method, path, sessionId);
}
private HttpResponse doRequest(HttpRequest.Method method, String path, long sessionId) {
@@ -170,4 +177,9 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase {
componentRegistry.getClock())
);
}
+
+ private ApplicationId applicationId() {
+ return ApplicationId.from(tenantName, ApplicationName.defaultName(), InstanceName.defaultName());
+ }
+
}