### Question:
ClusterLayoutFinder { public int[] findValidNodeCounts() { int[] initialLayout = getInitialNodeCounts(); if (initialLayout == null) { return null; } SlottedCombinationIterator layoutIter = new SlottedCombinationIterator(initialLayout, getGlobalNodeLayoutMaxes()); int[] previousLayout = initialLayout; while (layoutIter.hasNext()) { int[] candidateLayout = layoutIter.next(); for (int i = 0; i < candidateLayout.length; i++) { int countDiff = candidateLayout[i] - previousLayout[i]; updateServiceCounts(i, countDiff); } if (isValidCluster(serviceCounts)) { return candidateLayout; } previousLayout = candidateLayout; } return null; } ClusterLayoutFinder(List<NodeLayout> nodePreferences, ClusterTemplate template, Set<String> services,
                             int numMachines); int[] findValidNodeCounts();  }### Answer:
@Test public void testGetClusterNodes() { List<NodeLayout> nodePreferences = ImmutableList.of( new NodeLayout("large-mem", "centos6", ImmutableSet.of("namenode", "resourcemanager", "hbasemaster")), new NodeLayout("large-cpu", "centos6", ImmutableSet.of("datanode", "nodemanager", "regionserver")), new NodeLayout("medium", "centos6", ImmutableSet.of("reactor", "zookeeper")), new NodeLayout("medium", "centos6", ImmutableSet.of("zookeeper")), new NodeLayout("large", "centos6", ImmutableSet.of("reactor")) ); Set<String> services = ImmutableSet.of("namenode", "resourcemanager", "hbasemaster", "datanode", "nodemanager", "regionserver", "reactor", "zookeeper"); ClusterLayoutFinder finder = new ClusterLayoutFinder(nodePreferences, reactorTemplate, services, 5); Assert.assertTrue(Arrays.equals(new int[]{1, 3, 1, 0, 0}, finder.findValidNodeCounts())); finder = new ClusterLayoutFinder(nodePreferences, reactorTemplate, services, 10); Assert.assertTrue(Arrays.equals(new int[]{1, 8, 1, 0, 0}, finder.findValidNodeCounts())); finder = new ClusterLayoutFinder(nodePreferences, reactorTemplate, services, 54); Assert.assertTrue(Arrays.equals(new int[]{1, 50, 3, 0, 0}, finder.findValidNodeCounts())); }
@Test public void testNoSolutionReturnsNull() { Set<String> services = ImmutableSet.of("svc1", "svc2", "svc3"); ClusterTemplate template = ClusterTemplate.builder() .setName("simple") .setDescription("all services on all nodes template") .setClusterDefaults(ClusterDefaults.builder().setServices(services).setProvider("joyent").build()) .setCompatibilities(Compatibilities.builder().setServices(services).build()) .setConstraints(new Constraints( ImmutableMap.<String, ServiceConstraint>of("svc1", new ServiceConstraint(null, null, 1, 1)), new LayoutConstraint( ImmutableSet.<Set<String>>of(ImmutableSet.of("svc1", "svc2", "svc3")), ImmutableSet.<Set<String>>of() ), SizeConstraint.EMPTY)) .build(); List<NodeLayout> nodePreferences = ImmutableList.of( new NodeLayout("small", "centos6", ImmutableSet.of("svc1", "svc2", "svc3")) ); ClusterLayoutFinder finder = new ClusterLayoutFinder(nodePreferences, template, services, 2); Assert.assertNull(finder.findValidNodeCounts()); }