@Test(timeout = 10000) public void scrape_without_contentlength() throws Exception { final HttpRequest REQUEST = HttpRequest.request("/scrapeWCL") .withMethod("GET"); final UrlGetCollector collector = endpoint("/scrapeWCL"); mockServerClient .when(REQUEST) .respond(HttpResponse.response("chocoladevla") .withConnectionOptions(ConnectionOptions.connectionOptions().withSuppressContentLengthHeader(true).withCloseSocket(true))); Collection<MetricGroup> groups = GroupGenerator.deref(collector.getGroups(threadpool, new CompletableFuture<>())); mockServerClient.verify(REQUEST, VerificationTimes.once()); assertThat(groups.stream().map(MetricGroup::getName).collect(Collectors.toList()), Matchers.contains(GroupName.valueOf("test"))); final Map<MetricName, MetricValue> metrics = Arrays.stream(groups.stream() .filter(mg -> mg.getName().equals(GroupName.valueOf("test"))) .findFirst() .get() .getMetrics() ) .collect(Collectors.toMap(Metric::getName, Metric::getValue)); System.err.println(metrics); assertThat(metrics, allOf( hasEntry(MetricName.valueOf("up"), MetricValue.TRUE), hasEntry(MetricName.valueOf("content", "length"), MetricValue.fromIntValue(12)))); }
@Override public Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout) throws Exception { CompletableFuture<Stream<Metric>> timeoutMetric = timeout .thenApply(ignored -> { return Stream.of(new SimpleMetric(MN_UP, MetricValue.FALSE)); }); final List<CompletableFuture<? extends Collection<? extends MetricGroup>>> urls; try { return patterns.getUrls() .map(x -> { CompletableFuture<Stream<Metric>> reqMetrics = do_request_(x.getKey(), x.getValue()); return reqMetrics.applyToEither( timeoutMetric, metrics -> { final GroupName groupName = groupNameFromArgs(x.getKey()); return singleton(new SimpleMetricGroup(groupName, metrics)); }); }) .collect(Collectors.toList()); } catch (Exception ex) { throw new Exception("unable to load URLs", ex); } }
UrlGetCollector implements GroupGenerator { @Override public Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout) throws Exception { CompletableFuture<Stream<Metric>> timeoutMetric = timeout .thenApply(ignored -> { return Stream.of(new SimpleMetric(MN_UP, MetricValue.FALSE)); }); final List<CompletableFuture<? extends Collection<? extends MetricGroup>>> urls; try { return patterns.getUrls() .map(x -> { CompletableFuture<Stream<Metric>> reqMetrics = do_request_(x.getKey(), x.getValue()); return reqMetrics.applyToEither( timeoutMetric, metrics -> { final GroupName groupName = groupNameFromArgs(x.getKey()); return singleton(new SimpleMetricGroup(groupName, metrics)); }); }) .collect(Collectors.toList()); } catch (Exception ex) { throw new Exception("unable to load URLs", ex); } } }
UrlGetCollector implements GroupGenerator { @Override public Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout) throws Exception { CompletableFuture<Stream<Metric>> timeoutMetric = timeout .thenApply(ignored -> { return Stream.of(new SimpleMetric(MN_UP, MetricValue.FALSE)); }); final List<CompletableFuture<? extends Collection<? extends MetricGroup>>> urls; try { return patterns.getUrls() .map(x -> { CompletableFuture<Stream<Metric>> reqMetrics = do_request_(x.getKey(), x.getValue()); return reqMetrics.applyToEither( timeoutMetric, metrics -> { final GroupName groupName = groupNameFromArgs(x.getKey()); return singleton(new SimpleMetricGroup(groupName, metrics)); }); }) .collect(Collectors.toList()); } catch (Exception ex) { throw new Exception("unable to load URLs", ex); } } UrlGetCollector(SimpleGroupPath base_group_name, UrlPattern patterns); }
UrlGetCollector implements GroupGenerator { @Override public Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout) throws Exception { CompletableFuture<Stream<Metric>> timeoutMetric = timeout .thenApply(ignored -> { return Stream.of(new SimpleMetric(MN_UP, MetricValue.FALSE)); }); final List<CompletableFuture<? extends Collection<? extends MetricGroup>>> urls; try { return patterns.getUrls() .map(x -> { CompletableFuture<Stream<Metric>> reqMetrics = do_request_(x.getKey(), x.getValue()); return reqMetrics.applyToEither( timeoutMetric, metrics -> { final GroupName groupName = groupNameFromArgs(x.getKey()); return singleton(new SimpleMetricGroup(groupName, metrics)); }); }) .collect(Collectors.toList()); } catch (Exception ex) { throw new Exception("unable to load URLs", ex); } } UrlGetCollector(SimpleGroupPath base_group_name, UrlPattern patterns); @Override Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout); }
UrlGetCollector implements GroupGenerator { @Override public Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout) throws Exception { CompletableFuture<Stream<Metric>> timeoutMetric = timeout .thenApply(ignored -> { return Stream.of(new SimpleMetric(MN_UP, MetricValue.FALSE)); }); final List<CompletableFuture<? extends Collection<? extends MetricGroup>>> urls; try { return patterns.getUrls() .map(x -> { CompletableFuture<Stream<Metric>> reqMetrics = do_request_(x.getKey(), x.getValue()); return reqMetrics.applyToEither( timeoutMetric, metrics -> { final GroupName groupName = groupNameFromArgs(x.getKey()); return singleton(new SimpleMetricGroup(groupName, metrics)); }); }) .collect(Collectors.toList()); } catch (Exception ex) { throw new Exception("unable to load URLs", ex); } } UrlGetCollector(SimpleGroupPath base_group_name, UrlPattern patterns); @Override Collection<CompletableFuture<? extends Collection<? extends MetricGroup>>> getGroups(Executor threadpool, CompletableFuture<TimeoutObject> timeout); static final int TIMEOUT_SECONDS; static final int OVERALL_TIMEOUT_SECONDS; }