@Test public void testDetectsNoOrphanedGroupsWhenAllNodesArePresentAndTerminated() { Set<NodeMetadata> deadNodesGroup1 = ImmutableSet.<NodeMetadata>builder() .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); Set<NodeMetadata> deadNodesGroup2 = ImmutableSet.<NodeMetadata> builder() .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.SUSPENDED)).build(); Set<NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); ComputeService mock = createMock(ComputeService.class); expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) .andReturn((Set) deadNodesGroup1).once(); expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) .andReturn((Set) deadNodesGroup2).once(); replay(mock); OrphanedGroupsFromDeadNodes orphanedGroupsFromDeadNodes = new OrphanedGroupsFromDeadNodes( allNodesInGroupTerminated(mock)); Set<String> orphanedGroups = orphanedGroupsFromDeadNodes.apply(allDeadNodes); assertTrue(orphanedGroups.isEmpty()); }
@Override public Set<String> apply(Set<? extends NodeMetadata> deadNodes) { Set<String> groups = Sets.newLinkedHashSet(); for (NodeMetadata deadNode : deadNodes) { groups.add(deadNode.getGroup()); } Set<String> orphanedGroups = Sets.newLinkedHashSet(); for (String group : groups) { if (isOrphanedGroupPredicate.apply(group)) { orphanedGroups.add(group); } } return orphanedGroups; }
OrphanedGroupsFromDeadNodes implements Function<Set<? extends NodeMetadata>, Set<String>> { @Override public Set<String> apply(Set<? extends NodeMetadata> deadNodes) { Set<String> groups = Sets.newLinkedHashSet(); for (NodeMetadata deadNode : deadNodes) { groups.add(deadNode.getGroup()); } Set<String> orphanedGroups = Sets.newLinkedHashSet(); for (String group : groups) { if (isOrphanedGroupPredicate.apply(group)) { orphanedGroups.add(group); } } return orphanedGroups; } }
OrphanedGroupsFromDeadNodes implements Function<Set<? extends NodeMetadata>, Set<String>> { @Override public Set<String> apply(Set<? extends NodeMetadata> deadNodes) { Set<String> groups = Sets.newLinkedHashSet(); for (NodeMetadata deadNode : deadNodes) { groups.add(deadNode.getGroup()); } Set<String> orphanedGroups = Sets.newLinkedHashSet(); for (String group : groups) { if (isOrphanedGroupPredicate.apply(group)) { orphanedGroups.add(group); } } return orphanedGroups; } @Inject  OrphanedGroupsFromDeadNodes(Predicate<String> isOrphanedGroupPredicate); }
OrphanedGroupsFromDeadNodes implements Function<Set<? extends NodeMetadata>, Set<String>> { @Override public Set<String> apply(Set<? extends NodeMetadata> deadNodes) { Set<String> groups = Sets.newLinkedHashSet(); for (NodeMetadata deadNode : deadNodes) { groups.add(deadNode.getGroup()); } Set<String> orphanedGroups = Sets.newLinkedHashSet(); for (String group : groups) { if (isOrphanedGroupPredicate.apply(group)) { orphanedGroups.add(group); } } return orphanedGroups; } @Inject  OrphanedGroupsFromDeadNodes(Predicate<String> isOrphanedGroupPredicate); @Override Set<String> apply(Set<? extends NodeMetadata> deadNodes); }
OrphanedGroupsFromDeadNodes implements Function<Set<? extends NodeMetadata>, Set<String>> { @Override public Set<String> apply(Set<? extends NodeMetadata> deadNodes) { Set<String> groups = Sets.newLinkedHashSet(); for (NodeMetadata deadNode : deadNodes) { groups.add(deadNode.getGroup()); } Set<String> orphanedGroups = Sets.newLinkedHashSet(); for (String group : groups) { if (isOrphanedGroupPredicate.apply(group)) { orphanedGroups.add(group); } } return orphanedGroups; } @Inject  OrphanedGroupsFromDeadNodes(Predicate<String> isOrphanedGroupPredicate); @Override Set<String> apply(Set<? extends NodeMetadata> deadNodes);  }