summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-07-17 14:30:48 +0200
committerJon Bratseth <bratseth@gmail.com>2022-07-17 14:30:48 +0200
commit7d1955dbbe90db24537f566bd1c503c8454d31fc (patch)
tree612541c0bcdac85345c057a393ac7e22c145f80d
parent3a24aefe5163d61b406e8aeaef69f68f4bf0b937 (diff)
Use fixture
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTest.java79
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java6
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/Fixture.java61
3 files changed, 88 insertions, 58 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTest.java
index f3af5016697..e36091332be 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTest.java
@@ -50,10 +50,10 @@ public class AutoscalingTest {
9, 1, 2.8, 5.0, 50.0,
fixture.autoscale());
- fixture.deploy(scaledResources);
+ fixture.deploy(Capacity.from(scaledResources));
assertTrue("Cluster in flux -> No further change", fixture.autoscale().isEmpty());
- fixture.deactivateRetired(scaledResources);
+ fixture.deactivateRetired(Capacity.from(scaledResources));
fixture.tester().clock().advance(Duration.ofDays(2));
fixture.applyCpuLoad(0.8f, 3);
@@ -88,7 +88,7 @@ public class AutoscalingTest {
ClusterResources scaledResources = fixture.tester().assertResources("Scaling up since cpu usage is too high",
5, 1, 3.8, 8.0, 50.5,
fixture.autoscale());
- fixture.deploy(scaledResources);
+ fixture.deploy(Capacity.from(scaledResources));
fixture.applyCpuLoad(0.1f, 120);
fixture.tester().assertResources("Scaling down since cpu usage has gone down",
4, 1, 2.5, 6.4, 25.5,
@@ -97,65 +97,56 @@ public class AutoscalingTest {
@Test
public void autoscaling_handles_disk_setting_changes() {
- NodeResources hostResources = new NodeResources(3, 100, 100, 1, NodeResources.DiskSpeed.slow);
- AutoscalingTester tester = new AutoscalingTester(hostResources);
-
- ApplicationId application1 = AutoscalingTester.applicationId("application1");
- ClusterSpec cluster1 = AutoscalingTester.clusterSpec(ClusterSpec.Type.content, "cluster1");
-
- // deploy with slow
- tester.deploy(application1, cluster1, 5, 1, hostResources);
- assertTrue(tester.nodeRepository().nodes().list().owner(application1).stream()
+ var resources = new NodeResources(3, 100, 100, 1, NodeResources.DiskSpeed.slow);
+ var fixture = AutoscalingTester.fixture()
+ .hostResources(resources)
+ .initialResources(Optional.of(new ClusterResources(5, 1, resources)))
+ .capacity(Capacity.from(new ClusterResources(5, 1, resources)))
+ .build();
+
+ assertTrue(fixture.tester().nodeRepository().nodes().list().owner(fixture.application).stream()
.allMatch(n -> n.allocation().get().requestedResources().diskSpeed() == NodeResources.DiskSpeed.slow));
- tester.clock().advance(Duration.ofDays(2));
- tester.addQueryRateMeasurements(application1, cluster1.id(), 100, t -> t == 0 ? 20.0 : 10.0); // Query traffic only
- tester.addCpuMeasurements(0.25f, 1f, 120, application1);
+ fixture.tester().clock().advance(Duration.ofDays(2));
+ fixture.applyCpuLoad(0.25, 120);
+
// Changing min and max from slow to any
ClusterResources min = new ClusterResources( 2, 1,
new NodeResources(1, 1, 1, 1, NodeResources.DiskSpeed.any));
ClusterResources max = new ClusterResources(20, 1,
new NodeResources(100, 1000, 1000, 1, NodeResources.DiskSpeed.any));
var capacity = Capacity.from(min, max);
- ClusterResources scaledResources = tester.assertResources("Scaling up since resource usage is too high",
- 14, 1, 1.4, 30.8, 30.8,
- tester.autoscale(application1, cluster1, capacity));
- assertEquals("Disk speed from min/max is used",
+ ClusterResources scaledResources = fixture.tester().assertResources("Scaling up",
+ 14, 1, 1.4, 30.8, 30.8,
+ fixture.autoscale(capacity));
+ assertEquals("Disk speed from new capacity is used",
NodeResources.DiskSpeed.any, scaledResources.nodeResources().diskSpeed());
- tester.deploy(application1, cluster1, scaledResources);
- assertTrue(tester.nodeRepository().nodes().list().owner(application1).stream()
- .allMatch(n -> n.allocation().get().requestedResources().diskSpeed() == NodeResources.DiskSpeed.any));
+ fixture.deploy(Capacity.from(scaledResources));
+ assertTrue(fixture.nodes().stream()
+ .allMatch(n -> n.allocation().get().requestedResources().diskSpeed() == NodeResources.DiskSpeed.any));
}
@Test
public void autoscaling_target_preserves_any() {
- NodeResources hostResources = new NodeResources(3, 100, 100, 1);
- AutoscalingTester tester = new AutoscalingTester(hostResources);
-
- ApplicationId application1 = AutoscalingTester.applicationId("application1");
- ClusterSpec cluster1 = AutoscalingTester.clusterSpec(ClusterSpec.Type.content, "cluster1");
-
- // Initial deployment
NodeResources resources = new NodeResources(1, 10, 10, 1);
- var min = new ClusterResources( 2, 1, resources.with(NodeResources.DiskSpeed.any));
- var max = new ClusterResources( 10, 1, resources.with(NodeResources.DiskSpeed.any));
- var capacity = Capacity.from(min, max);
- tester.deploy(application1, cluster1, Capacity.from(min, max));
+ var capacity = Capacity.from(new ClusterResources( 2, 1, resources.with(NodeResources.DiskSpeed.any)),
+ new ClusterResources( 10, 1, resources.with(NodeResources.DiskSpeed.any)));
+
+ var fixture = AutoscalingTester.fixture()
+ .capacity(capacity)
+ .initialResources(Optional.empty())
+ .build();
// Redeployment without target: Uses current resource numbers with *requested* non-numbers (i.e disk-speed any)
- assertTrue(tester.nodeRepository().applications().get(application1).get().cluster(cluster1.id()).get().targetResources().isEmpty());
- tester.deploy(application1, cluster1, Capacity.from(min, max));
- assertEquals(NodeResources.DiskSpeed.any,
- tester.nodeRepository().nodes().list().owner(application1).cluster(cluster1.id()).first().get()
- .allocation().get().requestedResources().diskSpeed());
+ assertTrue(fixture.tester().nodeRepository().applications().get(fixture.application).get().cluster(fixture.cluster.id()).get().targetResources().isEmpty());
+ fixture.deploy();
+ assertEquals(NodeResources.DiskSpeed.any, fixture.nodes().first().get().allocation().get().requestedResources().diskSpeed());
// Autoscaling: Uses disk-speed any as well
- tester.clock().advance(Duration.ofDays(2));
- tester.addCpuMeasurements(0.8f, 1f, 120, application1);
- Autoscaler.Advice advice = tester.autoscale(application1, cluster1, capacity);
- assertEquals(NodeResources.DiskSpeed.any, advice.target().get().nodeResources().diskSpeed());
-
-
+ fixture.deactivateRetired(capacity);
+ fixture.tester().clock().advance(Duration.ofDays(1));
+ fixture.applyCpuLoad(0.8, 120);
+ assertEquals(NodeResources.DiskSpeed.any, fixture.autoscale(capacity).target().get().nodeResources().diskSpeed());
}
@Test
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java
index 862eb744162..e08444c6edb 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java
@@ -130,13 +130,17 @@ class AutoscalingTester {
}
public void deactivateRetired(ApplicationId application, ClusterSpec cluster, ClusterResources resources) {
+ deactivateRetired(application, cluster, Capacity.from(resources));
+ }
+
+ public void deactivateRetired(ApplicationId application, ClusterSpec cluster, Capacity capacity) {
try (Mutex lock = nodeRepository().nodes().lock(application)) {
for (Node node : nodeRepository().nodes().list(Node.State.active).owner(application)) {
if (node.allocation().get().membership().retired())
nodeRepository().nodes().write(node.with(node.allocation().get().removable(true, true)), lock);
}
}
- deploy(application, cluster, resources);
+ deploy(application, cluster, capacity);
}
public ClusterModel clusterModel(ApplicationId applicationId, ClusterSpec clusterSpec) {
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/Fixture.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/Fixture.java
index 416f61d62d3..371cbe25e1b 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/Fixture.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/Fixture.java
@@ -6,8 +6,10 @@ import com.yahoo.config.provision.Capacity;
import com.yahoo.config.provision.ClusterResources;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.NodeResources;
+import com.yahoo.vespa.hosted.provision.NodeList;
import java.time.Duration;
+import java.util.Optional;
/**
* Fixture for autoscaling tests.
@@ -21,26 +23,44 @@ public class Fixture {
final ClusterSpec cluster;
final Capacity capacity;
- public Fixture(Fixture.Builder builder) {
+ public Fixture(Fixture.Builder builder, Optional<ClusterResources> initialResources) {
application = builder.application;
cluster = builder.cluster;
- capacity = Capacity.from(builder.min, builder.max);
+ capacity = builder.capacity;
tester = new AutoscalingTester(builder.hostResources);
- tester.deploy(builder.application, builder.cluster, 5, 1, builder.nodeResources);
+ var deployCapacity = initialResources.isPresent() ? Capacity.from(initialResources.get()) : capacity;
+ tester.deploy(builder.application, builder.cluster, deployCapacity);
}
public AutoscalingTester tester() { return tester; }
+ /** Autoscale within the deployed capacity of this. */
public Autoscaler.Advice autoscale() {
+ return autoscale(capacity);
+ }
+
+ /** Autoscale within the given capacity. */
+ public Autoscaler.Advice autoscale(Capacity capacity) {
return tester.autoscale(application, cluster, capacity);
}
- public void deploy(ClusterResources resources) {
- tester.deploy(application, cluster, resources);
+ /** Redeploy with the deployed capacity of this. */
+ public void deploy() {
+ deploy(capacity);
+ }
+
+ /** Redeploy with the given capacity. */
+ public void deploy(Capacity capacity) {
+ tester.deploy(application, cluster, capacity);
}
- public void deactivateRetired(ClusterResources resources) {
- tester.deactivateRetired(application, cluster, resources);
+ /** Returns the nodes allocated to the fixture application cluster */
+ public NodeList nodes() {
+ return tester.nodeRepository().nodes().list().owner(application).cluster(cluster.id());
+ }
+
+ public void deactivateRetired(Capacity capacity) {
+ tester.deactivateRetired(application, cluster, capacity);
}
public void applyLoad(double cpuLoad, double memoryLoad, double diskLoad, int measurements) {
@@ -60,11 +80,11 @@ public class Fixture {
public static class Builder {
NodeResources hostResources = new NodeResources(100, 100, 100, 1);
- NodeResources nodeResources = new NodeResources(3, 10, 100, 1);
- ClusterResources min = new ClusterResources(2, 1,
- new NodeResources(1, 1, 1, 1, NodeResources.DiskSpeed.any));
- ClusterResources max = new ClusterResources(20, 1,
- new NodeResources(100, 1000, 1000, 1, NodeResources.DiskSpeed.any));
+ Optional<ClusterResources> initialResources = Optional.of(new ClusterResources(5, 1, new NodeResources(3, 10, 100, 1)));
+ Capacity capacity = Capacity.from(new ClusterResources(2, 1,
+ new NodeResources(1, 1, 1, 1, NodeResources.DiskSpeed.any)),
+ new ClusterResources(20, 1,
+ new NodeResources(100, 1000, 1000, 1, NodeResources.DiskSpeed.any)));
ApplicationId application = AutoscalingTester.applicationId("application1");
ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("cluster1")).vespaVersion("7").build();
@@ -74,8 +94,23 @@ public class Fixture {
return this;
}
+ public Fixture.Builder hostResources(NodeResources hostResources) {
+ this.hostResources = hostResources;
+ return this;
+ }
+
+ public Fixture.Builder initialResources(Optional<ClusterResources> initialResources) {
+ this.initialResources = initialResources;
+ return this;
+ }
+
+ public Fixture.Builder capacity(Capacity capacity) {
+ this.capacity = capacity;
+ return this;
+ }
+
public Fixture build() {
- return new Fixture(this);
+ return new Fixture(this, initialResources);
}
}