@Test public void testSummingEnricherWhenNoSensorValuesYet() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromHardcodedProducers(ImmutableList.of(entity)) .defaultValueForUnreportedSensors(11) .valueToReportIfNoSensors(40) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 11); }
@Test public void testSummingEnricherWithNoProducers() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromChildren() .defaultValueForUnreportedSensors(11) .valueToReportIfNoSensors(40) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 40); }
.fromMembers() .publishing(MachineAttributes.AVERAGE_CPU_USAGE) .valueToReportIfNoSensors(0d) .build()); hosts.enrichers().add(Enrichers.builder()
@Test public void testAggregatesNewMembersOfGroup() { BasicGroup group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); TestEntity p1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity p2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); log.debug("created {} and the entities it will contain {} {}", new Object[] {group, p1, p2}); group.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromMembers() .defaultValueForUnreportedSensors(0) .valueToReportIfNoSensors(0) .build()); EntityAsserts.assertAttributeEqualsEventually(group, target, 0); group.addMember(p1); p1.sensors().set(intSensor, 1); EntityAsserts.assertAttributeEqualsEventually(group, target, 1); group.addMember(p2); p2.sensors().set(intSensor, 2); EntityAsserts.assertAttributeEqualsEventually(group, target, 3); group.removeMember(p2); EntityAsserts.assertAttributeEqualsEventually(group, target, 1); }
@Test public void testMultipleProducersAverageDefaultingZero() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity producer3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1, producer2, producer3)) .defaultValueForUnreportedSensors(0) .valueToReportIfNoSensors(0) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 0d); producer1.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 1d); producer2.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 2d); producer3.sensors().set(intSensor, 3); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); }
@Test public void testAggregatesNewChidren() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromChildren() .defaultValueForUnreportedSensors(0) .valueToReportIfNoSensors(0) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 0); TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); p1.sensors().set(intSensor, 1); EntityAsserts.assertAttributeEqualsEventually(entity, target, 1); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); p2.sensors().set(intSensor, 2); EntityAsserts.assertAttributeEqualsEventually(entity, target, 3); Entities.unmanage(p2); EntityAsserts.assertAttributeEqualsEventually(entity, target, 1); }
@Test public void testSummingEnricherWhenDefaultValueForUnreportedSensors() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromHardcodedProducers(ImmutableList.of(entity)) .defaultValueForUnreportedSensors(3) .valueToReportIfNoSensors(5) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 3); entity.sensors().set(intSensor, null); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, target, 3); entity.sensors().set(intSensor, 1); EntityAsserts.assertAttributeEqualsEventually(entity, target, 1); entity.sensors().set(intSensor, 7); EntityAsserts.assertAttributeEqualsEventually(entity, target, 7); }
@Test public void testAveragingEnricherWhenDefaultValueForUnreportedSensors() { TestEntity producer1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromHardcodedProducers(ImmutableList.of(producer1)) .defaultValueForUnreportedSensors(3) .valueToReportIfNoSensors(5) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 3d); producer1.sensors().set(intSensor, null); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 50), entity, doubleSensor, 3d); producer1.sensors().set(intSensor, 4); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 4d); }
@Test public void testAveragingEnricherWhenNoSensors() { entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(doubleSensor) .computingAverage() .fromChildren() .defaultValueForUnreportedSensors(3) .valueToReportIfNoSensors(5) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, doubleSensor, 5d); }
@Override public void init() { super.init(); enrichers().add(Enrichers.builder() .aggregating(Changeable.GROUP_SIZE) .publishing(FABRIC_SIZE) .fromMembers() .computingSum() .valueToReportIfNoSensors(0) .build()); sensors().set(SERVICE_UP, false); }