### Question:
NodeLayoutGenerator { public List<NodeLayout> generateNodeLayoutPreferences() { long start = System.nanoTime(); Set<String> unconstrainedServices = findUnconstrainedServices(); Set<String> constrainedServices = Sets.difference(clusterServices, unconstrainedServices); Set<Set<String>> validServiceSets = findValidServiceSets(Sets.newHashSet(constrainedServices)); if (!unconstrainedServices.isEmpty()) { for (Set<String> validServiceSet : validServiceSets) { validServiceSet.addAll(unconstrainedServices); } validServiceSets.add(unconstrainedServices); } long dur = (System.nanoTime() - start) / 1000000; LOG.debug("took {} ms to find {} valid service sets", dur, validServiceSets.size()); start = System.nanoTime(); Set<NodeLayout> validNodeLayouts = findValidNodeLayouts(validServiceSets); dur = (System.nanoTime() - start) / 1000000; LOG.debug("took {} ms to find {} valid node layouts", dur, validNodeLayouts.size()); start = System.nanoTime(); List<NodeLayout> traversalOrder = narrowNodeLayouts(validNodeLayouts, null, null); dur = (System.nanoTime() - start) / 1000000; LOG.debug("took {} ms to narrow to {} valid node layouts", dur, traversalOrder.size()); return traversalOrder; } NodeLayoutGenerator(ClusterTemplate clusterTemplate, Set<String> clusterServices,
                             Set<String> allowedHardwareTypes, Set<String> allowedImageTypes); List<NodeLayout> generateNodeLayoutPreferences();  }### Answer:
@Test public void testNodesMustHaveServices() throws Exception { 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> expected = ImmutableList.of( new NodeLayout("small", "centos6", ImmutableSet.of("svc1", "svc2", "svc3")) ); NodeLayoutGenerator nodeLayoutGenerator = new NodeLayoutGenerator(template, services, ImmutableSet.<String>of("small"), ImmutableSet.<String>of("centos6")); List<NodeLayout> actual = nodeLayoutGenerator.generateNodeLayoutPreferences(); Assert.assertEquals(expected, actual); }