summaryrefslogtreecommitdiffstats
path: root/configserver/src
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-07-02 14:35:29 +0200
committerHarald Musum <musum@verizonmedia.com>2020-07-02 14:35:29 +0200
commit247db8199c5e6ac6a5c63d73f064b465b918f18d (patch)
tree4295f77aa1485b18a21ec720360b8c7a318e9d45 /configserver/src
parenta6ca420bef2c7b7f43afc541d62c889dbac69c06 (diff)
Simplify tests, stop using low-level code to setup handlers
Diffstat (limited to 'configserver/src')
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/TestConfigDefinitionRepo.java3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java99
2 files changed, 58 insertions, 44 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/TestConfigDefinitionRepo.java b/configserver/src/test/java/com/yahoo/vespa/config/server/TestConfigDefinitionRepo.java
index 5878b250bc8..ea093542354 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/TestConfigDefinitionRepo.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/TestConfigDefinitionRepo.java
@@ -15,7 +15,9 @@ import java.util.Map;
* @author Ulf Lilleengen
*/
public class TestConfigDefinitionRepo implements ConfigDefinitionRepo {
+
private final Map<ConfigDefinitionKey, ConfigDefinition> repo = new LinkedHashMap<>();
+
public TestConfigDefinitionRepo() {
repo.put(new ConfigDefinitionKey(SimpletypesConfig.CONFIG_DEF_NAME, SimpletypesConfig.CONFIG_DEF_NAMESPACE),
new ConfigDefinition(SimpletypesConfig.CONFIG_DEF_NAME, SimpletypesConfig.CONFIG_DEF_SCHEMA));
@@ -32,4 +34,5 @@ public class TestConfigDefinitionRepo implements ConfigDefinitionRepo {
@Override
public ConfigDefinition get(ConfigDefinitionKey key) { return null; }
+
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
index 97789caeb4b..4ec75ce04ba 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
@@ -1,27 +1,32 @@
// 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.SimpletypesConfig;
+import com.yahoo.cloud.config.ConfigserverConfig;
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.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
-import com.yahoo.vespa.config.ConfigKey;
-import com.yahoo.vespa.config.ConfigPayload;
-import com.yahoo.vespa.config.protocol.SlimeConfigResponse;
+import com.yahoo.vespa.config.server.ApplicationRepository;
import com.yahoo.vespa.config.server.TestComponentRegistry;
+import com.yahoo.vespa.config.server.TestConfigDefinitionRepo;
+import com.yahoo.vespa.config.server.application.OrchestratorMock;
import com.yahoo.vespa.config.server.http.HandlerTest;
import com.yahoo.vespa.config.server.http.HttpConfigRequest;
import com.yahoo.vespa.config.server.http.HttpErrorResponse;
import com.yahoo.vespa.config.server.http.SessionHandlerTest;
-import com.yahoo.vespa.config.server.rpc.MockRequestHandler;
+import com.yahoo.vespa.config.server.session.PrepareParams;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import java.io.File;
import java.io.IOException;
+import java.time.Clock;
import java.util.Collections;
-import java.util.HashSet;
import static com.yahoo.jdisc.Response.Status.BAD_REQUEST;
import static com.yahoo.jdisc.Response.Status.NOT_FOUND;
@@ -34,51 +39,56 @@ import static org.junit.Assert.assertTrue;
public class HttpGetConfigHandlerTest {
private static final TenantName tenant = TenantName.from("mytenant");
- private static final String EXPECTED_RENDERED_STRING = "{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}";
- private static final String configUri = "http://yahoo.com:8080/config/v2/tenant/" + tenant.value() + "/application/myapplication/foo.bar/myid";
- private MockRequestHandler mockRequestHandler;
+ private static final ApplicationName applicationName = ApplicationName.from("myapplication");
+ private static final String expected =
+ "{\"port\":{\"telnet\":19098,\"rpc\":19097},\"application\":{\"tenant\":\"mytenant\",\"name\":\"myapplication\"";
+ private static final String baseUri = "http://yahoo.com:8080/config/v2/tenant/mytenant/application/myapplication/";
+ private static final String configUri = baseUri + "cloud.config.sentinel/hosts/localhost/sentinel";
+ private final static File testApp = new File("src/test/resources/deploy/validapp");
+ private static final ApplicationId applicationId = ApplicationId.from(tenant, applicationName, InstanceName.defaultName());
+
private HttpGetConfigHandler handler;
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
@Before
- public void setUp() {
- mockRequestHandler = new MockRequestHandler(ApplicationId.defaultId());
- mockRequestHandler.setAllConfigs(new HashSet<>() {{
- add(new ConfigKey<>("bar", "myid", "foo"));
- }} );
- TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
- TenantRepository tenantRepository = new TenantRepository(componentRegistry, false);
- tenantRepository.addTenant(tenant, mockRequestHandler, mockRequestHandler);
+ public void setUp() throws IOException {
+ TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder()
+ .configDefinitionRepo(new TestConfigDefinitionRepo())
+ .configServerConfig(new ConfigserverConfig.Builder()
+ .configServerDBDir(temporaryFolder.newFolder().getAbsolutePath())
+ .configDefinitionsDir(temporaryFolder.newFolder().getAbsolutePath())
+ .build())
+ .build();
+ TenantRepository tenantRepository = new TenantRepository(componentRegistry);
+ tenantRepository.addTenant(tenant);
+ ApplicationRepository applicationRepository =
+ new ApplicationRepository(tenantRepository,
+ new SessionHandlerTest.MockProvisioner(),
+ new OrchestratorMock(),
+ Clock.systemUTC());
handler = new HttpGetConfigHandler(HttpGetConfigHandler.testOnlyContext(), tenantRepository);
+ applicationRepository.deploy(testApp, prepareParams());
}
@Test
public void require_that_handler_can_be_created() throws IOException {
- // Define config response for mock handler
- final long generation = 1L;
- ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
- mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(),
- SlimeConfigResponse.fromConfigPayload(payload, generation, false, "mymd5"));
HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
- assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
+ assertTrue(SessionHandlerTest.getRenderedString(response).startsWith(expected));
}
@Test
public void require_that_handler_can_handle_long_appid_request_with_configid() throws IOException {
- String uriLongAppId = "http://yahoo.com:8080/config/v2/tenant/" + tenant.value() +
- "/application/myapplication/environment/staging/region/myregion/instance/myinstance/foo.bar/myid";
- final long generation = 1L;
- ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
- mockRequestHandler.responses.put(new ApplicationId.Builder()
- .tenant(tenant)
- .applicationName("myapplication").instanceName("myinstance").build(),
- SlimeConfigResponse.fromConfigPayload(payload, generation, false, "mymd5"));
- HttpResponse response = handler.handle(HttpRequest.createTestRequest(uriLongAppId, GET));
- assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
+ String configUri = baseUri + "/environment/staging/region/myregion/instance/default/cloud.config.sentinel/hosts/localhost/sentinel";
+ HttpResponse response = handler.handle(HttpRequest.createTestRequest(configUri, GET));
+ String renderedString = SessionHandlerTest.getRenderedString(response);
+ assertTrue(renderedString, renderedString.startsWith(expected));
}
@Test
public void require_that_request_gets_correct_fields_with_full_appid() {
- String uriLongAppId = "http://yahoo.com:8080/config/v2/tenant/bill/application/sookie/environment/dev/region/bellefleur/instance/sam/foo.bar/myid";
+ String uriLongAppId = "http://foo.com:8080/config/v2/tenant/bill/application/sookie/environment/dev/region/bellefleur/instance/sam/foo.bar/myid";
HttpRequest r = HttpRequest.createTestRequest(uriLongAppId, GET);
HttpConfigRequest req = HttpConfigRequest.createFromRequestV2(r);
assertThat(req.getApplicationId().tenant().value(), is("bill"));
@@ -88,7 +98,7 @@ public class HttpGetConfigHandlerTest {
@Test
public void require_that_request_gets_correct_fields_with_short_appid() {
- String uriShortAppId = "http://yahoo.com:8080/config/v2/tenant/jason/application/alcide/foo.bar/myid";
+ String uriShortAppId = "http://foo.com:8080/config/v2/tenant/jason/application/alcide/foo.bar/myid";
HttpRequest r = HttpRequest.createTestRequest(uriShortAppId, GET);
HttpConfigRequest req = HttpConfigRequest.createFromRequestV2(r);
assertThat(req.getApplicationId().tenant().value(), is("jason"));
@@ -98,9 +108,9 @@ public class HttpGetConfigHandlerTest {
@Test
public void require_correct_error_response() throws IOException {
- final String nonExistingConfigNameUri = "http://yahoo.com:8080/config/v2/tenant/mytenant/application/myapplication/nonexisting.config/myid";
- final String nonExistingConfigUri = "http://yahoo.com:8080/config/v2/tenant/mytenant/application/myapplication//foo.bar/myid/nonexisting/id";
- final String illegalConfigNameUri = "http://yahoo.com:8080/config/v2/tenant/mytenant/application/myapplication//foobar/myid";
+ String nonExistingConfigNameUri = baseUri + "nonexisting.config/myid";
+ String nonExistingConfigUri = baseUri + "cloud.config.sentinel/myid/nonexisting/id";
+ String illegalConfigNameUri = baseUri + "/foobar/myid";
HttpResponse response = handler.handle(HttpRequest.createTestRequest(nonExistingConfigNameUri, GET));
HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, NOT_FOUND, HttpErrorResponse.errorCodes.NOT_FOUND, "No such config: nonexisting.config");
@@ -115,13 +125,14 @@ public class HttpGetConfigHandlerTest {
@Test
public void require_that_nocache_property_works() throws IOException {
- long generation = 1L;
- ConfigPayload payload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
- mockRequestHandler.responses.put(new ApplicationId.Builder().tenant(tenant).applicationName("myapplication").build(),
- SlimeConfigResponse.fromConfigPayload(payload, generation, false, "mymd5"));
- final HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
+ HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
HttpResponse response = handler.handle(request);
- assertThat(SessionHandlerTest.getRenderedString(response), is(EXPECTED_RENDERED_STRING));
+ String renderedString = SessionHandlerTest.getRenderedString(response);
+ assertTrue(renderedString, renderedString.startsWith(expected));
+ }
+
+ private PrepareParams prepareParams() {
+ return new PrepareParams.Builder().applicationId(applicationId).build();
}
}