diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-02-19 11:52:26 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2023-02-19 11:52:26 +0100 |
commit | 9d9826112b6ab3a48f79a8d1346587a7cbbbe39b (patch) | |
tree | 3c95f4973f79da93901d0fe12d90218929f15012 /config-model-api/src/test/java | |
parent | 665da0c90fc7d9a26d4307d24840267d809147e6 (diff) |
Complete bcp handling
- Add bcp to schema validation
- Read endpoints defined in bcp elements
Diffstat (limited to 'config-model-api/src/test/java')
2 files changed, 169 insertions, 8 deletions
diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java index afa7e3e502b..89b7318739e 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecTest.java @@ -1294,22 +1294,22 @@ public class DeploymentSpecTest { @Test public void invalidEndpoints() { assertInvalidEndpoints("<endpoint id='FOO' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'FOO'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'FOO'"); assertInvalidEndpoints("<endpoint id='123' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got '123'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got '123'"); assertInvalidEndpoints("<endpoint id='foo!' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo!'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo!'"); assertInvalidEndpoints("<endpoint id='foo.bar' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo.bar'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo.bar'"); assertInvalidEndpoints("<endpoint id='foo--bar' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo--bar'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo--bar'"); assertInvalidEndpoints("<endpoint id='foo-' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo-'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foo-'"); assertInvalidEndpoints("<endpoint id='foooooooooooo' container-id='qrs'/>", - "Endpoint ID must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foooooooooooo'"); + "Endpoint id must be all lowercase, alphanumeric, with no consecutive dashes, of length 1 to 12, and begin with a character; but got 'foooooooooooo'"); assertInvalidEndpoints("<endpoint id='foo' container-id='qrs'/><endpoint id='foo' container-id='qrs'/>", - "Endpoint ID 'foo' is specified multiple times"); + "Endpoint id 'foo' is specified multiple times"); assertInvalidEndpoints("<endpoint id='default' type='zone' container-id='foo' />", "Instance-level endpoint 'default': cannot declare 'id' with type 'zone' or 'private'"); assertInvalidEndpoints("<endpoint id='default' type='private' container-id='foo' />", diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithBcpTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithBcpTest.java index 77aadc88be8..e1ff8f012bd 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithBcpTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/DeploymentSpecWithBcpTest.java @@ -6,6 +6,7 @@ import org.junit.Test; import java.io.StringReader; import java.time.Duration; +import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -100,7 +101,9 @@ public class DeploymentSpecWithBcpTest { </bcp> </deployment> """); + var spec = DeploymentSpec.fromXml(r); + var betaBcp = spec.requireInstance("beta").bcp().orElse(spec.bcp()); assertEquals(1, betaBcp.groups().size()); var betaGroup = betaBcp.groups().get(0); @@ -241,6 +244,164 @@ public class DeploymentSpecWithBcpTest { } } + @Test + public void endpointsDefinedInBcp() { + StringReader r = new StringReader(""" + <deployment version='1.0'> + <instance id='beta'> + <prod> + <region>us-east1</region> + <region>us-east2</region> + </prod> + <bcp> + <group> + <endpoint id="foo" container-id="bar"/> + <region>us-east1</region> + <region>us-east2</region> + </group> + </bcp> + </instance> + <instance id='main'> + <prod> + <region>us-east1</region> + <region>us-east2</region> + <region>us-central1</region> + <region>us-west1</region> + <region>us-west2</region> + </prod> + <bcp> + <group> + <endpoint id="east" container-id="bar"/> + <region>us-east1</region> + <region>us-east2</region> + <region fraction="0.3">us-central1</region> + </group> + <group> + <endpoint id="west" container-id="bar"/> + <region>us-west1</region> + <region>us-west2</region> + <region fraction="0.7">us-central1</region> + </group> + </bcp> + </instance> + </deployment> + """); + + var spec = DeploymentSpec.fromXml(r); + + var betaEndpoints = spec.requireInstance("beta").endpoints(); + assertEquals(1, betaEndpoints.size()); + assertEquals("foo", betaEndpoints.get(0).endpointId()); + assertEquals("bar", betaEndpoints.get(0).containerId()); + assertEquals(List.of(RegionName.from("us-east1"), RegionName.from("us-east2")), + betaEndpoints.get(0).regions()); + + var mainEndpoints = spec.requireInstance("main").endpoints(); + assertEquals(2, mainEndpoints.size()); + assertEquals("east", mainEndpoints.get(0).endpointId()); + assertEquals(List.of(RegionName.from("us-east1"), RegionName.from("us-east2"), RegionName.from("us-central1")), + mainEndpoints.get(0).regions()); + assertEquals("west", mainEndpoints.get(1).endpointId()); + assertEquals(List.of(RegionName.from("us-west1"), RegionName.from("us-west2"), RegionName.from("us-central1")), + mainEndpoints.get(1).regions()); + } + + @Test + public void endpointsDefinedInBcpImplicitInstance() { + StringReader r = new StringReader(""" + <deployment version='1.0'> + <prod> + <region>us-east1</region> + <region>us-east2</region> + <region>us-central1</region> + <region>us-west1</region> + <region>us-west2</region> + </prod> + <bcp> + <group> + <endpoint id="east" container-id="bar"/> + <region>us-east1</region> + <region>us-east2</region> + <region fraction="0.3">us-central1</region> + </group> + <group> + <endpoint id="west" container-id="bar"/> + <region>us-west1</region> + <region>us-west2</region> + <region fraction="0.7">us-central1</region> + </group> + </bcp> + </deployment> + """); + + var spec = DeploymentSpec.fromXml(r); + + var mainEndpoints = spec.requireInstance("default").endpoints(); + assertEquals(2, mainEndpoints.size()); + assertEquals("east", mainEndpoints.get(0).endpointId()); + assertEquals(List.of(RegionName.from("us-east1"), RegionName.from("us-east2"), RegionName.from("us-central1")), + mainEndpoints.get(0).regions()); + assertEquals("west", mainEndpoints.get(1).endpointId()); + assertEquals(List.of(RegionName.from("us-west1"), RegionName.from("us-west2"), RegionName.from("us-central1")), + mainEndpoints.get(1).regions()); + } + + @Test + public void endpontsDefinedInBcpValidation1() { + StringReader r = new StringReader(""" + <deployment version='1.0'> + <instance id='beta'> + <prod> + <region>us-east1</region> + <region>us-east2</region> + </prod> + </instance> + <bcp> + <group> + <endpoint id="foo" container-id="bar"/> + <region>us-east1</region> + <region>us-east2</region> + </group> + </bcp> + </deployment> + """); + try { + DeploymentSpec.fromXml(r); + } + catch (IllegalArgumentException e) { + assertEquals("The default <bcp> element at the root cannot define endpoints", Exceptions.toMessageString(e)); + } + } + + @Test + public void endpontsDefinedInBcpValidation2() { + StringReader r = new StringReader(""" + <deployment version='1.0'> + <instance id='beta'> + <prod> + <region>us-east1</region> + <region>us-east2</region> + </prod> + <bcp> + <group> + <region>us-east1</region> + <region>us-east2</region> + <endpoint id="foo" container-id="bar"> + <region>us-east1</region> + </endpoint> + </group> + </bcp> + </instance> + </deployment> + """); + try { + DeploymentSpec.fromXml(r); + } + catch (IllegalArgumentException e) { + assertEquals("Endpoints in <group> cannot contain <region> children", Exceptions.toMessageString(e)); + } + + } private void assertTwoRegions(DeploymentSpec spec) { var bcp = spec.requireInstance("default").bcp().orElse(spec.bcp()); assertEquals(1, bcp.groups().size()); |