@Override public void run() { // must use "succeedsEventually" because size + members attributes are set sequentially in another thread; // just waiting for the first does not mean the second will have been set by the time we check in this thread. Asserts.assertEqualsIgnoringOrder(group.getAttribute(BasicGroup.GROUP_MEMBERS), ImmutableList.of(e1, e2)); }}); }
@Override public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e2)); }}); }
@Override public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e3)); }}); }
@Override public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of()); }}); }
@Override public void run() { assertEqualsIgnoringOrder(ImmutableSet.copyOf(group.getMembers()), ImmutableSet.of(e1, e2)); }}); }
@Test public void testCanUsePredicateAsFilter() throws Exception { Predicate<Entity> predicate = Predicates.<Entity>equalTo(e1); group.setEntityFilter(predicate); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1)); }
@Test public void testGroupWithMatchingFilterReturnsEverythingThatMatches() throws Exception { group.setEntityFilter(Predicates.alwaysTrue()); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, app, group)); }
private void assertGroupMembers(Entity... expectedMembers) { Asserts.assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.copyOf(expectedMembers)); assertEquals(group.getAttribute(BasicGroup.GROUP_SIZE), (Integer)expectedMembers.length); } }
@Test public void testEntityGetGroups() throws Exception { group.addMember(entity1); Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of(group)); group.removeMember(entity1); Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of()); }
@Test public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception { group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId())); assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1)); }
@Test(enabled = false) // FIXME fails currently public void testRemoveChild() { Entity e = app.addChild(EntitySpec.create(TestEntity.class)); app.removeChild(e); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of()); assertEquals(e.getParent(), null); }
@Test public void testSpecDeclaresParent() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app)); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); }
@Test public void testParentCanHaveMultipleChildren() { Entity e = app.addChild(EntitySpec.create(TestEntity.class)); Entity e2 = app.addChild(EntitySpec.create(TestEntity.class)); assertEquals(e.getParent(), app); assertEquals(e2.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e,e2)); }
@Test public void testSetParentInSetterMethod() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)); e.setParent(app); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); assertEquals(e.getApplication(), app); }
@Test public void testGroupUsesNewFilter() throws Exception { final Entity e3 = app.addChild(EntitySpec.create(TestEntity.class).displayName("myname")); group.setEntityFilter(EntityPredicates.displayNameEqualTo("myname")); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e3)); }
public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3, e)); assertAttributeEquals(e, SequenceGroup.SEQUENCE_VALUE, 4); assertAttributeEquals(group, SequenceGroup.SEQUENCE_CURRENT, e); AtomicInteger state = group.sensors().get(SequenceGroup.SEQUENCE_STATE); assertEquals(state.get(), 5); }}); }
@Test public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception { group = app.addChild(EntitySpec.create(SequenceGroup.class) .configure(SequenceGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("test-one"))); createTestEntities(); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true); assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1)); assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1); AtomicInteger state = group.sensors().get(SequenceGroup.SEQUENCE_STATE); assertEquals(state.get(), 2); }
@Test public void testPolicyTags() throws Exception { Policy origPolicy = origApp.policies().add(PolicySpec.create(MyPolicy.class)); origPolicy.tags().addTag("foo"); origPolicy.tags().addTag(origApp); newApp = rebind(); Policy newPolicy = Iterables.getOnlyElement(newApp.policies()); Asserts.assertEqualsIgnoringOrder(newPolicy.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test public void testPolicyTags() throws Exception { Enricher origEnricher = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class)); origEnricher.tags().addTag("foo"); origEnricher.tags().addTag(origApp); newApp = rebind(); Enricher newEnricher = Iterables.getOnlyElement(newApp.enrichers()); Asserts.assertEqualsIgnoringOrder(newEnricher.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test public void testLocationTags() throws Exception { Location origLoc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class)); origLoc.tags().addTag("foo"); origLoc.tags().addTag(origApp); origApp.start(ImmutableList.of(origLoc)); newApp = rebind(); Location newLoc = newManagementContext.getLocationManager().getLocation(origLoc.getId()); Asserts.assertEqualsIgnoringOrder(newLoc.tags().getTags(), ImmutableSet.of("foo", newApp)); }