@Test public void testContextEntityOnSubscriptionCallbackTask() { observedEntity.sensors().set(TestEntity.NAME, "myval"); entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.NAME, listener); // notify-of-initial-value should give us our entity assertListenerCalledOnceWithContextEntityEventually(listener, entity); listener.clearEvents(); // as should subsequent events observedEntity.sensors().set(TestEntity.NAME, "myval2"); assertListenerCalledOnceWithContextEntityEventually(listener, entity); listener.clearEvents(); // same for subscribing to children: context should be the subscriber entity.subscriptions().subscribeToChildren(observedEntity, TestEntity.SEQUENCE, listener); observedChildEntity.sensors().set(TestEntity.SEQUENCE, 123); assertListenerCalledOnceWithContextEntityEventually(listener, entity); }
@Test(groups="Integration") public void testSetsServiceLifecycle() { ControlledDynamicWebAppCluster cluster = app.createAndManageChild( EntitySpec.create(ControlledDynamicWebAppCluster.class) .configure("initialSize", 1) .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class)) ); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); RecordingSensorEventListener<Lifecycle> listener = new RecordingSensorEventListener<Lifecycle>(true); app.subscriptions().subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, listener); app.start(locs); Asserts.eventually(Suppliers.ofInstance(listener.getEventValues()), CollectionFunctionals.sizeEquals(2)); assertEquals(listener.getEventValues(), ImmutableList.of(Lifecycle.STARTING, Lifecycle.RUNNING), "vals="+listener.getEventValues()); listener.clearEvents(); app.stop(); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); Asserts.eventually(Suppliers.ofInstance(listener), CollectionFunctionals.sizeEquals(2)); assertEquals(listener.getEventValues(), ImmutableList.of(Lifecycle.STOPPING, Lifecycle.STOPPED), "vals="+listener.getEventValues()); }
protected Entity runTest(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(entity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector triggers event RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulate a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); listener.assertEventCount(1); listener.clearEvents(); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); listener.assertEventCount(1); return app; }