@Override
    protected double maintain() {
        if ( ! nodeRepository().nodes().isWorking()) return 0.0;
        if (nodeRepository().zone().environment().isTest()) return 1.0;

        int attempts = 0;
        int failures = 0;
        outer:
        for (var applicationNodes : activeNodesByApplication().entrySet()) {
            for (var clusterNodes : nodesByCluster(applicationNodes.getValue()).entrySet()) {
                if (shuttingDown()) break outer;
                attempts++;
                if ( ! autoscale(applicationNodes.getKey(), clusterNodes.getKey()))
                    failures++;
            }
        }
        return asSuccessFactorDeviation(attempts, failures);
    }
@Test
    public void empty_autoscaling_is_ignored() {
        ApplicationId app1 = AutoscalingMaintainerTester.makeApplicationId("app1");
        ClusterSpec cluster1 = AutoscalingMaintainerTester.containerClusterSpec();
        NodeResources resources = new NodeResources(4, 4, 10, 1);
        ClusterResources min = new ClusterResources(2, 1, resources);
        ClusterResources max = new ClusterResources(20, 1, resources);
        var capacity = Capacity.from(min, max);
        var tester = new AutoscalingMaintainerTester(new MockDeployer.ApplicationContext(app1, cluster1, capacity));

        // Add a scaling event
        tester.deploy(app1, cluster1, capacity);
        tester.addMeasurements(1.0f, 0.3f, 0.3f, 0, 4, app1, cluster1.id());
        tester.maintainer().maintain();
        assertEquals("Scale up: " + tester.cluster(app1, cluster1).target().status(),
                     1,
                     tester.cluster(app1, cluster1).lastScalingEvent().get().generation());
        Load peak = tester.cluster(app1, cluster1).target().peak();
        assertNotEquals(Load.zero(), peak);

        // Old measurements go out of scope and no new ones are made
        tester.clock().advance(Duration.ofDays(1));
        tester.maintainer().maintain();
        Load newPeak = tester.cluster(app1, cluster1).target().peak();
        assertEquals("Old measurements are retained", peak, newPeak);
    }