/** * Asserts sensors {@code service.isUp} is true, and that {@code service.state} is "running". * Setting these sensors is common behaviour for entities, but depends on the particular entity * implementation. */ @Beta public static void assertEntityHealthy(Entity entity) { assertAttributeEquals(entity, SERVICE_UP, true); assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertAttribute(entity, Attributes.SERVICE_STATE_EXPECTED, new Predicate<Lifecycle.Transition>() { @Override public boolean apply(Lifecycle.Transition transition) { assertNotNull(transition); return Lifecycle.RUNNING.equals(transition.getState()); } }); }
@Override public void run() { T val = assertAttribute(entity, attribute, predicate); result.set(val); }}); return result.get();
@Test public void testGroupDefaults() throws Exception { group = app.addChild(EntitySpec.create(SequenceGroup.class)); createTestEntities(); app.start(ImmutableList.of(loc1)); assertAttributeEqualsEventually(group, SequenceGroup.RUNNING, true); assertAttribute(group, SequenceGroup.SEQUENCE_VALUE, Predicates.isNull()); assertTrue(group.getMembers().isEmpty()); }
@Test public void testAddsConditionalAndPropagatesSensors() throws Exception { optional = app.addChild(EntitySpec.create(ConditionalEntity.class) .configure(ConditionalEntity.CREATE_CONDITIONAL_ENTITY, true) .configure(ConditionalEntity.PROPAGATE_CONDITIONAL_ENTITY_SENSORS, true) .configure(ConditionalEntity.CONDITIONAL_ENTITY_SENSOR_LIST, ImmutableList.<AttributeSensor<?>>of(TestEntity.SEQUENCE)) .configure(ConditionalEntity.CONDITIONAL_ENTITY_SPEC, EntitySpec.create(TestEntity.class))); app.start(ImmutableList.of(loc1)); assertEquals(optional.getChildren().size(), 1); Entity child = Iterables.getOnlyElement(optional.getChildren()); assertTrue(child instanceof TestEntity); assertEquals(child, optional.sensors().get(ConditionalEntity.CONDITIONAL_ENTITY)); // Check that the configured sensors are propagated child.sensors().set(TestEntity.SEQUENCE, 123); EntityAsserts.assertAttributeEqualsEventually(child, TestEntity.SEQUENCE, 123); EntityAsserts.assertAttributeEqualsEventually(optional, TestEntity.SEQUENCE, 123); child.sensors().set(TestEntity.NAME, "frog"); EntityAsserts.assertAttributeEqualsEventually(child, TestEntity.NAME, "frog"); EntityAsserts.assertAttribute(optional, TestEntity.NAME, Predicates.isNull()); }
@Test public void shouldAssertAttribute() { final String before = "before"; entity.sensors().set(TestEntity.NAME, before); EntityAsserts.assertAttribute(entity, TestEntity.NAME, Predicates.equalTo(before)); }
@Override public void run() { assertNotNull(cassandra.getAttribute(CassandraNode.TOKENS)); assertEquals(cassandra.getAttribute(CassandraNode.TOKENS).size(), 256, "tokens="+cassandra.getAttribute(CassandraNode.TOKENS)); assertEquals(cassandra.getAttribute(CassandraNode.PEERS), (Integer)256); assertEquals(cassandra.getAttribute(CassandraNode.LIVE_NODE_COUNT), (Integer)1); assertTrue(cassandra.getAttribute(CassandraNode.SERVICE_UP_JMX)); assertNotNull(cassandra.getAttribute(CassandraNode.THRIFT_PORT_LATENCY)); assertNotNull(cassandra.getAttribute(CassandraNode.READ_PENDING)); assertNotNull(cassandra.getAttribute(CassandraNode.READ_ACTIVE)); EntityAsserts.assertAttribute(cassandra, CassandraNode.READ_COMPLETED, MathPredicates.greaterThanOrEqual(1)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITE_PENDING)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITE_ACTIVE)); EntityAsserts.assertAttribute(cassandra, CassandraNode.WRITE_COMPLETED, MathPredicates.greaterThanOrEqual(1)); assertNotNull(cassandra.getAttribute(CassandraNode.READS_PER_SECOND_LAST)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITES_PER_SECOND_LAST)); assertNotNull(cassandra.getAttribute(CassandraNode.THRIFT_PORT_LATENCY_IN_WINDOW)); assertNotNull(cassandra.getAttribute(CassandraNode.READS_PER_SECOND_IN_WINDOW)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITES_PER_SECOND_IN_WINDOW)); // an example MXBean EntityAsserts.assertAttribute(cassandra, CassandraNode.MAX_HEAP_MEMORY, MathPredicates.greaterThanOrEqual(1)); }});