@Test public void testDisplayNameEqualTo() throws Exception { assertTrue(EntityPredicates.displayNameEqualTo("mydisplayname").apply(entity)); assertFalse(EntityPredicates.displayNameEqualTo("wrongname").apply(entity)); }
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNull(bucketA); assertNotNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketB.getMembers()), ImmutableSet.of(child)); } });
@Override public void run() { Group bucketC = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketC"), null); assertNotNull(bucketC); assertEquals(ImmutableSet.copyOf(bucketC.getMembers()), ImmutableSet.of(child3)); } });
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNotNull(bucketA); assertNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketA.getMembers()), ImmutableSet.of(child1, child2)); } });
@Override public void run() { Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); Group bucketC = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketC"), null); assertNotNull(bucketB); assertNull(bucketC); assertEquals(ImmutableSet.copyOf(bucketB.getMembers()), ImmutableSet.of(child1, child2)); } });
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNull(bucketA); assertNotNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketB.getMembers()), ImmutableSet.of(child1, child2)); } });
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); assertNotNull(bucketA); assertEquals(ImmutableSet.copyOf(bucketA.getMembers()), ImmutableSet.of(child)); } });
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNotNull(bucketA); assertNotNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketB.getMembers()), ImmutableSet.of(child1)); assertEquals(ImmutableSet.copyOf(bucketA.getMembers()), ImmutableSet.of(child2)); } });
@Override public void run() { Group bucketC = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketC"), null); assertNotNull(bucketC); assertEquals(ImmutableSet.copyOf(bucketC.getMembers()), ImmutableSet.of(child3)); } });
@Test public void testBrooklynIdentityFunction() throws Exception { Iterable<? extends Entity> testEntities = setupAndCheckTestEntityInBasicYamlWith(); Entity entityOne = Iterables.find(testEntities, EntityPredicates.displayNameEqualTo("Test Entity One")); Entity entityTwo = Iterables.find(testEntities, EntityPredicates.displayNameEqualTo("Test Entity Two")); Assert.assertNotNull(entityOne, "Test entity one should be present"); Assert.assertNotNull(entityTwo, "Test entity two should be present"); Assert.assertEquals(entityOne.config().get(TEST_ENTITY_ONE_ID), entityOne.getId(), "Entity one IDs should match"); Assert.assertEquals(entityOne.config().get(TEST_ENTITY_TWO_ID), entityTwo.getId(), "Entity two IDs should match"); }
@Test public void testWithDslConfigReferenceParentDefault() throws Exception { Entity app = runTest(catalogYamlWithDslReferenceParentDefault, appVersionedId); TestEntity newEntity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); ServiceFailureDetector newEnricher = assertHasEnricher(newEntity, ServiceFailureDetector.class); assertEnricherConfigMatchesDsl(newEnricher); }
@Test public void testWithDslConfig() throws Exception { Entity app = runTest(catalogYamlWithDsl, appVersionedId); TestEntity newEntity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); ServiceFailureDetector newEnricher = assertHasEnricher(newEntity, ServiceFailureDetector.class); assertEnricherConfigMatchesDsl(newEnricher); }
protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services: ", "- type: " + appId); createStartWaitAndLogApplication(appYaml); // Rebind StartableApplication newApp = rebind(); TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); Effector effector = assertHasInitializers(testEntity, "myEffector"); // Confirm HttpCommandEffector still functions Object result = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get(); assertEquals(((String)result).trim(), "myId"); }
@Test public void testRebindWhenHealthyWithDslConfig() throws Exception { runRebindWhenHealthy(catalogYamlWithDsl, appVersionedId); TestEntity newEntity = (TestEntity) Iterables.find(app().getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); ServiceFailureDetector newEnricher = assertHasEnricher(newEntity, ServiceFailureDetector.class); assertEnricherConfigMatchesDsl(newEnricher); }
@Test public void testRebindWhenHealthyWithDslConfigReferenceParentDefault() throws Exception { runRebindWhenHealthy(catalogYamlWithDslReferenceParentDefault, appVersionedId); TestEntity newEntity = (TestEntity) Iterables.find(app().getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); ServiceFailureDetector newEnricher = assertHasEnricher(newEntity, ServiceFailureDetector.class); assertEnricherConfigMatchesDsl(newEnricher); }
@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)); }
@Test public void testGroupDetectsNewlyManagedMatchingMember() throws Exception { group.setEntityFilter(EntityPredicates.displayNameEqualTo("myname")); final Entity e3 = app.addChild(EntitySpec.create(TestEntity.class).displayName("myname")); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e3)); }}); }
@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 testRebindsToExistingApp() throws Exception { populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig")); // Rebind to the app we just started last time newLauncherDefault(PersistMode.REBIND).start(); assertOnlyApp(lastMgmt(), TestApplication.class); assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("myorig"), null), "apps="+lastMgmt().getApplications()); }
@Override public void run() { DynamicGroup group2 = app.addChild(EntitySpec.create(DynamicGroupTestManagedAndMemberAddedConcurrently.class) .configure("rescanReachedLatch", rescanReachedLatch) .configure("entityAddedReachedLatch", entityAddedReachedLatch) .configure("rescanLatch", rescanLatch) .configure("entityAddedLatch", entityAddedLatch) .configure(DynamicGroup.ENTITY_FILTER, EntityPredicates.displayNameEqualTo("e3"))); group2ref.set(group2); }});