diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-04-26 14:18:48 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-04-29 13:11:37 +0200 |
commit | 555d63309ff1a798ab093ecdb91d00665ed3c7b0 (patch) | |
tree | ff7ddbb8399a8138ae04579768bcb7119e0f93fc /controller-server/src/test/java | |
parent | c9f9f467df69a65fe1a403f58411259e3c0fa823 (diff) |
Add persistent queue for name service requests
Diffstat (limited to 'controller-server/src/test/java')
3 files changed, 147 insertions, 9 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java new file mode 100644 index 00000000000..d0362ae98b8 --- /dev/null +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/dns/NameServiceQueueTest.java @@ -0,0 +1,86 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.dns; + +import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.dns.AliasTarget; +import com.yahoo.vespa.hosted.controller.api.integration.dns.MemoryNameService; +import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; +import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData; +import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName; +import com.yahoo.vespa.hosted.controller.dns.NameServiceQueue.Priority; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +/** + * @author mpolden + */ +public class NameServiceQueueTest { + + @Test + public void test_queue() { + var nameService = new MemoryNameService(); + var r1 = new Record(Record.Type.CNAME, RecordName.from("cname.vespa.oath.cloud"), RecordData.from("example.com")); + var r2 = new Record(Record.Type.TXT, RecordName.from("txt.example.com"), RecordData.from("text")); + var r3 = List.of(new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), RecordData.from("alias1/dns-zone-01/prod.us-north-1")), + new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), RecordData.from("alias2/dns-zone-02/prod.us-north-2"))); + var req1 = new CreateRecord(r1); + var req2 = new CreateRecords(List.of(r2)); + var req3 = new CreateRecords(List.of(new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), + new AliasTarget(HostName.from("alias1"), + "dns-zone-01", + ZoneId.from("prod", "us-north-1")).asData()), + new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), + new AliasTarget(HostName.from("alias2"), + "dns-zone-02", + ZoneId.from("prod", "us-north-2")).asData())) + ); + var req4 = new RemoveRecords(r3.get(0).type(), r3.get(0).name()); + var req5 = new RemoveRecords(r2.type(), r2.data()); + var req6 = new RemoveRecords(Record.Type.CNAME, r1.data()); + + // Add requests with different priorities and dispatch first one + var queue = NameServiceQueue.EMPTY.with(req2).with(req1, Priority.high); + assertEquals(2, queue.requests().size()); + queue = queue.dispatchTo(nameService, 1); + assertEquals(r1, nameService.findRecords(r1.type(), r1.name()).get(0)); + assertEquals(1, queue.requests().size()); + assertEquals(req2, queue.requests().iterator().next()); + + // Dispatch remaining requests + queue = queue.dispatchTo(nameService, 10); + assertTrue(queue.requests().isEmpty()); + assertEquals(r2, nameService.findRecords(r2.type(), r2.name()).get(0)); + + // Dispatch from empty queue + assertSame(queue, queue.dispatchTo(nameService, 10)); + + // Dispatch create alias + queue = queue.with(req3).dispatchTo(nameService, 1); + assertEquals(r3, nameService.findRecords(Record.Type.ALIAS, r3.get(0).name())); + + // Dispatch removals + queue = queue.with(req4).with(req5).dispatchTo(nameService, 2); + assertTrue("Removed " + r2, nameService.findRecords(r2.type(), r2.name()).isEmpty()); + assertTrue("Removed " + r3, nameService.findRecords(Record.Type.ALIAS, r3.get(0).name()).isEmpty()); + + // Dispatch removals by data + queue = queue.with(req6).dispatchTo(nameService, 1); + assertTrue(queue.requests().isEmpty()); + assertTrue("Removed " + r1, nameService.findRecords(Record.Type.CNAME, r1.name()).isEmpty()); + + // Keep n most recent requests + queue = queue.with(req1).with(req2).with(req3).with(req4).with(req6) + .last(2); + assertEquals(List.of(req4, req6), List.copyOf(queue.requests())); + assertSame(queue, queue.last(2)); + assertSame(queue, queue.last(10)); + assertTrue(queue.last(0).requests().isEmpty()); + } + +} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicyMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicyMaintainerTest.java index b0f64eee532..8d1c3949201 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicyMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RoutingPolicyMaintainerTest.java @@ -67,10 +67,10 @@ public class RoutingPolicyMaintainerTest { Supplier<List<Record>> records2 = () -> tester.controllerTester().nameService().findRecords(Record.Type.ALIAS, RecordName.from("r1.app1.tenant1.global.vespa.oath.cloud")); assertEquals(2, records1.get().size()); assertEquals(records1.get().size(), records2.get().size()); - assertEquals("lb-0--tenant1:app1:default--prod.us-central-1.", records1.get().get(0).data().asString()); - assertEquals("lb-0--tenant1:app1:default--prod.us-west-1.", records1.get().get(1).data().asString()); - assertEquals("lb-0--tenant1:app1:default--prod.us-central-1.", records2.get().get(0).data().asString()); - assertEquals("lb-0--tenant1:app1:default--prod.us-west-1.", records2.get().get(1).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-central-1/dns-zone-1/prod.us-central-1", records1.get().get(0).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-west-1/dns-zone-1/prod.us-west-1", records1.get().get(1).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-central-1/dns-zone-1/prod.us-central-1", records2.get().get(0).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-west-1/dns-zone-1/prod.us-west-1", records2.get().get(1).data().asString()); assertEquals(2, tester.controller().applications().routingPolicies(app1.id()).iterator().next() .rotationEndpointsIn(SystemName.main).asList().size()); @@ -88,9 +88,9 @@ public class RoutingPolicyMaintainerTest { provisionLoadBalancers(app1, 2, rotations); maintainer.maintain(); assertEquals(numberOfDeployments, records1.get().size()); - assertEquals("lb-0--tenant1:app1:default--prod.us-central-1.", records1.get().get(0).data().asString()); - assertEquals("lb-0--tenant1:app1:default--prod.us-east-3.", records1.get().get(1).data().asString()); - assertEquals("lb-0--tenant1:app1:default--prod.us-west-1.", records1.get().get(2).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-central-1/dns-zone-1/prod.us-central-1", records1.get().get(0).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-east-3/dns-zone-1/prod.us-east-3", records1.get().get(1).data().asString()); + assertEquals("lb-0--tenant1:app1:default--prod.us-west-1/dns-zone-1/prod.us-west-1", records1.get().get(2).data().asString()); // Another application is deployed Supplier<List<Record>> records3 = () -> tester.controllerTester().nameService().findRecords(Record.Type.ALIAS, RecordName.from("r0.app2.tenant1.global.vespa.oath.cloud")); @@ -98,8 +98,8 @@ public class RoutingPolicyMaintainerTest { provisionLoadBalancers(app2, 1, Map.of(0, Set.of(RotationName.from("r0")))); maintainer.maintain(); assertEquals(2, records3.get().size()); - assertEquals("lb-0--tenant1:app2:default--prod.us-central-1.", records3.get().get(0).data().asString()); - assertEquals("lb-0--tenant1:app2:default--prod.us-west-1.", records3.get().get(1).data().asString()); + assertEquals("lb-0--tenant1:app2:default--prod.us-central-1/dns-zone-1/prod.us-central-1", records3.get().get(0).data().asString()); + assertEquals("lb-0--tenant1:app2:default--prod.us-west-1/dns-zone-1/prod.us-west-1", records3.get().get(1).data().asString()); // All rotations for app1 are removed provisionLoadBalancers(app1, clustersPerZone, Collections.emptyMap()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/NameServiceQueueSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/NameServiceQueueSerializerTest.java new file mode 100644 index 00000000000..e852710c604 --- /dev/null +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/NameServiceQueueSerializerTest.java @@ -0,0 +1,52 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.persistence; + +import com.yahoo.config.provision.HostName; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.dns.AliasTarget; +import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; +import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordData; +import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName; +import com.yahoo.vespa.hosted.controller.dns.CreateRecord; +import com.yahoo.vespa.hosted.controller.dns.CreateRecords; +import com.yahoo.vespa.hosted.controller.dns.NameServiceQueue; +import com.yahoo.vespa.hosted.controller.dns.RemoveRecords; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author mpolden + */ +public class NameServiceQueueSerializerTest { + + private final NameServiceQueueSerializer serializer = new NameServiceQueueSerializer(); + + @Test + public void test_serialization() { + var record1 = new Record(Record.Type.CNAME, RecordName.from("cname.example.com"), RecordData.from("example.com")); + var record2 = new Record(Record.Type.TXT, RecordName.from("txt.example.com"), RecordData.from("text")); + var requests = List.of( + new CreateRecord(record1), + new CreateRecords(List.of(record2)), + new CreateRecords(List.of(new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), + new AliasTarget(HostName.from("alias1"), + "dns-zone-01", + ZoneId.from("prod", "us-north-1")).asData()), + new Record(Record.Type.ALIAS, RecordName.from("alias.example.com"), + new AliasTarget(HostName.from("alias2"), + "dns-zone-02", + ZoneId.from("prod", "us-north-2")).asData())) + ), + new RemoveRecords(record1.type(), record1.name()), + new RemoveRecords(record2.type(), record2.data()) + ); + + var queue = new NameServiceQueue(requests); + var serialized = serializer.fromSlime(serializer.toSlime(queue)); + assertEquals(List.copyOf(queue.requests()), List.copyOf(serialized.requests())); + } + +} |