From 20cef72bd64f76a4b702702d32d54c7020c2249a Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 17 Oct 2018 11:33:46 +0200 Subject: Allow subset matches --- .../config/application/OverrideProcessor.java | 13 +++--- .../application/HostedOverrideProcessorTest.java | 18 ++++---- .../config/application/OverrideProcessorTest.java | 48 +++++++++++++--------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java b/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java index 16accb368fd..9443339624a 100644 --- a/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java +++ b/config-application-package/src/main/java/com/yahoo/config/application/OverrideProcessor.java @@ -101,18 +101,17 @@ class OverrideProcessor implements PreProcessor { retainMostSpecificEnvironmentAndRegion(parent, children, context); } - /** - * Ensures that environment and region does not change from something non-default to something else. - */ private void checkConsistentInheritance(List children, Context context) { for (Element child : children) { Set environments = getEnvironments(child); Set regions = getRegions(child); - if ( ! environments.isEmpty() && ! context.environments.isEmpty() && !environments.equals(context.environments)) { - throw new IllegalArgumentException("Environments in child (" + environments + ") differs from that inherited from parent (" + context.environments + ") at " + child); + if ( ! environments.isEmpty() && ! context.environments.isEmpty() && ! context.environments.containsAll(environments)) { + throw new IllegalArgumentException("Environments in child (" + environments + + ") are not a subset of those of the parent (" + context.environments + ") at " + child); } - if ( ! regions.isEmpty() && ! context.regions.isEmpty() && ! regions.equals(context.regions)) { - throw new IllegalArgumentException("Regions in child (" + regions + ") differs from that inherited from parent (" + context.regions + ") at " + child); + if ( ! regions.isEmpty() && ! context.regions.isEmpty() && ! context.regions.containsAll(regions)) { + throw new IllegalArgumentException("Regions in child (" + regions + + ") are not a subset of those of the parent (" + context.regions + ") at " + child); } } } diff --git a/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java index d01faaaaea9..4c6a3eb3513 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/HostedOverrideProcessorTest.java @@ -38,7 +38,7 @@ public class HostedOverrideProcessorTest { @Test - public void testParsingDefault() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { + public void testParsingDefault() throws TransformerException { String expected = "" + "" + @@ -50,7 +50,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingEnvironmentAndRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentAndRegion() throws TransformerException { String expected = "" + "" + @@ -62,7 +62,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingEnvironmentAndRegion2() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentAndRegion2() throws TransformerException { String expected = "" + "" + @@ -74,7 +74,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingEnvironmentAndRegion3() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentAndRegion3() throws TransformerException { String expected = "" + "" + @@ -86,7 +86,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentUnknownRegion() throws TransformerException { String expected = "" + "" + @@ -98,7 +98,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingEnvironmentNoRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentNoRegion() throws TransformerException { String expected = "" + "" + @@ -110,7 +110,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingUnknownEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingUnknownEnvironment() throws TransformerException { String expected = "" + "" + @@ -122,7 +122,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingUnknownEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingUnknownEnvironmentUnknownRegion() throws TransformerException { String expected = "" + "" + @@ -134,7 +134,7 @@ public class HostedOverrideProcessorTest { } @Test - public void testParsingInheritEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingInheritEnvironment() throws TransformerException { String expected = "" + "" + diff --git a/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java index 32a1c4f847f..62e6671120b 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/OverrideProcessorTest.java @@ -34,7 +34,7 @@ public class OverrideProcessorTest { " " + " " + " 1" + - " " + + " " + " \n" + " \n" + " \n" + @@ -42,6 +42,10 @@ public class OverrideProcessorTest { " \n" + " \n" + " " + + " " + + " \n" + + " \n" + + " " + " " + " " + " " + @@ -73,7 +77,7 @@ public class OverrideProcessorTest { @Test - public void testParsingDefault() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { + public void testParsingDefault() throws TransformerException { String expected = "" + "" + " " + @@ -82,8 +86,8 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + - " " + + " " + + " " + " " + " " + " " + @@ -101,7 +105,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingEnvironmentAndRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentAndRegion() throws TransformerException { String expected = "" + "" + @@ -133,7 +137,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentUnknownRegion() throws TransformerException { String expected = "" + "" + @@ -143,7 +147,9 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + + " \n" + + " \n" + + " " + " " + " " + " " + @@ -164,7 +170,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingEnvironmentNoRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingEnvironmentNoRegion() throws TransformerException { String expected = "" + "" + @@ -174,7 +180,9 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + + " \n" + + " \n" + + " " + " " + " " + " " + @@ -195,7 +203,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingUnknownEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingDevEnvironment() throws TransformerException { String expected = "" + "" + @@ -205,8 +213,8 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + - " " + + " " + + " " + " " + " " + " " + @@ -224,7 +232,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingUnknownEnvironmentUnknownRegion() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingTestEnvironmentUnknownRegion() throws TransformerException { String expected = "" + "" + @@ -234,8 +242,8 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + - " " + + " " + + " " + " " + " " + " " + @@ -253,7 +261,7 @@ public class OverrideProcessorTest { } @Test - public void testParsingInheritEnvironment() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingInheritEnvironment() throws TransformerException { String expected = "" + "" + @@ -263,8 +271,8 @@ public class OverrideProcessorTest { " " + " 1" + " " + - " " + - " " + + " \n" + + " \n" + " " + " " + // node1 is specified for us-west but does not match because region overrides implies environment=prod @@ -284,7 +292,7 @@ public class OverrideProcessorTest { } @Test(expected = IllegalArgumentException.class) - public void testParsingDifferentEnvInParentAndChild() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingDifferentEnvInParentAndChild() throws TransformerException { String in = "" + "" + " " + @@ -296,7 +304,7 @@ public class OverrideProcessorTest { } @Test(expected = IllegalArgumentException.class) - public void testParsingDifferentRegionInParentAndChild() throws ParserConfigurationException, IOException, SAXException, TransformerException { + public void testParsingDifferentRegionInParentAndChild() throws TransformerException { String in = "" + "" + " " + -- cgit v1.2.3