public void getConfig(StorDistributionConfig.Group.Builder builder) {
        builder.index(index == null ? "invalid" : index);
        builder.name(name == null ? "invalid" : name);
        partitions.ifPresent(builder::partitions);
        for (StorageNode node : nodes) {
            StorDistributionConfig.Group.Nodes.Builder nb = new StorDistributionConfig.Group.Nodes.Builder();
            nb.index(node.getDistributionKey());
            nb.retired(node.isRetired());
            builder.nodes.add(nb);
        }
        builder.capacity(getCapacity());
    }
@Test
    void testNestedGroups() throws Exception {
        ContentCluster cluster = parse(
                "<content version=\"1.0\" id=\"storage\">\n" +
                        "  <redundancy>4</redundancy>" +
                        "  <documents/>" +
                        "  <group>\n" +
                        "    <distribution partitions=\"1|*\"/>\n" +
                        "    <group distribution-key=\"0\" name=\"sub1\">\n" +
                        "      <node hostalias=\"mockhost\" distribution-key=\"0\"/>\n" +
                        "      <node hostalias=\"mockhost\" distribution-key=\"1\"/>\n" +
                        "    </group>\n" +
                        "    <group distribution-key=\"1\" name=\"sub2\">\n" +
                        "      <distribution partitions=\"1|*\"/>\n" +
                        "      <group distribution-key=\"0\" name=\"sub3\">\n" +
                        "        <node hostalias=\"mockhost\" distribution-key=\"2\"/>\n" +
                        "        <node hostalias=\"mockhost\" distribution-key=\"3\"/>\n" +
                        "      </group>\n" +
                        "      <group distribution-key=\"1\" name=\"sub4\">\n" +
                        "        <node hostalias=\"mockhost\" distribution-key=\"4\"/>\n" +
                        "        <node hostalias=\"mockhost\" distribution-key=\"5\"/>\n" +
                        "      </group>\n" +
                        "    </group>\n" +
                        "  </group>\n" +
                        "</content>"
        );

        StorDistributionConfig.Builder builder = new StorDistributionConfig.Builder();
        cluster.getConfig(builder);
        StorDistributionConfig config = new StorDistributionConfig(builder);

        assertEquals(5, config.group().size());
        assertEquals("invalid", config.group(0).index());
        assertEquals("0", config.group(1).index());
        assertEquals("1", config.group(2).index());
        assertEquals("1.0", config.group(3).index());
        assertEquals("1.1", config.group(4).index());
        assertEquals("invalid", config.group(0).name());
        assertEquals("sub1", config.group(1).name());
        assertEquals("sub2", config.group(2).name());
        assertEquals("sub3", config.group(3).name());
        assertEquals("sub4", config.group(4).name());
        assertEquals(2, config.group(1).nodes().size());
        assertEquals(0, config.group(1).nodes(0).index());
        assertEquals(1, config.group(1).nodes(1).index());
        assertEquals(0, config.group(2).nodes().size());
        assertEquals(2, config.group(3).nodes().size());
        assertEquals(2, config.group(3).nodes(0).index());
        assertEquals(3, config.group(3).nodes(1).index());
        assertEquals(2, config.group(4).nodes().size());
        assertEquals(4, config.group(4).nodes(0).index());
        assertEquals(5, config.group(4).nodes(1).index());

        assertEquals("1|*", config.group(0).partitions());

        DistributionConfig.Builder distributionBuilder = new DistributionConfig.Builder();
        cluster.getConfig(distributionBuilder);
        DistributionConfig.Cluster clusterConfig = distributionBuilder.build().cluster("storage");

        assertEquals(5, clusterConfig.group().size());
        assertEquals("invalid", clusterConfig.group(0).index());
        assertEquals("0", clusterConfig.group(1).index());
        assertEquals("1", clusterConfig.group(2).index());
        assertEquals("1.0", clusterConfig.group(3).index());
        assertEquals("1.1", clusterConfig.group(4).index());
        assertEquals("invalid", clusterConfig.group(0).name());
        assertEquals("sub1", clusterConfig.group(1).name());
        assertEquals("sub2", clusterConfig.group(2).name());
        assertEquals("sub3", clusterConfig.group(3).name());
        assertEquals("sub4", clusterConfig.group(4).name());
        assertEquals(2, clusterConfig.group(1).nodes().size());
        assertEquals(0, clusterConfig.group(1).nodes(0).index());
        assertEquals(1, clusterConfig.group(1).nodes(1).index());
        assertEquals(0, clusterConfig.group(2).nodes().size());
        assertEquals(2, clusterConfig.group(3).nodes().size());
        assertEquals(2, clusterConfig.group(3).nodes(0).index());
        assertEquals(3, clusterConfig.group(3).nodes(1).index());
        assertEquals(2, clusterConfig.group(4).nodes().size());
        assertEquals(4, clusterConfig.group(4).nodes(0).index());
        assertEquals(5, clusterConfig.group(4).nodes(1).index());

        assertEquals("1|*", clusterConfig.group(0).partitions());
    }