diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-06-01 13:52:17 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-06-01 13:52:17 +0200 |
commit | 15f1b04fa8afc3b632a3a3c6dee560f487cfb8c6 (patch) | |
tree | d11befca8a5768970d93ce1f2e131e9eebe1fc3d /configserver | |
parent | 6a48337dddea59910c0abd8bab3539bfc91fde88 (diff) |
Test internalRedeploy from ApplicationMetaData -> ConfigResponse
Diffstat (limited to 'configserver')
5 files changed, 53 insertions, 31 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployer.java index 22ce952481d..68c129d1e42 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/deploy/ZooKeeperDeployer.java @@ -13,7 +13,7 @@ import java.util.Map; * Interface for initializing zookeeper and deploying an application package to zookeeper. * Initialize must be called before each deploy. * - * @author lulf + * @author Ulf Lilleengen */ public class ZooKeeperDeployer { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantHandlerProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantHandlerProvider.java index 8c774fd35ce..b19f8bf8d0b 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantHandlerProvider.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantHandlerProvider.java @@ -7,8 +7,7 @@ import com.yahoo.vespa.config.server.RequestHandler; /** * Represents something that can provide request and reload handlers of a tenant. * - * @author lulf - * @since 5.3 + * @author Ulf Lilleengen */ public interface TenantHandlerProvider { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRequestHandler.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRequestHandler.java index 62ff13093ea..ebdee8f58e5 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRequestHandler.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/MockRequestHandler.java @@ -15,15 +15,15 @@ import java.util.*; /** * Test utility class - * @author lulf - * @since 5.25 + * + * @author Ulf Lilleengen */ public class MockRequestHandler implements RequestHandler, ReloadHandler, TenantHandlerProvider { volatile boolean throwException = false; private Set<ConfigKey<?>> allConfigs = new HashSet<>(); public volatile ConfigResponse responseConfig = null; // for some v1 mocking - public Map<ApplicationId, ConfigResponse> responses = new LinkedHashMap<>(); // for v2 mocking + public Map<ApplicationId, ConfigResponse> responses = new LinkedHashMap<>(); // for v3 mocking private final boolean pretendToHaveLoadedAnyApplication; public MockRequestHandler() { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/MockTenantProvider.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/MockTenantProvider.java index 77505006b77..4d01f8a609d 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/MockTenantProvider.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/MockTenantProvider.java @@ -7,8 +7,7 @@ import com.yahoo.vespa.config.server.ReloadHandler; import com.yahoo.vespa.config.server.RequestHandler; /** - * @author lulf - * @since 5. + * @author Ulf Lilleengen */ public class MockTenantProvider implements TenantHandlerProvider { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java index 27ae0945b4a..cecbab2d9ec 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRequestHandlerTest.java @@ -3,8 +3,10 @@ package com.yahoo.vespa.config.server.tenant; import com.yahoo.config.ConfigInstance; import com.yahoo.config.SimpletypesConfig; +import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.config.model.application.provider.BaseDeployLogger; +import com.yahoo.config.model.application.provider.DeployData; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.provision.ApplicationName; @@ -69,9 +71,13 @@ public class TenantRequestHandlerTest extends TestWithCurator { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); + private ApplicationId defaultApp() { + return new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(tenant).build(); + } + @Before - public void setUp() throws IOException, SAXException { - feedApp(app1, 1); + public void setUp() throws IOException { + feedApp(app1, 1, defaultApp(), false); Metrics sh = Metrics.createTestMetrics(); List<ReloadListener> listeners = new ArrayList<>(); listeners.add(listener); @@ -79,11 +85,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { componentRegistry = new TestComponentRegistry.Builder().curator(curator).modelFactoryRegistry(createRegistry()).build(); } - private void feedApp(File appDir, long sessionId) throws IOException { - feedApp(appDir, sessionId, new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(tenant).build()); - } - - private void feedApp(File appDir, long sessionId, ApplicationId appId) throws IOException { + private void feedApp(File appDir, long sessionId, ApplicationId appId, boolean internalRedeploy) throws IOException { SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, configCurator, TenantRepository.getSessionsPath(tenant).append(String.valueOf(sessionId)), new TestConfigDefinitionRepo(), @@ -92,7 +94,17 @@ public class TenantRequestHandlerTest extends TestWithCurator { File app = tempFolder.newFolder(); IOUtils.copyDirectory(appDir, app); ZooKeeperDeployer deployer = zkc.createDeployer(new BaseDeployLogger()); - deployer.deploy(FilesApplicationPackage.fromFile(appDir), Collections.singletonMap(vespaVersion, new MockFileRegistry()), AllocatedHosts.withHosts(Collections.emptySet())); + DeployData deployData = new DeployData("user", + appDir.toString(), + appId.application().toString(), + 0L, + internalRedeploy, + 0L, + 0L); + ApplicationPackage appPackage = FilesApplicationPackage.fromFileWithDeployData(appDir, deployData); + deployer.deploy(appPackage, + Collections.singletonMap(vespaVersion, new MockFileRegistry()), + AllocatedHosts.withHosts(Collections.emptySet())); } private ApplicationSet reloadConfig(long id, Clock clock) { @@ -114,12 +126,21 @@ public class TenantRequestHandlerTest extends TestWithCurator { new TestModelFactory(Version.fromIntValues(3, 2, 1)))); } - public <T extends ConfigInstance> T resolve(Class<T> clazz, TenantRequestHandler tenantRequestHandler, String configId) { - return resolve(clazz, tenantRequestHandler, new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(tenant).build(), vespaVersion, configId); + public <T extends ConfigInstance> T resolve(Class<T> clazz, + TenantRequestHandler tenantRequestHandler, + ApplicationId appId, + Version vespaVersion, + String configId) { + ConfigResponse response = getConfigResponse(clazz, tenantRequestHandler, appId, vespaVersion, configId); + return ConfigPayload.fromUtf8Array(response.getPayload()).toInstance(clazz, configId); } - public <T extends ConfigInstance> T resolve(final Class<T> clazz, TenantRequestHandler tenantRequestHandler, ApplicationId appId, Version vespaVersion, final String configId) { - ConfigResponse response = tenantRequestHandler.resolveConfig(appId, new GetConfigRequest() { + public <T extends ConfigInstance> ConfigResponse getConfigResponse(Class<T> clazz, + TenantRequestHandler tenantRequestHandler, + ApplicationId appId, + Version vespaVersion, + String configId) { + return tenantRequestHandler.resolveConfig(appId, new GetConfigRequest() { @Override public ConfigKey<T> getConfigKey() { return new ConfigKey<T>(clazz, configId); @@ -140,23 +161,24 @@ public class TenantRequestHandlerTest extends TestWithCurator { return false; } }, Optional.empty()); - return ConfigPayload.fromUtf8Array(response.getPayload()).toInstance(clazz, configId); } @Test - public void testReloadConfig() throws IOException, SAXException { + public void testReloadConfig() throws IOException { Clock clock = Clock.systemUTC(); ApplicationId applicationId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(tenant).build(); server.reloadConfig(reloadConfig(1, clock)); assertThat(listener.reloaded.get(), is(1)); // Using only payload list for this simple test - SimpletypesConfig config = resolve(SimpletypesConfig.class, server, ""); + SimpletypesConfig config = resolve(SimpletypesConfig.class, server, defaultApp(), vespaVersion, ""); assertThat(config.intval(), is(1337)); assertThat(server.getApplicationGeneration(applicationId, Optional.of(vespaVersion)), is(1l)); - server.reloadConfig(reloadConfig(1l, clock)); - config = resolve(SimpletypesConfig.class, server, ""); + server.reloadConfig(reloadConfig(1L, clock)); + ConfigResponse configResponse = getConfigResponse(SimpletypesConfig.class, server, defaultApp(), vespaVersion, ""); + assertFalse(configResponse.isInternalRedeploy()); + config = resolve(SimpletypesConfig.class, server, defaultApp(), vespaVersion, ""); assertThat(config.intval(), is(1337)); assertThat(listener.reloaded.get(), is(2)); assertThat(server.getApplicationGeneration(applicationId, Optional.of(vespaVersion)), is(1l)); @@ -164,9 +186,11 @@ public class TenantRequestHandlerTest extends TestWithCurator { assertThat(server.resolveApplicationId("mytesthost"), is(applicationId)); listener.reloaded.set(0); - feedApp(app2, 2); - server.reloadConfig(reloadConfig(2l, clock)); - config = resolve(SimpletypesConfig.class, server, ""); + feedApp(app2, 2, defaultApp(), true); + server.reloadConfig(reloadConfig(2L, clock)); + configResponse = getConfigResponse(SimpletypesConfig.class, server, defaultApp(), vespaVersion, ""); + assertTrue(configResponse.isInternalRedeploy()); + config = resolve(SimpletypesConfig.class, server, defaultApp(), vespaVersion,""); assertThat(config.intval(), is(1330)); assertThat(listener.reloaded.get(), is(1)); assertThat(server.getApplicationGeneration(applicationId, Optional.of(vespaVersion)), is(2l)); @@ -182,7 +206,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { @Test public void testResolveForAppId() { - long id = 1l; + long id = 1L; SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, configCurator, TenantRepository.getSessionsPath(tenant).append(String.valueOf(id)), new TestConfigDefinitionRepo(), @@ -198,7 +222,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { } @Test - public void testResolveMultipleApps() throws IOException, SAXException { + public void testResolveMultipleApps() throws IOException { ApplicationId appId1 = new ApplicationId.Builder() .tenant(tenant) .applicationName("myapp1").instanceName("myinst1").build(); @@ -227,7 +251,7 @@ public class TenantRequestHandlerTest extends TestWithCurator { } private void feedAndReloadApp(File appDir, long sessionId, ApplicationId appId) throws IOException { - feedApp(appDir, sessionId, appId); + feedApp(appDir, sessionId, appId, false); SessionZooKeeperClient zkc = new SessionZooKeeperClient(curator, TenantRepository.getSessionsPath(tenant).append(String.valueOf(sessionId))); zkc.writeApplicationId(appId); RemoteSession session = new RemoteSession(tenant, sessionId, componentRegistry, zkc, Clock.systemUTC()); |