protected void initialize() { checkState(getConfig(URL) != null ^ getConfig(URL_SENSOR) != null, "Must set exactly one of url or urlSensor: url=%s; urlSensor=%s", getConfig(URL), getConfig(URL_SENSOR)); checkState(getConfig(URL_SENSOR) != null || getConfig(URL_POST_PROCESSING) == null, "Must not set urlPostProcessing without urlSensor"); Object configValue = getConfig(URL); if (configValue != null) { url.set(configValue.toString()); } httpFeed = HttpFeed.builder() .entity(entity) .period(getConfig(PERIOD)) .baseUri(Suppliers.compose(Urls.stringToUriFunction(), AtomicReferences.supplier(url))) .poll(new HttpPollConfig<Double>(REQUEST_LATENCY_IN_SECONDS_MOST_RECENT) .onResult(MathFunctions.divide(HttpValueFunctions.latency(), 1000.0d)) .setOnException(null)) .suspended() .build(); if (getUniqueTag()==null) uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+ (getConfig(URL)!=null ? getConfig(URL) : getConfig(URL_SENSOR)); }
@Test(groups="Integration") // marked integration as it takes a wee while public void testStartSuspended() throws Exception { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forSensor(SENSOR_INT) .period(100) .onSuccess(HttpValueFunctions.responseCode())) .poll(HttpPollConfig.forSensor(SENSOR_STRING) .period(100) .onSuccess(HttpValueFunctions.stringContentsFunction())) .suspended() .build(); Asserts.continually(MutableMap.of("timeout", 500), Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(null)); int countWhenSuspended = server.getRequestCount(); feed.resume(); Asserts.eventually(Entities.attributeSupplier(entity, SENSOR_INT), Predicates.<Integer>equalTo(200)); if (server.getRequestCount() <= countWhenSuspended) Assert.fail("Request count failed to increment when feed was resumed, from "+countWhenSuspended+", still at "+server.getRequestCount()); log.info("RUN: "+countWhenSuspended+" - "+server.getRequestCount()); }
public Builder suspended() { return suspended(true); } public Builder suspended(boolean startsSuspended) {