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; }
protected void runRebindWhenHealthy(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); createStartWaitAndLogApplication(appYaml); // Rebind StartableApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(newEntity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector still functions RecordingSensorEventListener<Object> listener = subscribeToHaSensors(newEntity); ServiceNotUpLogic.updateNotUpIndicator(newEntity, INDICATOR_KEY_1, "Simulate a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); listener.assertEventCount(1); }
protected void runRebindWhenNotUp(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); // Make entity go on-fire TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulating a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); // Rebind StartableApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(newEntity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector still functions RecordingSensorEventListener<Object> newListener = subscribeToHaSensors(newEntity); ServiceNotUpLogic.clearNotUpIndicator(newEntity, INDICATOR_KEY_1); newListener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); newListener.assertEventCount(1); }
@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")); }
listener.assertHasEventEventually(Predicates.alwaysTrue());
@Test(groups="Integration") public void testSupressingDuplicates() throws Exception { AttributeSensor<String> mySensor = Sensors.newStringSensor("mysensor"); RecordingSensorEventListener<String> listener = new RecordingSensorEventListener<>(); app().subscriptions().subscribe(null, mySensor, listener); RecordingWinRmTool.setCustomResponse(".*mycommand.*", new RecordingWinRmTool.CustomResponse(0, "myval", "")); Entity entity = app().createAndManageChild(EntitySpec.create(TestEntity.class) .addInitializer(new WinRmCommandSensor<String>(ConfigBag.newInstance(ImmutableMap.of( HttpRequestSensor.SUPPRESS_DUPLICATES, true, WinRmCommandSensor.SENSOR_PERIOD, "1ms", WinRmCommandSensor.SENSOR_COMMAND, "mycommand", WinRmCommandSensor.SENSOR_NAME, mySensor.getName()))))); app().start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(entity, mySensor, "myval"); listener.assertHasEventEventually(Predicates.alwaysTrue()); Asserts.succeedsContinually(new Runnable() { @Override public void run() { listener.assertEventCount(1); }}); } }
@Test(groups="Integration") @SuppressWarnings("deprecation") public void testHttpSensorSuppressingDuplicates() throws Exception { RecordingSensorEventListener<String> listener = new RecordingSensorEventListener<>(); entity.subscriptions().subscribe(entity, SENSOR_STRING, listener); HttpRequestSensor<Integer> sensor = new HttpRequestSensor<Integer>(ConfigBag.newInstance() .configure(HttpRequestSensor.SUPPRESS_DUPLICATES, true) .configure(HttpRequestSensor.SENSOR_PERIOD, Duration.millis(1)) .configure(HttpRequestSensor.SENSOR_NAME, SENSOR_STRING.getName()) .configure(HttpRequestSensor.SENSOR_TYPE, STRING_TARGET_TYPE) .configure(HttpRequestSensor.JSON_PATH, "$.myKey") .configure(HttpRequestSensor.SENSOR_URI, serverUrl + "/myKey/myValue")); sensor.apply((org.apache.brooklyn.api.entity.EntityLocal)entity); entity.sensors().set(Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_STRING, "myValue"); listener.assertHasEventEventually(Predicates.alwaysTrue()); Asserts.succeedsContinually(new Runnable() { @Override public void run() { listener.assertEventCount(1); }}); }
listener.assertHasEventEventually(Predicates.alwaysTrue());