private void deploy(ApplicationId application, Capacity capacity, ProvisioningTester tester) {
        int nodeCount = capacity.minResources().nodes();
        NodeResources nodeResources = capacity.minResources().nodeResources();

        tester.activate(application, prepare(application, capacity, tester));
        assertEquals("Nodes of wrong size are retired",
                     0, tester.getNodes(application, Node.State.active).not().retired().not().resources(nodeResources).size());

        // Check invariants for all nodes
        Set<Integer> allIndexes = new HashSet<>();
        for (Node node : tester.getNodes(application, Node.State.active)) {
            // Node indexes must be unique
            int index = node.allocation().get().membership().index();
            assertFalse("Node indexes are unique", allIndexes.contains(index));
            allIndexes.add(index);

            assertTrue(node.allocation().get().membership().cluster().group().isPresent());
        }

        // Count unretired nodes and groups of the requested flavor
        Set<Integer> indexes = new HashSet<>();
        Map<ClusterSpec.Group, Integer> nonretiredGroups = new HashMap<>();
        for (Node node : tester.getNodes(application, Node.State.active).not().retired().resources(nodeResources)) {
            indexes.add(node.allocation().get().membership().index());

            ClusterSpec.Group group = node.allocation().get().membership().cluster().group().get();
            nonretiredGroups.put(group, nonretiredGroups.getOrDefault(group, 0) + 1);

            if (capacity.minResources().groups() > 1)
                assertTrue("Group indexes are always in [0, wantedGroups>",
                           group.index() < capacity.minResources().groups());
        }
        assertEquals("Total nonretired nodes", nodeCount, indexes.size());
        assertEquals("Total nonretired groups", capacity.minResources().groups(), nonretiredGroups.size());
        for (Integer groupSize : nonretiredGroups.values())
            assertEquals("Group size", (long)nodeCount / capacity.minResources().groups(), (long)groupSize);

        Map<ClusterSpec.Group, Integer> allGroups = new HashMap<>();
        for (Node node : tester.getNodes(application, Node.State.active).resources(nodeResources)) {
            ClusterSpec.Group group = node.allocation().get().membership().cluster().group().get();
            allGroups.put(group, nonretiredGroups.getOrDefault(group, 0) + 1);
        }
        assertEquals("No additional groups are retained containing retired nodes", capacity.minResources().groups(), allGroups.size());
    }
When increasing the number of groups without changing node count, we need to provison new nodes for
the new groups since although we can remove nodes from existing groups without losing data we
cannot do so without losing coverage.
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/MultigroupProvisioningTest.java