AttributeAggregate { @VisibleForTesting Multiset<Pair<String, String>> getAggregates() { return aggregate.get(); } private  AttributeAggregate(Supplier<Multiset<Pair<String, String>>> aggregate); static AttributeAggregate getJobActiveState(
      final StoreProvider storeProvider,
      final IJobKey jobKey); long getNumTasksWithAttribute(String name, String value); @Override boolean equals(Object o); @Override int hashCode(); @VisibleForTesting
  static final AttributeAggregate EMPTY; }
@Test public void testNoTasks() { control.replay(); AttributeAggregate aggregate = aggregate(); assertEquals(ImmutableMultiset.<Pair<String, String>>of(), aggregate.getAggregates()); assertAggregate(aggregate, "none", "alsoNone", 0); }
@Test(expected = IllegalStateException.class) public void testAttributesMissing() { expect(attributeStore.getHostAttributes("a")).andReturn(Optional.absent()); control.replay(); aggregate(task("1", "a")).getAggregates(); }
@Test(expected = NullPointerException.class) public void testTaskWithNoHost() { control.replay(); aggregate(task("1", null)).getAggregates(); }
@Test public void testNoAttributes() { expectGetAttributes("hostA"); control.replay(); assertEquals( ImmutableMultiset.<Pair<String, String>>of(), aggregate(task("1", "hostA")).getAggregates()); }
@Test public void testAggregate() { expectGetAttributes( "a1", attribute("host", "a1"), attribute("rack", "a"), attribute("pdu", "p1")); expectGetAttributes( "b1", attribute("host", "b1"), attribute("rack", "b"), attribute("pdu", "p1", "p2")) .times(2); expectGetAttributes( "b2", attribute("host", "b2"), attribute("rack", "b"), attribute("pdu", "p1", "p2")); expectGetAttributes( "c1", attribute("host", "c1"), attribute("rack", "c"), attribute("pdu", "p2"), attribute("ssd", "true")); control.replay(); Multiset<Pair<String, String>> expected = ImmutableMultiset.<Pair<String, String>>builder() .add(Pair.of("rack", "a")) .addCopies(Pair.of("rack", "b"), 3) .add(Pair.of("rack", "c")) .add(Pair.of("host", "a1")) .addCopies(Pair.of("host", "b1"), 2) .add(Pair.of("host", "b2")) .add(Pair.of("host", "c1")) .addCopies(Pair.of("pdu", "p1"), 4) .addCopies(Pair.of("pdu", "p2"), 4) .add(Pair.of("ssd", "true")) .build(); AttributeAggregate aggregate = aggregate( task("1", "a1"), task("2", "b1"), task("3", "b1"), task("4", "b2"), task("5", "c1")); assertEquals(expected, aggregate.getAggregates()); for (Multiset.Entry<Pair<String, String>> entry : expected.entrySet()) { Pair<String, String> element = entry.getElement(); assertAggregate(aggregate, element.getFirst(), element.getSecond(), entry.getCount()); } assertAggregate(aggregate, "host", "c2", 0L); assertAggregate(aggregate, "hostc", "2", 0L); }