@Override public void run() { // TODO In tests, have seen duplicate "starting"; and always begins with "stopped"; and have // seen "on-fire" between stopping and stopped! Therefore not using // assertEqualsOrderIgnoringDuplicates. List<Lifecycle> states = ImmutableList.copyOf(listener.getEventValues()); assertContainsOrdered(states, ImmutableList.of(Lifecycle.RUNNING, Lifecycle.STOPPING, Lifecycle.STOPPED)); }}); }
private <T> List<T> getServiceStateEvents(RecordingSensorEventListener<T> listener) { if (stateListener == null) { return ImmutableList.of(); } else { return MutableList.copyOf(listener.getEventValues()).asUnmodifiable(); } }
@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()); }
@Test public void testUpdateMapEmitsEventOnChange() throws Exception { Entity entity = app.createAndManageChild(EntitySpec.create(BasicApplication.class) .enricher(EnricherSpec.create(UpdatingMap.class) .configure(UpdatingMap.SOURCE_SENSOR.getName(), mySensor.getName()) .configure(UpdatingMap.TARGET_SENSOR, mapSensor) .configure(UpdatingMap.KEY_IN_TARGET_SENSOR, "myKey") .configure(UpdatingMap.COMPUTING, Functions.forMap(MutableMap.of("v1", "valIsV1", "v2", "valIsV2"), "myDefault")))); EntityAsserts.assertAttributeEqualsEventually(entity, mapSensor, ImmutableMap.of("myKey", "myDefault")); RecordingSensorEventListener<Map<String, Object>> listener = new RecordingSensorEventListener<>(); app.subscriptions().subscribe(entity, mapSensor, listener); entity.sensors().set(mySensor, "v1"); EntityAsserts.assertAttributeEqualsEventually(entity, mapSensor, ImmutableMap.of("myKey", "valIsV1")); listener.assertHasEventEventually(Predicates.alwaysTrue()); assertEquals(Iterables.getOnlyElement(listener.getEventValues()), ImmutableMap.of("myKey", "valIsV1")); }