Skip to content

Commit

Permalink
Add Kotlin WebServiceHandler.handle extension method for unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokar committed May 24, 2019
1 parent b2918be commit 0263f11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public MetricsHandler(MetricRegistry metricRegistry, Optional<Duration> cacheExp
this.metricRegistry = metricRegistry;
}

@Override
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) {
return this.urlMatcher.handle(request, context);
}

private static boolean matchesRoot(String metricName, String root) {
return root == null || metricName.equals(root) || metricName.startsWith(root + ".");
}
Expand All @@ -88,11 +93,6 @@ private static boolean containsSearchTerm(String name, String searchTerm) {
return searchTerm == null || name.contains(searchTerm);
}

@Override
public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) {
return this.urlMatcher.handle(request, context);
}

private HttpResponse filteredMetricResponse(HttpRequest request) {
String root = Optional.of(SPECIFIC_METRICS_PATH_PATTERN.matcher(request.path()))
.filter(Matcher::matches)
Expand Down Expand Up @@ -129,7 +129,7 @@ private String serialise(Object object, boolean pretty) {
}
}

static class RootMetricsHandler extends JsonHandler<MetricRegistry> {
private static class RootMetricsHandler extends JsonHandler<MetricRegistry> {
public RootMetricsHandler(MetricRegistry data, Optional<Duration> cacheExpiration, Module... modules) {
super(data, cacheExpiration, modules);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.hotels.styx.routing
import com.hotels.styx.Environment
import com.hotels.styx.api.HttpHandler
import com.hotels.styx.api.HttpRequest
import com.hotels.styx.api.WebServiceHandler
import com.hotels.styx.infrastructure.configuration.yaml.YamlConfig
import com.hotels.styx.proxy.plugin.NamedPlugin
import com.hotels.styx.routing.config.BuiltinInterceptorsFactory
Expand All @@ -40,5 +41,7 @@ data class RoutingContext(
fun get() = HttpHandlerFactory.Context(environment, routeDb, routingObjectFactory, plugins, interceptorsFactory, requestTracking)
}

fun WebServiceHandler.handle(request: HttpRequest) = this.handle(request, HttpInterceptorContext.create())

fun HttpHandler.handle(request: HttpRequest, count: Int = 10000) = this.handle(request.stream(), HttpInterceptorContext.create())
.flatMap { it.aggregate(count) }

0 comments on commit 0263f11

Please sign in to comment.