@Test
    public void relocate_nodes_from_spare_hosts() {
        int spareCount = 1;
        ProvisioningTester tester = new ProvisioningTester.Builder().zone(new Zone(Environment.prod, RegionName.from("us-east")))
                                                                    .flavorsConfig(flavorsConfig())
                                                                    .spareCount(spareCount)
                                                                    .build();
        tester.makeReadyNodes(4, "host-small", NodeType.host, 32);
        tester.activateTenantHosts();
        List<Node> hosts = tester.nodeRepository().nodes().list(Node.State.active).nodeType(NodeType.host).asList();
        NodeResources flavor = new NodeResources(1, 4, 100, 1);

        // Application 1
        ApplicationId application1 = makeApplicationId("t1", "a1");
        ClusterSpec clusterSpec1 = clusterSpec("myContent.t1.a1");
        addAndAssignNode(application1, "1a", hosts.get(0).hostname(), clusterSpec1, flavor, 0, tester);
        addAndAssignNode(application1, "1b", hosts.get(1).hostname(), clusterSpec1, flavor, 1, tester);

        // Application 2
        ApplicationId application2 = makeApplicationId("t2", "a2");
        ClusterSpec clusterSpec2 = clusterSpec("myContent.t2.a2");
        addAndAssignNode(application2, "2a", hosts.get(2).hostname(), clusterSpec2, flavor, 3, tester);
        addAndAssignNode(application2, "2b", hosts.get(3).hostname(), clusterSpec2, flavor, 4, tester);

        // Redeploy both applications (to be agnostic on which hosts are picked as spares)
        deployApp(application1, clusterSpec1, flavor, tester, 2);
        deployApp(application2, clusterSpec2, flavor, tester, 2);

        // Assert that we have two spare nodes (two hosts that are don't have allocations)
        Set<String> hostsWithChildren = new HashSet<>();
        for (Node node : tester.nodeRepository().nodes().list(State.active).nodeType(NodeType.tenant).not().state(State.inactive).not().retired()) {
            hostsWithChildren.add(node.parentHostname().get());
        }
        assertEquals(4 - spareCount, hostsWithChildren.size());
    }
Test relocation of nodes from spare hosts.
<p>
Setup 4 hosts and allocate one container on each (from two different applications)
getSpareCapacityProd() spares.
<p>
Check that it relocates containers away from the getSpareCapacityProd() spares
<p>
Initial allocation of app 1 and 2 --> final allocation (example using 2 spares):
<p>
|    |    |    |    |        |    |    |    |    |
|    |    |    |    |   -->  | 2a | 2b |    |    |
| 1a | 1b | 2a | 2b |        | 1a | 1b |    |    |
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DynamicAllocationTest.java