### Question:
ClusterLayout { public boolean isValid() { return satisfiesConstraints(constraints); } ClusterLayout(Constraints constraints, Multiset<NodeLayout> layout); Multiset<NodeLayout> getLayout(); Constraints getConstraints(); boolean isValid(); boolean isCompatibleWithTemplate(ClusterTemplate template); static ClusterLayout fromNodes(Set<Node> clusterNodes, Constraints constraints); @Override boolean equals(Object o); @Override int hashCode();  }### Answer:
@Test public void testInvalidHardwareTypeShowsAsInvalid() { NodeLayout badNodeLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("namenode")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(badNodeLayout, 1); ClusterLayout layout = new ClusterLayout(constraints, counts); Assert.assertFalse(layout.isValid()); }
@Test public void testInvalidImageTypeShowsAsInvalid() { NodeLayout badNodeLayout = new NodeLayout("large-mem", "rhel5", ImmutableSet.of("namenode")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(badNodeLayout, 1); ClusterLayout layout = new ClusterLayout(constraints, counts); Assert.assertFalse(layout.isValid()); }
@Test public void testInvalidCountsShowsAsInvalid() { NodeLayout goodNodeLayout = new NodeLayout("large-mem", "ubuntu12", ImmutableSet.of("namenode")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(goodNodeLayout, 2); ClusterLayout layout = new ClusterLayout(constraints, counts); Assert.assertFalse(layout.isValid()); }
@Test public void testValidLayout() { NodeLayout masterNodeLayout = new NodeLayout("large-mem", "centos6", ImmutableSet.of("namenode")); NodeLayout slaveLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("datanode")); NodeLayout reactorLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("reactor", "zookeeper")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(masterNodeLayout); counts.add(reactorLayout); counts.add(slaveLayout, 50); ClusterLayout layout = new ClusterLayout(constraints, counts); Assert.assertTrue(layout.isValid()); }