@Test public void testPropagatorFailsWithEmptyConfig() throws Exception { EnricherSpec<?> spec = EnricherSpec.create(Propagator.class); assertAddEnricherThrowsIllegalStateException(spec, "must have"); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception{ super.setUp(); enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class)); }
@Test public void testRebindWithFailingEnricherContinuesWithoutEnricher() throws Exception { origApp.enrichers().add(EnricherSpec.create(MyEnricherFailingImpl.class) .configure(MyEnricherFailingImpl.FAIL_ON_REBIND, true)); newApp = rebind(); Optional<Enricher> newEnricher = Iterables.tryFind(newApp.enrichers(), Predicates.instanceOf(MyEnricherFailingImpl.class)); assertFalse(newEnricher.isPresent(), "enricher="+newEnricher); }
@Test public void testConfigCannotBeSetAfterApplicationIsStarted() throws Exception { MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class) .configure(MyEnricher.STR_KEY, "origval")); try { enricher.config().set(MyEnricher.STR_KEY,"newval"); fail(); } catch (UnsupportedOperationException e) { // success } assertEquals(enricher.getConfig(MyEnricher.STR_KEY), "origval"); }
protected void activateAdditionalEnrichers(EntityLocal entity) { Duration rollupWindowSize = getConfig(ROLLUP_WINDOW_SIZE); if (rollupWindowSize!=null) { entity.enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class) .configure("producer", entity) .configure("source", REQUEST_LATENCY_IN_SECONDS_MOST_RECENT) .configure("target", REQUEST_LATENCY_IN_SECONDS_IN_WINDOW) .configure("timePeriod", rollupWindowSize)); } }
@Test public void testReboundConfigDoesNotContainId() throws Exception { MyEnricher policy = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class)); newApp = rebind(); MyEnricher newEnricher = (MyEnricher) Iterables.getOnlyElement(newApp.enrichers()); assertNull(newEnricher.getConfig(ConfigKeys.newStringConfigKey("id"))); assertEquals(newEnricher.getId(), policy.getId()); }
@Test public void testSameUniqueTagEnricherNotAddedTwice() throws Exception { MyEnricher enricher1 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x")); MyEnricher enricher2 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(94).uniqueTag("x")); // the more recent one should dominate assertEquals(app.enrichers().asList(), ImmutableList.of(enricher2)); Enricher enricher = Iterables.getOnlyElement(app.enrichers()); Assert.assertTrue(enricher.tags().containsTag(94)); Assert.assertFalse(enricher.tags().containsTag(99)); }
@Test public void testIgnoresWhenNoSubnetAddress() throws Exception { entity.sensors().set(Attributes.HTTP_PORT, 1234); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTP_PORT))); EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", VERY_SHORT_WAIT), entity, Sensors.newStringSensor(Attributes.HTTP_PORT.getName()+".mapped.subnet"), null); }
@Test public <T> void testCoercesSensorName() throws Exception { AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor"); entity.sensors().set(sensor, "127.0.0.1:1234"); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS.getName(), ImmutableList.of("mysensor"))); assertAttributeEqualsEventually("mysensor.mapped.public", "mypublichost:5678"); }
@Test public void testReportsFailureWhenAlreadyDownOnRegisteringPolicy() throws Exception { ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); e1.sensors().set(TestEntity.SERVICE_UP, false); e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.ENTITY_FAILED_ONLY_IF_PREVIOUSLY_UP, false)); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null); }
@Override protected void initEnrichers() { // Deliberately not calling `super.initEnrichers()`. For our state (i.e. "service.state" // and "service.isUp"), we rely on the `serviceStateComputer`. This keeps things a lot // simpler. However, it means that if someone manually sets a "service.notUp.indicators" // or "service.problems" then that won't cause the entity to transition to false or ON_FIRE. enrichers().add(EnricherSpec.create(ServiceStateComputer.class) .configure(ServiceStateComputer.FROM_CHILDREN, true) .configure(ServiceStateComputer.UP_QUORUM_CHECK, config().get(UP_QUORUM_CHECK)) .configure(ServiceStateComputer.RUNNING_QUORUM_CHECK, config().get(RUNNING_QUORUM_CHECK))); }
@Test(dataProvider = "invalidVariants") public <T> void testIgnoresWhenInvalidAttribute(AttributeSensor<T> sensor, T sensorVal) throws Exception { entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(sensor, sensorVal); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class) .configure(OnSubnetNetworkEnricher.SENSORS, ImmutableList.of(sensor))); EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", VERY_SHORT_WAIT), entity, Sensors.newStringSensor(sensor.getName()+".mapped.subnet"), null); }
@Test public void testIgnoresWhenNoMapping() throws Exception { // Creates associate for a non-matching port entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(Attributes.HTTP_PORT, 1234); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 4321); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.HTTP_PORT))); EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(Attributes.HTTP_PORT.getName()+".mapped.public"), null); }
@Test public void testPolicyTags() throws Exception { Enricher origEnricher = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class)); origEnricher.tags().addTag("foo"); origEnricher.tags().addTag(origApp); newApp = rebind(); Enricher newEnricher = Iterables.getOnlyElement(newApp.enrichers()); Asserts.assertEqualsIgnoringOrder(newEnricher.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test(groups="Integration") // Has a 1 second wait public void testOnlyReportsFailureIfRunning() throws Exception { e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); // Make the entity fail ServiceStateLogic.setExpectedState(e1, Lifecycle.STARTING); e1.sensors().set(TestEntity.SERVICE_UP, true); e1.sensors().set(TestEntity.SERVICE_UP, false); assertNoEventsContinually(); }
@Override public void onManagementStarting() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("y").tag(Identifiers.makeRandomId(8))); } @Override
@Override public void onManagementStarted() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("z").tag(Identifiers.makeRandomId(8))); // all the enrichers above should not be added on rebind, but this one will be: enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag( Identifiers.makeRandomId(8) ).tag(Identifiers.makeRandomId(8))); } }
@Test(groups="Broken") public <T> void testTransformsWithDefaultPorts() throws Exception { AttributeSensor<String> stringUriWithHttpNoPort = Sensors.newStringSensor("string.uriWithHttpNoPort"); AttributeSensor<String> stringUriWithHttpsNoPort = Sensors.newStringSensor("string.uriWithHttpsNoPort"); entity.sensors().set(Attributes.SUBNET_ADDRESS, privateIp); entity.sensors().set(stringUriWithHttpNoPort, "http://"+publicIp+"/my/path"); entity.sensors().set(stringUriWithHttpsNoPort, "https://"+publicIp+"/my/path"); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class)); assertAttributeEqualsEventually("string.uriWithHttpNoPort.mapped.subnet", "http://"+privateIp+"/my/path"); assertAttributeEqualsEventually("string.uriWithHttpsNoPort.mapped.subnet", "https://"+privateIp+"/my/path"); }
@Test public void testDeltaEnricher() throws Exception { origApp.enrichers().add(EnricherSpec.create(DeltaEnricher.class) .configure("producer", origApp) .configure("source", INT_METRIC) .configure("target", INT_METRIC2)); TestApplication newApp = rebind(); newApp.sensors().set(INT_METRIC, 1); newApp.sensors().set(INT_METRIC, 10); EntityAsserts.assertAttributeEqualsEventually(newApp, INT_METRIC2, 9); }