You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/08/01 18:47:38 UTC
[4/9] git commit: add failing test for enrichers being added multiple
times on rebind
add failing test for enrichers being added multiple times on rebind
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/d135df40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/d135df40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/d135df40
Branch: refs/heads/master
Commit: d135df402c3b93f69772418babec004678cebd94
Parents: e6b7af4
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Jul 31 02:14:27 2014 -0400
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Jul 31 02:15:30 2014 -0400
----------------------------------------------------------------------
.../entity/java/VanillaJavaAppRebindTest.java | 59 +++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d135df40/software/base/src/test/java/brooklyn/entity/java/VanillaJavaAppRebindTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/brooklyn/entity/java/VanillaJavaAppRebindTest.java b/software/base/src/test/java/brooklyn/entity/java/VanillaJavaAppRebindTest.java
index 19d6082..7ba7e36 100644
--- a/software/base/src/test/java/brooklyn/entity/java/VanillaJavaAppRebindTest.java
+++ b/software/base/src/test/java/brooklyn/entity/java/VanillaJavaAppRebindTest.java
@@ -24,20 +24,26 @@ import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import brooklyn.enricher.RollingTimeWindowMeanEnricher;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.java.JavaOptsTest.TestingJavaOptsVanillaJavaAppImpl;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.rebind.RebindTestUtils;
+import brooklyn.event.AttributeSensor;
+import brooklyn.event.basic.Sensors;
import brooklyn.location.basic.LocalhostMachineProvisioningLocation;
import brooklyn.management.internal.LocalManagementContext;
import brooklyn.test.EntityTestUtils;
import brooklyn.test.entity.TestApplication;
import brooklyn.util.ResourceUtils;
import brooklyn.util.collections.MutableMap;
+import brooklyn.util.time.Duration;
+import brooklyn.util.time.Time;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
@@ -113,7 +119,58 @@ public class VanillaJavaAppRebindTest {
VanillaJavaApp javaProcess2 = (VanillaJavaApp) Iterables.find(app.getChildren(), Predicates.instanceOf(VanillaJavaApp.class));
EntityTestUtils.assertAttributeEqualsEventually(javaProcess2, VanillaJavaApp.SERVICE_UP, false);
- // check that it was quick (previously it hung for
+ // check that it was quick (previously it hung)
assertTrue(rebindTime < 30*1000, "rebindTime="+rebindTime);
}
+
+
+ @Test(groups="Integration")
+ public void testEnrichersOnRebindJavaApp() throws Exception {
+ VanillaJavaApp javaProcess = app.addChild(EntitySpec.create(VanillaJavaApp.class, EnrichedVanillaJavaAppImpl.class)
+ .configure("main", MAIN_CLASS.getCanonicalName()).configure("classpath", ImmutableList.of(BROOKLYN_THIS_CLASSPATH)));
+
+ Entities.manage(javaProcess);
+ app.start(ImmutableList.of(loc));
+
+ EntityTestUtils.assertAttributeEventuallyNonNull(javaProcess, EnrichedVanillaJavaAppImpl.AVG1);
+ EntityTestUtils.assertAttributeEventuallyNonNull(javaProcess, EnrichedVanillaJavaAppImpl.AVG2);
+ LOG.info("Got avg "+javaProcess.getAttribute(EnrichedVanillaJavaAppImpl.AVG1));
+
+ rebind();
+ VanillaJavaApp javaProcess2 = (VanillaJavaApp) Iterables.find(app.getChildren(), Predicates.instanceOf(VanillaJavaApp.class));
+
+ // check sensors working
+ EntityTestUtils.assertAttributeEventually(javaProcess2, EnrichedVanillaJavaAppImpl.PROCESS_CPU_TIME,
+ Predicates.not(Predicates.equalTo(javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.PROCESS_CPU_TIME))));
+ LOG.info("Avg now "+javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG1));
+
+ // check enrichers are functioning
+ EntityTestUtils.assertAttributeEventually(javaProcess2, EnrichedVanillaJavaAppImpl.AVG1,
+ Predicates.not(Predicates.equalTo(javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG1))));
+ EntityTestUtils.assertAttributeEventually(javaProcess2, EnrichedVanillaJavaAppImpl.AVG2,
+ Predicates.not(Predicates.equalTo(javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG2))));
+ LOG.info("Avg now "+javaProcess2.getAttribute(EnrichedVanillaJavaAppImpl.AVG1));
+
+ // and check we don't have too many
+ Assert.assertEquals(javaProcess2.getEnrichers().size(), javaProcess.getEnrichers().size());
+ }
+
+ public static class EnrichedVanillaJavaAppImpl extends VanillaJavaAppImpl {
+ private static final AttributeSensor<Double> AVG1 = Sensors.newDoubleSensor("avg1");
+ private static final AttributeSensor<Double> AVG2 = Sensors.newDoubleSensor("avg2");
+
+ @Override
+ public void onManagementStarted() {
+ super.onManagementStarted();
+ LOG.info("mgmt started for "+this);
+ addEnricher(new RollingTimeWindowMeanEnricher<Double>(this, PROCESS_CPU_TIME, AVG1, Duration.TEN_SECONDS));
+ }
+ @Override
+ protected void connectSensors() {
+ super.connectSensors();
+ LOG.info("connecting sensors for "+this);
+ addEnricher(new RollingTimeWindowMeanEnricher<Double>(this, PROCESS_CPU_TIME, AVG2, Duration.TEN_SECONDS));
+ }
+ }
+
}