aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-05-07 16:06:05 +0200
committerTor Egge <Tor.Egge@oath.com>2018-05-08 11:58:22 +0200
commit16d49b3816560b42d1eacdabe834d42730622791 (patch)
tree8f345d0be20b97e2fe1071c18dd965e18e2f6e75 /config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java
parentb4b4c1ecf20f30bd8702657e8377a6d09b92a880 (diff)
Validate that global attribute on document types in a content cluster are
unchanged unless the corresponding override is present.
Diffstat (limited to 'config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java')
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java
new file mode 100644
index 00000000000..5e3b8361c75
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/GlobalDocumentChangeValidatorTest.java
@@ -0,0 +1,65 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.model.application.validation.change;
+
+import com.yahoo.config.model.api.ConfigChangeAction;
+import com.yahoo.config.model.api.ConfigChangeRefeedAction;
+import com.yahoo.vespa.model.VespaModel;
+import com.yahoo.vespa.model.application.validation.ValidationTester;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * Test that global attribute changes are detected by change validator.
+ */
+public class GlobalDocumentChangeValidatorTest {
+
+ @Test
+ public void testChangGlobalAttribute() throws IOException, SAXException {
+ testChangeGlobalAttribute(true, false, false, null);
+ testChangeGlobalAttribute(true, true, true, null);
+ testChangeGlobalAttribute(false, false, true, null);
+ testChangeGlobalAttribute(false, true, false, null);
+ testChangeGlobalAttribute(true, false, true, globalDocumentValidationOverrides);
+ testChangeGlobalAttribute(true, true, false, globalDocumentValidationOverrides);
+ }
+
+ private void testChangeGlobalAttribute(boolean allowed, boolean oldGlobal, boolean newGlobal, String validationOverrides) {
+ ValidationTester tester = new ValidationTester();
+ VespaModel oldModel = tester.deploy(null, getServices(oldGlobal), validationOverrides).getFirst();
+ try {
+ List<ConfigChangeAction> changeActions =
+ tester.deploy(oldModel, getServices(newGlobal), validationOverrides).getSecond();
+ assertTrue(allowed);
+ } catch (IllegalStateException e) {
+ assertFalse(allowed);
+ assertEquals("Document type music in cluster default changed global from " + oldGlobal + " to " + newGlobal,
+ e.getMessage());
+ }
+ }
+ private static final String getServices(boolean isGlobal) {
+ return "<services version='1.0'>" +
+ " <content id='default' version='1.0'>" +
+ " <redundancy>1</redundancy>" +
+ " <documents>" +
+ " <document type='music' mode='index' global='" +
+ isGlobal + "'/>" +
+ " </documents>" +
+ " <nodes count='1'/>" +
+ " </content>" +
+ "</services>";
+ }
+
+ private static final String globalDocumentValidationOverrides =
+ "<validation-overrides>\n" +
+ " <allow until='2000-01-14' comment='test override'>global-document-change</allow>\n" +
+ "</validation-overrides>\n";
+
+}