diff --git a/src/main/kotlin/com/cubetiqs/wsclient/WebClientStockClient.kt b/src/main/kotlin/com/cubetiqs/wsclient/WebClientStockClient.kt index 93c1809..a77db41 100644 --- a/src/main/kotlin/com/cubetiqs/wsclient/WebClientStockClient.kt +++ b/src/main/kotlin/com/cubetiqs/wsclient/WebClientStockClient.kt @@ -2,8 +2,6 @@ package com.cubetiqs.wsclient import org.springframework.web.reactive.function.client.WebClient import reactor.core.publisher.Flux -import reactor.kotlin.extra.retry.retryExponentialBackoff -import java.time.Duration class WebClientStockClient(val webClient: WebClient) : StockClient { override fun priceFor(symbol: String): Flux { @@ -11,7 +9,6 @@ class WebClientStockClient(val webClient: WebClient) : StockClient { .uri("http://localhost:8080/stocks/{symbol}", symbol) .retrieve() .bodyToFlux(StockPrice::class.java) - .retryExponentialBackoff(5, Duration.ofSeconds(10), Duration.ofSeconds(20)) .doOnError { println(it.message) } diff --git a/src/test/kotlin/com/cubetiqs/wsclient/WebClientApplicationTests.kt b/src/test/kotlin/com/cubetiqs/wsclient/WebClientApplicationTests.kt new file mode 100644 index 0000000..9cf455e --- /dev/null +++ b/src/test/kotlin/com/cubetiqs/wsclient/WebClientApplicationTests.kt @@ -0,0 +1,28 @@ +package com.cubetiqs.wsclient + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import reactor.core.publisher.Flux +import reactor.test.StepVerifier + +@SpringBootTest +class WebClientApplicationTests @Autowired constructor( + private val stockClient: WebClientStockClient +) { + @Test + fun shouldRetrieveStockPricesFromTheService() { + val prices: Flux = stockClient.priceFor("USD") + + Assertions.assertNotNull(prices) + val fivePrices = prices.take(5) + Assertions.assertEquals(5, fivePrices.count().block()) + Assertions.assertEquals("USD", fivePrices.blockFirst()?.symbol) + + StepVerifier.create(prices.take(2)) + .expectNextMatches { it.symbol == "USD" } + .expectNextMatches { it.symbol == "USD" } + .verifyComplete() + } +}