diff --git a/components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java b/components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java index 6ffa2f8290..35eff64c4a 100644 --- a/components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java +++ b/components/proxy/src/main/java/com/hotels/styx/admin/handlers/RoutingObjectHandler.java @@ -27,7 +27,7 @@ import com.hotels.styx.api.HttpRequest; import com.hotels.styx.api.HttpResponse; import com.hotels.styx.api.WebServiceHandler; -import com.hotels.styx.routing.RoutingObjectAdapter; +import com.hotels.styx.routing.RoutingObjectDecorator; import com.hotels.styx.routing.RoutingObjectRecord; import com.hotels.styx.routing.config.Builtins; import com.hotels.styx.routing.config.RoutingObjectFactory; @@ -96,7 +96,7 @@ public RoutingObjectHandler(StyxObjectStore routeDatabase, try { RoutingObjectDefinition payload = YAML_MAPPER.readValue(body, RoutingObjectDefinition.class); - RoutingObjectAdapter adapter = new RoutingObjectAdapter(Builtins.build(emptyList(), routingObjectFactoryContext, payload)); + RoutingObjectDecorator adapter = new RoutingObjectDecorator(Builtins.build(emptyList(), routingObjectFactoryContext, payload)); routeDatabase.insert(name, new RoutingObjectRecord(payload.type(), ImmutableSet.copyOf(payload.tags()), payload.config(), adapter)) .ifPresent(previous -> previous.getRoutingObject().stop()); diff --git a/components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectAdapter.java b/components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectDecorator.java similarity index 94% rename from components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectAdapter.java rename to components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectDecorator.java index 4a91d711f4..9e766802bf 100644 --- a/components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectAdapter.java +++ b/components/proxy/src/main/java/com/hotels/styx/routing/RoutingObjectDecorator.java @@ -31,7 +31,7 @@ * Adapts routing object into Styx core. * Provides a load balancing metric for the adapted routing object. */ -public class RoutingObjectAdapter implements RoutingObject { +public class RoutingObjectDecorator implements RoutingObject { private final RoutingObject delegate; @@ -42,7 +42,7 @@ public class RoutingObjectAdapter implements RoutingObject { * Routing object adapater constructor. * @param routingObject */ - public RoutingObjectAdapter(RoutingObject routingObject) { + public RoutingObjectDecorator(RoutingObject routingObject) { this.delegate = requireNonNull(routingObject); } diff --git a/components/proxy/src/main/java/com/hotels/styx/routing/handlers/HostProxy.java b/components/proxy/src/main/java/com/hotels/styx/routing/handlers/HostProxy.java index f456b35c6f..bd22770d1d 100644 --- a/components/proxy/src/main/java/com/hotels/styx/routing/handlers/HostProxy.java +++ b/components/proxy/src/main/java/com/hotels/styx/routing/handlers/HostProxy.java @@ -229,7 +229,7 @@ private static Connection.Factory connectionFactory( .responseTimeoutMillis(responseTimeoutMillis) .build() ) - .tlsSettings(Optional.ofNullable(tlsSettings).orElse(null)) + .tlsSettings(tlsSettings) .build(); if (connectionExpiration > 0) { diff --git a/components/proxy/src/main/java/com/hotels/styx/startup/StyxServerComponents.java b/components/proxy/src/main/java/com/hotels/styx/startup/StyxServerComponents.java index 76ad9a7c15..d32edfa718 100644 --- a/components/proxy/src/main/java/com/hotels/styx/startup/StyxServerComponents.java +++ b/components/proxy/src/main/java/com/hotels/styx/startup/StyxServerComponents.java @@ -32,7 +32,7 @@ import com.hotels.styx.client.netty.eventloop.PlatformAwareClientEventLoopGroupFactory; import com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig; import com.hotels.styx.proxy.plugin.NamedPlugin; -import com.hotels.styx.routing.RoutingObjectAdapter; +import com.hotels.styx.routing.RoutingObjectDecorator; import com.hotels.styx.routing.RoutingObjectRecord; import com.hotels.styx.routing.config.Builtins; import com.hotels.styx.routing.config.RoutingObjectFactory; @@ -109,7 +109,7 @@ private StyxServerComponents(Builder builder) { .map(StyxServerComponents::readHttpHandlers) .orElse(ImmutableMap.of()) .forEach((name, record) -> { - RoutingObjectAdapter adapter = new RoutingObjectAdapter(Builtins.build(ImmutableList.of(name), routingObjectContext, record)); + RoutingObjectDecorator adapter = new RoutingObjectDecorator(Builtins.build(ImmutableList.of(name), routingObjectContext, record)); routeObjectStore.insert(name, new RoutingObjectRecord(record.type(), ImmutableSet.copyOf(record.tags()), record.config(), adapter)) .ifPresent(previous -> previous.getRoutingObject().stop()); }); diff --git a/components/proxy/src/main/kotlin/com/hotels/styx/routing/RoutingObjectRecord.kt b/components/proxy/src/main/kotlin/com/hotels/styx/routing/RoutingObjectRecord.kt index c2b278a32a..90f7725ae2 100644 --- a/components/proxy/src/main/kotlin/com/hotels/styx/routing/RoutingObjectRecord.kt +++ b/components/proxy/src/main/kotlin/com/hotels/styx/routing/RoutingObjectRecord.kt @@ -17,16 +17,19 @@ package com.hotels.styx.routing import com.fasterxml.jackson.databind.JsonNode +/** + * Holds routing object and its associated metadata. + */ internal data class RoutingObjectRecord( val type: String, val tags: Set, val config: JsonNode, - val routingObject: RoutingObjectAdapter) { + val routingObject: RoutingObjectDecorator) { companion object { fun create(type: String, tags: Set, config: JsonNode, routingObject: RoutingObject) = RoutingObjectRecord( type, tags, config, - RoutingObjectAdapter(routingObject)) + RoutingObjectDecorator(routingObject)) } } diff --git a/components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/RoutingObjectHandlerTest.kt b/components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/RoutingObjectHandlerTest.kt index a5fb020a39..32a26c1f0c 100644 --- a/components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/RoutingObjectHandlerTest.kt +++ b/components/proxy/src/test/kotlin/com/hotels/styx/admin/handlers/RoutingObjectHandlerTest.kt @@ -23,7 +23,7 @@ import com.hotels.styx.api.HttpResponseStatus.CREATED import com.hotels.styx.api.HttpResponseStatus.NOT_FOUND import com.hotels.styx.api.HttpResponseStatus.OK import com.hotels.styx.routing.RoutingObjectFactoryContext -import com.hotels.styx.routing.RoutingObjectAdapter +import com.hotels.styx.routing.RoutingObjectDecorator import com.hotels.styx.routing.RoutingObjectRecord import com.hotels.styx.routing.db.StyxObjectStore import com.hotels.styx.routing.handle @@ -64,7 +64,7 @@ class RoutingObjectHandlerTest : FeatureSpec({ routeDatabase.get("staticResponse").isPresent shouldBe true routeDatabase.get("staticResponse").get().type shouldBe "StaticResponseHandler" routeDatabase.get("staticResponse").get().config.shouldBeTypeOf() - routeDatabase.get("staticResponse").get().routingObject.shouldBeTypeOf() + routeDatabase.get("staticResponse").get().routingObject.shouldBeTypeOf() } scenario("Retrieving objects") { @@ -154,7 +154,7 @@ class RoutingObjectHandlerTest : FeatureSpec({ scenario("Replacing existing objects triggers lifecycle methods") { val db = StyxObjectStore() - val mockObject = RoutingObjectAdapter(mockObject()) + val mockObject = RoutingObjectDecorator(mockObject()) db.insert("staticResponse", RoutingObjectRecord("StaticResponseHandler", mockk(), mockk(), mockObject)) db.get("staticResponse").isPresent shouldBe true @@ -182,7 +182,7 @@ class RoutingObjectHandlerTest : FeatureSpec({ scenario("Removing existing objects triggers lifecycle methods") { val db = StyxObjectStore() - val mockObject = RoutingObjectAdapter(mockObject()) + val mockObject = RoutingObjectDecorator(mockObject()) db.insert("staticResponse", RoutingObjectRecord("StaticResponseHandler", mockk(), mockk(), mockObject)) diff --git a/components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectAdapterTest.kt b/components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectDecoratorTest.kt similarity index 94% rename from components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectAdapterTest.kt rename to components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectDecoratorTest.kt index ddac10248e..bdb0c1b8ce 100644 --- a/components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectAdapterTest.kt +++ b/components/proxy/src/test/kotlin/com/hotels/styx/routing/RoutingObjectDecoratorTest.kt @@ -26,7 +26,7 @@ import io.mockk.verify import reactor.core.publisher.toMono import reactor.test.publisher.TestPublisher -class RoutingObjectAdapterTest : FeatureSpec({ +class RoutingObjectDecoratorTest : FeatureSpec({ val request = get("/").build() feature("Maintains load balancing metrics") { @@ -40,7 +40,7 @@ class RoutingObjectAdapterTest : FeatureSpec({ .returnsMany(listOf(Eventual(publisher1), Eventual(publisher2), Eventual(publisher3))) } - RoutingObjectAdapter(delegate) + RoutingObjectDecorator(delegate) .let { it.handle(request) @@ -73,7 +73,7 @@ class RoutingObjectAdapterTest : FeatureSpec({ feature("Calls close on delegate") { val delegate = mockk(relaxed = true) - RoutingObjectAdapter(delegate).stop() + RoutingObjectDecorator(delegate).stop() verify { delegate.stop() } } diff --git a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/HostProxyTest.kt b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/HostProxyTest.kt index b18feebcfe..10cee5bad2 100644 --- a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/HostProxyTest.kt +++ b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/HostProxyTest.kt @@ -52,7 +52,7 @@ class HostProxyTest : FeatureSpec() { HostProxy(HostAndPort.fromString("localhost:80"), client, mockk()).handle(request.stream(), mockk()) verify { - client?.sendRequest(ofType(LiveHttpRequest::class)) + client!!.sendRequest(ofType(LiveHttpRequest::class)) } } @@ -70,7 +70,7 @@ class HostProxyTest : FeatureSpec() { exception.message shouldBe ("HostProxy localhost:80 is stopped but received traffic.") verify(exactly = 0) { - client?.sendRequest(any()) + client!!.sendRequest(any()) } } diff --git a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/LoadBalancingGroupTest.kt b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/LoadBalancingGroupTest.kt index 463a200fab..be2868c891 100644 --- a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/LoadBalancingGroupTest.kt +++ b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/LoadBalancingGroupTest.kt @@ -78,12 +78,12 @@ class LoadBalancingGroupTest : FeatureSpec() { } } - frequencies["appx-01"]?.shouldBeGreaterThan(20) - frequencies["appx-02"]?.shouldBeGreaterThan(20) - frequencies["appx-03"]?.shouldBeGreaterThan(20) + frequencies["appx-01"]!!.shouldBeGreaterThan(20) + frequencies["appx-02"]!!.shouldBeGreaterThan(20) + frequencies["appx-03"]!!.shouldBeGreaterThan(20) - frequencies["appy-01"]?.shouldBeNull() - frequencies["appy-02"]?.shouldBeNull() + frequencies["appy-01"].shouldBeNull() + frequencies["appy-02"].shouldBeNull() } @@ -111,11 +111,9 @@ class LoadBalancingGroupTest : FeatureSpec() { } } - println("Frequencies: " + frequencies) - - frequencies["appx-04"]?.shouldBeGreaterThan(20) - frequencies["appx-05"]?.shouldBeGreaterThan(20) - frequencies["appx-06"]?.shouldBeGreaterThan(20) + frequencies["appx-04"]!!.shouldBeGreaterThan(20) + frequencies["appx-05"]!!.shouldBeGreaterThan(20) + frequencies["appx-06"]!!.shouldBeGreaterThan(20) } scenario("... and detects replaced origins") { @@ -136,11 +134,9 @@ class LoadBalancingGroupTest : FeatureSpec() { } } - println("Frequencies: " + frequencies) - - frequencies["appx-04-a"]?.shouldBeGreaterThan(20) - frequencies["appx-05-b"]?.shouldBeGreaterThan(20) - frequencies["appx-06-c"]?.shouldBeGreaterThan(20) + frequencies["appx-04-a"]!!.shouldBeGreaterThan(20) + frequencies["appx-05-b"]!!.shouldBeGreaterThan(20) + frequencies["appx-06-c"]!!.shouldBeGreaterThan(20) } scenario("... and emits NoAvailableHostsException when load balancing group is empty") { diff --git a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/RouteRefLookupTest.kt b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/RouteRefLookupTest.kt index 2fc92fec04..47a40a006d 100644 --- a/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/RouteRefLookupTest.kt +++ b/components/proxy/src/test/kotlin/com/hotels/styx/routing/handlers/RouteRefLookupTest.kt @@ -20,7 +20,7 @@ import com.hotels.styx.api.ByteStream import com.hotels.styx.api.HttpRequest.get import com.hotels.styx.api.HttpResponseStatus.NOT_FOUND import com.hotels.styx.api.LiveHttpRequest -import com.hotels.styx.routing.RoutingObjectAdapter +import com.hotels.styx.routing.RoutingObjectDecorator import com.hotels.styx.routing.RoutingObjectRecord import com.hotels.styx.routing.config.RoutingObjectReference import com.hotels.styx.routing.db.StyxObjectStore @@ -39,7 +39,7 @@ import java.util.Optional class RouteRefLookupTest : StringSpec({ "Retrieves handler from route database" { - val handler = RoutingObjectAdapter(mockk()) + val handler = RoutingObjectDecorator(mockk()) val routeDb = mockk>() every { routeDb.get(any()) } returns Optional.of(RoutingObjectRecord("StaticResponseHandler", mockk(), mockk(), handler)) diff --git a/system-tests/ft-suite/src/test/kotlin/com/hotels/styx/routing/LoadBalancingGroupSpec.kt b/system-tests/ft-suite/src/test/kotlin/com/hotels/styx/routing/LoadBalancingGroupSpec.kt index 65b49bcf81..c1a3ae6b13 100644 --- a/system-tests/ft-suite/src/test/kotlin/com/hotels/styx/routing/LoadBalancingGroupSpec.kt +++ b/system-tests/ft-suite/src/test/kotlin/com/hotels/styx/routing/LoadBalancingGroupSpec.kt @@ -337,9 +337,9 @@ class LoadBalancingGroupSpec : FeatureSpec() { } } -// scenario("!Routes to new origin when the origin indicated by sticky session cookie is no longer available") { -// TODO("Styx doesn't support this as of today") -// } + scenario("!Routes to new origin when the origin indicated by sticky session cookie is no longer available") { + // See bug: https://github.com/HotelsDotCom/styx/issues/434 + } } feature("Origins restriction") {