Skip to content

Commit

Permalink
Injected stickySessionConfig into StyxBackendServiceClientFactory, ad…
Browse files Browse the repository at this point in the history
…ded assertion in test
  • Loading branch information
VivianLopes committed Aug 31, 2018
1 parent c0b94ca commit 62e5322
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.hotels.styx.client

import java.nio.charset.Charset
import java.util.concurrent.TimeUnit

import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.hotels.styx.api.HttpHeaderNames.CONTENT_LENGTH
Expand Down Expand Up @@ -97,9 +98,13 @@ class StickySessionSpec extends FunSuite with BeforeAndAfter with ShouldMatchers

def stickySessionStrategy(activeOrigins: ActiveOrigins) = new StickySessionLoadBalancingStrategy(activeOrigins, roundRobinStrategy(activeOrigins))


test("Responds with sticky session cookie when STICKY_SESSION_ENABLED=true") {
val stickySessionConfig = StickySessionConfig.newStickySessionConfigBuilder().timeout(100, TimeUnit.SECONDS).build()

val client = newHttpClientBuilder(backendService.id)
.loadBalancer(stickySessionStrategy(activeOrigins(backendService)))
.stickySessionConfig(stickySessionConfig)
.build

val request: HttpRequest = HttpRequest.get("/")
Expand All @@ -113,6 +118,8 @@ class StickySessionSpec extends FunSuite with BeforeAndAfter with ShouldMatchers
cookie.path().get() should be("/")
cookie.httpOnly() should be(true)
cookie.maxAge().isPresent should be(true)

cookie.maxAge().get() should be (100L)
}

test("Responds without sticky session cookie when sticky session is not enabled") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public HttpClient createClient(BackendService backendService, OriginsInventory o

return new StyxHttpClient.Builder(backendService.id())
.loadBalancer(loadBalancingStrategy)
.stickySessionConfig(backendService.stickySessionConfig())
.metricsRegistry(environment.metricRegistry())
.retryPolicy(retryPolicy)
.enableContentValidation()
Expand Down

0 comments on commit 62e5322

Please sign in to comment.