@Test public void testAggregatingMembersEnricher() throws Exception { origApp.start(ImmutableList.of(origLoc)); origCluster.resize(2); origApp.addEnricher( Enrichers.builder() .aggregating(METRIC1) .from(origCluster) .fromMembers() .computing(StringFunctions.joiner(",")) .publishing(METRIC2) .build()); TestApplication newApp = rebind(); DynamicCluster newCluster = (DynamicCluster) Iterables.find(newApp.getChildren(), Predicates.instanceOf(DynamicCluster.class)); int i = 1; for (Entity member : newCluster.getMembers()) { ((EntityInternal) member).setAttribute(METRIC1, "myval" + (i++)); } EntityTestUtils.assertAttributeEventually( newApp, METRIC2, Predicates.or(Predicates.equalTo("myval1,myval2"), Predicates.equalTo("myval2,myval1"))); }
@SuppressWarnings("unchecked") @Test public void testCombiningEnricher() throws Exception { origApp.addEnricher( Enrichers.builder() .combining(METRIC1, METRIC2) .from(origEntity) .computing(StringFunctions.joiner(",")) .publishing(METRIC2) .build()); TestApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.setAttribute(METRIC1, "myval"); newEntity.setAttribute(METRIC2, "myval2"); EntityTestUtils.assertAttributeEventually( newApp, METRIC2, Predicates.or(Predicates.equalTo("myval,myval2"), Predicates.equalTo("myval2,myval"))); }