diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-10-30 17:19:25 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-10-30 17:25:23 +0100 |
commit | b3749fb6b3208062783213a33d6083df3f12181d (patch) | |
tree | 47c3c6206d2ddd67d08964e35f2e20a90c3397ee /configserver/src/test/java/com/yahoo/vespa/config | |
parent | cc23e7060d7b10ca352cf962b01a3b28c35e90e3 (diff) |
Support reindex actions in configserver
The new classes are essentially carbon copies of the equivalent classes for refeed actions.
Diffstat (limited to 'configserver/src/test/java/com/yahoo/vespa/config')
5 files changed, 118 insertions, 4 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 b71d1b99cf0..e45839bc00c 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 @@ -149,6 +149,7 @@ public class ApplicationRepositoryTest { public void prepareAndActivate() { PrepareResult result = prepareAndActivate(testApp); assertTrue(result.configChangeActions().getRefeedActions().isEmpty()); + assertTrue(result.configChangeActions().getReindexActions().isEmpty()); assertTrue(result.configChangeActions().getRestartActions().isEmpty()); Tenant tenant = applicationRepository.getTenant(applicationId()); @@ -164,6 +165,7 @@ public class ApplicationRepositoryTest { Instant deployTime = clock.instant(); PrepareResult result = prepareAndActivate(testApp); assertTrue(result.configChangeActions().getRefeedActions().isEmpty()); + assertTrue(result.configChangeActions().getReindexActions().isEmpty()); assertTrue(result.configChangeActions().getRestartActions().isEmpty()); Tenant tenant = applicationRepository.getTenant(applicationId()); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsBuilder.java b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsBuilder.java index fe3155b251c..b5194432682 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsBuilder.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsBuilder.java @@ -2,14 +2,22 @@ package com.yahoo.vespa.config.server.configchange; import com.google.common.collect.ImmutableMap; +import com.yahoo.config.application.api.ValidationId; +import com.yahoo.config.application.api.ValidationOverrides; import com.yahoo.config.model.api.ConfigChangeAction; import com.yahoo.config.model.api.ServiceInfo; import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.vespa.model.application.validation.change.VespaReindexAction; import com.yahoo.vespa.model.application.validation.change.VespaRestartAction; +import java.time.Instant; import java.util.ArrayList; import java.util.List; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @author geirst */ @@ -44,6 +52,15 @@ public class ConfigChangeActionsBuilder { return this; } + ConfigChangeActionsBuilder reindex(String name, boolean allowed, String message, String documentType, String clusterName, String serviceName) { + List<ServiceInfo> services = List.of(createService(clusterName, "myclustertype", "myservicetype", serviceName)); + ValidationOverrides overrides = mock(ValidationOverrides.class); + when(overrides.allows((String) any(), any())).thenReturn(allowed); + when(overrides.allows((ValidationId) any(), any())).thenReturn(allowed); + actions.add(VespaReindexAction.of(ClusterSpec.Id.from(clusterName), name, overrides, message, services, documentType, Instant.now())); + return this; + } + public ConfigChangeActions build() { return new ConfigChangeActions(actions); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java index c7078bb0703..d145a796725 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ConfigChangeActionsSlimeConverterTest.java @@ -35,6 +35,8 @@ public class ConfigChangeActionsSlimeConverterTest { " \"restart\": [\n" + " ],\n" + " \"refeed\": [\n" + + " ],\n" + + " \"reindex\": [\n" + " ]\n" + " }\n" + "}\n", @@ -76,6 +78,8 @@ public class ConfigChangeActionsSlimeConverterTest { " }\n" + " ],\n" + " \"refeed\": [\n" + + " ],\n" + + " \"reindex\": [\n" + " ]\n" + " }\n" + "}\n", @@ -126,10 +130,47 @@ public class ConfigChangeActionsSlimeConverterTest { " }\n" + " ]\n" + " }\n" + + " ],\n" + + " \"reindex\": [\n" + " ]\n" + " }\n" + "}\n", - toJson(actions)); + toJson(actions)); + } + + @Test + public void json_representation_of_reindex_actions() throws IOException { + ConfigChangeActions actions = new ConfigChangeActionsBuilder(). + reindex(CHANGE_ID, true, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_TYPE).build(); + assertEquals( + "{\n" + + " \"configChangeActions\": {\n" + + " \"restart\": [\n" + + " ],\n" + + " \"refeed\": [\n" + + " ],\n" + + " \"reindex\": [\n" + + " {\n" + + " \"name\": \"change-id\",\n" + + " \"allowed\": true,\n" + + " \"documentType\": \"music\",\n" + + " \"clusterName\": \"foo\",\n" + + " \"messages\": [\n" + + " \"change\"\n" + + " ],\n" + + " \"services\": [\n" + + " {\n" + + " \"serviceName\": \"searchnode\",\n" + + " \"serviceType\": \"myservicetype\",\n" + + " \"configId\": \"myservicetype/searchnode\",\n" + + " \"hostName\": \"hostname\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ]\n" + + " }\n" + + "}\n", + toJson(actions)); } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ReindexActionsFormatterTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ReindexActionsFormatterTest.java new file mode 100644 index 00000000000..e9dd3f3bbfc --- /dev/null +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/configchange/ReindexActionsFormatterTest.java @@ -0,0 +1,53 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.configchange; + +import org.junit.Test; + +import static com.yahoo.vespa.config.server.configchange.Utils.CHANGE_ID; +import static com.yahoo.vespa.config.server.configchange.Utils.CHANGE_ID_2; +import static com.yahoo.vespa.config.server.configchange.Utils.CHANGE_MSG; +import static com.yahoo.vespa.config.server.configchange.Utils.CHANGE_MSG_2; +import static com.yahoo.vespa.config.server.configchange.Utils.CLUSTER; +import static com.yahoo.vespa.config.server.configchange.Utils.DOC_TYPE; +import static com.yahoo.vespa.config.server.configchange.Utils.DOC_TYPE_2; +import static com.yahoo.vespa.config.server.configchange.Utils.SERVICE_NAME; +import static org.junit.Assert.assertEquals; + +/** + * @author bjorncs + */ +public class ReindexActionsFormatterTest { + + @Test + public void formatting_of_single_action() { + ReindexActions actions = new ConfigChangeActionsBuilder(). + reindex(CHANGE_ID, false, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_NAME). + build().getReindexActions(); + assertEquals("change-id: Consider re-indexing document type 'music' in cluster 'foo' because:\n" + + " 1) change\n", + new ReindexActionsFormatter(actions).format()); + } + + @Test + public void formatting_of_multiple_actions() { + ReindexActions actions = new ConfigChangeActionsBuilder(). + reindex(CHANGE_ID, false, CHANGE_MSG, DOC_TYPE, CLUSTER, SERVICE_NAME). + reindex(CHANGE_ID, false, CHANGE_MSG_2, DOC_TYPE, CLUSTER, SERVICE_NAME). + reindex(CHANGE_ID_2, false, CHANGE_MSG_2, DOC_TYPE, CLUSTER, SERVICE_NAME). + reindex(CHANGE_ID_2, true, CHANGE_MSG_2, DOC_TYPE, CLUSTER, SERVICE_NAME). + reindex(CHANGE_ID, false, CHANGE_MSG_2, DOC_TYPE_2, CLUSTER, SERVICE_NAME). + build().getReindexActions(); + assertEquals("change-id: Consider re-indexing document type 'book' in cluster 'foo' because:\n" + + " 1) other change\n" + + "change-id: Consider re-indexing document type 'music' in cluster 'foo' because:\n" + + " 1) change\n" + + " 2) other change\n" + + "other-change-id: Consider re-indexing document type 'music' in cluster 'foo' because:\n" + + " 1) other change\n" + + "(allowed) other-change-id: Consider re-indexing document type 'music' in cluster 'foo' because:\n" + + " 1) other change\n", + new ReindexActionsFormatter(actions).format()); + } + + +} diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java index 3af408b90f6..d24faa1b433 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java @@ -234,15 +234,16 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { public void require_that_config_change_actions_are_in_response() throws Exception { long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, app); HttpResponse response = request(HttpRequest.Method.PUT, sessionId); - assertResponseContains(response, "\"configChangeActions\":{\"restart\":[],\"refeed\":[]}"); + assertResponseContains(response, "\"configChangeActions\":{\"restart\":[],\"refeed\":[],\"reindex\":[]}"); } @Test public void require_that_config_change_actions_are_not_logged_if_not_existing() throws Exception { long sessionId = applicationRepository.createSession(applicationId(), timeoutBudget, app); HttpResponse response = request(HttpRequest.Method.PUT, sessionId); - assertResponseNotContains(response, "Change(s) between active and new application that require restart"); - assertResponseNotContains(response, "Change(s) between active and new application that require re-feed"); + assertResponseNotContains(response, "Change(s) between active and new application that may require restart"); + assertResponseNotContains(response, "Change(s) between active and new application that may require re-feed"); + assertResponseNotContains(response, "Change(s) between active and new application that may require re-index"); } @Test |