@Override public void run() { assertAttributeEquals(entity, attribute, expected); } });
@Test public void testSequenceInitialConfig() throws Exception { sequence = app.addChild(EntitySpec.create(SequenceEntity.class) .configure(SequenceEntity.SEQUENCE_START, 42)); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true); assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 42); }
@Test(groups={"Integration", "Broken"}) public void testCanStartAndStop() throws Exception { BrooklynNode brooklynNode = app.createAndManageChild(newBrooklynNodeSpecForTest()); app.start(locs); log.info("started "+app+" containing "+brooklynNode+" for "+JavaClassNames.niceClassAndMethod()); EntityAsserts.assertAttributeEqualsEventually(brooklynNode, BrooklynNode.SERVICE_UP, true); brooklynNode.stop(); EntityAsserts.assertAttributeEquals(brooklynNode, BrooklynNode.SERVICE_UP, false); }
/** * Asserts sensors {@code service.isUp} is false, and that {@code service.state} is "on fire". * Setting these sensors is common behaviour for entities, but depends on the particular entity * implementation. */ @Beta public static void assertEntityFailed(Entity entity) { assertAttributeEquals(entity, SERVICE_UP, false); assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); }
@Test public void testSequenceIncrementAndGetEffector() throws Exception { sequence = app.addChild(EntitySpec.create(SequenceEntity.class)); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true); assertEquals(sequence.get(), Integer.valueOf(1)); Integer nextValue = sequence.invoke(SequenceEntity.INCREMENT_AND_GET, ImmutableMap.<String, Object>of()).getUnchecked(); assertEquals(nextValue, Integer.valueOf(2)); nextValue = sequence.invoke(SequenceEntity.INCREMENT_AND_GET, ImmutableMap.<String, Object>of()).getUnchecked(); assertEquals(nextValue, Integer.valueOf(3)); assertEquals(sequence.get(), Integer.valueOf(3)); assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 3); }
@Test public void testMainUriSensorsCorrectlyComputedWithDomain() throws Exception { URI expected = URI.create("http://mydomain:8000/"); EntityAsserts.assertAttributeEquals(controller, TrackingAbstractController.MAIN_URI, expected); EntityAsserts.assertAttributeEquals(controller, TrackingAbstractController.MAIN_URI_MAPPED_SUBNET, expected); EntityAsserts.assertAttributeEquals(controller, TrackingAbstractController.MAIN_URI_MAPPED_PUBLIC, expected); }
/** * Test that a node starts and sets SERVICE_UP correctly. */ @Test(groups = {"Integration", "WIP"}) public void canStartupAndShutdown() { couchdb = app.createAndManageChild(EntitySpec.create(CouchDBNode.class) .configure("httpPort", "8000+")); app.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(couchdb, Startable.SERVICE_UP, true); couchdb.stop(); EntityAsserts.assertAttributeEquals(couchdb, Startable.SERVICE_UP, false); }
@Override public void run() { EntityAsserts.assertAttributeEquals(app, TEST_SENSOR, lastSeenState.get()); } });
@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); }
@Override public void run() { for (Entity entity : Entities.descendantsAndSelf(app)) { assertNotEquals(entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); assertNotEquals(entity.getAttribute(Attributes.SERVICE_UP), false); if (entity instanceof SoftwareProcess) { EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_UP, Boolean.TRUE); } } }}); }
@Test public void shouldAssertAttributeEquals() { final String myName = "myname"; entity.sensors().set(TestEntity.NAME, myName); EntityAsserts.assertAttributeEquals(entity, TestEntity.NAME, myName); }
private static <T> void assertAttributeEquals(Entity x, AttributeSensor<T> sensor, T value) { try { EntityAsserts.assertAttributeEquals(x, sensor, value); } catch (Throwable e) { log.warn("Expected "+x+" to have "+sensor+" = "+value+"; instead:"); Entities.dumpInfo(x); throw Exceptions.propagate(e); } }
@Test(expectedExceptions = AssertionError.class) public void shouldFailToAssertAttributeEquals() { final String myName = "myname"; entity.sensors().set(TestEntity.NAME, myName); EntityAsserts.assertAttributeEquals(entity, TestEntity.NAME, "bogus"); }
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); }}); }
private void createNodeAndExecStopEffector(Effector<?> eff) throws Exception { BrooklynNode brooklynNode = setUpBrooklynNodeWithApp(); File pidFile = new File(getDriver(brooklynNode).getPidFile()); assertTrue(isPidRunning(pidFile)); brooklynNode.invoke(eff, Collections.<String, Object>emptyMap()).getUnchecked(); // Note can't use driver.isRunning to check shutdown; can't invoke scripts on an unmanaged entity EntityAsserts.assertAttributeEquals(brooklynNode, BrooklynNode.SERVICE_UP, false); // unmanaged if the machine is destroyed - ie false on localhost (this test by default), but true in the cloud // assertFalse(Entities.isManaged(brooklynNode)); assertFalse(isPidRunning(pidFile), "pid in "+pidFile+" still running"); }
@Test public void testStartsWhenNoStartableChildren() { BasicStartable startable = app.createAndManageChild(EntitySpec.create(BasicStartable.class) .child(EntitySpec.create(BasicEntity.class))); app.start(ImmutableList.of(app.newSimulatedLocation())); EntityAsserts.assertAttributeEquals(startable, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }
@Test public void shouldAssertAttributeEventuallyNonNull() throws Exception { EntityAsserts.assertAttributeEquals(entity, TestEntity.NAME, null); Task<?> assertValue = entity.getExecutionContext().submit(new Runnable() { @Override public void run() { EntityAsserts.assertAttributeEventuallyNonNull(entity, TestEntity.NAME); } }); entity.sensors().set(TestEntity.NAME, "something"); assertValue.get(); }
@Test public void testIgnoresWhenNoMapping() throws Exception { // Creates associate for a non-matching port entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(Attributes.HTTP_PORT, 1234); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 4321); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTP_PORT))); EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(Attributes.HTTP_PORT.getName()+".mapped.public"), null); }
@Test public void testIgnoresWhenNoMachine() throws Exception { // Does not call entity.addLocation entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(Attributes.HTTP_PORT, 1234); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTP_PORT))); EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(Attributes.HTTP_PORT.getName()+".mapped.public"), null); }
@Test public void testHandlesReferencingOtherEntities() throws Exception { MyEntity origOtherE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class)); MyEntityReffingOthers origE = origApp.createAndManageChild(EntitySpec.create(MyEntityReffingOthers.class) .configure("entityRef", origOtherE)); origE.sensors().set(MyEntityReffingOthers.ENTITY_REF_SENSOR, origOtherE); newApp = rebind(); MyEntityReffingOthers newE = (MyEntityReffingOthers) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntityReffingOthers.class)); MyEntity newOtherE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); EntityAsserts.assertAttributeEquals(newE, MyEntityReffingOthers.ENTITY_REF_SENSOR, newOtherE); EntityAsserts.assertConfigEquals(newE, MyEntityReffingOthers.ENTITY_REF_CONFIG, newOtherE); }