Init wsclient and code tests with rsocket client
This commit is contained in:
25
src/main/kotlin/com/cubetiqs/wsclient/StockClient.kt
Normal file
25
src/main/kotlin/com/cubetiqs/wsclient/StockClient.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.cubetiqs.wsclient
|
||||
|
||||
import org.springframework.messaging.rsocket.RSocketRequester
|
||||
import org.springframework.stereotype.Service
|
||||
import reactor.core.publisher.Flux
|
||||
|
||||
@Service
|
||||
interface StockClient {
|
||||
fun priceFor(symbol: String): Flux<StockPrice>
|
||||
}
|
||||
|
||||
@Service
|
||||
class RSocketStockClient (
|
||||
private val requesterBuilder: RSocketRequester.Builder
|
||||
) : StockClient {
|
||||
private fun createRSocketRequester(): RSocketRequester {
|
||||
return requesterBuilder.connectTcp("localhost", 7000).block() ?: throw Exception("requester not loaded")
|
||||
}
|
||||
|
||||
override fun priceFor(symbol: String): Flux<StockPrice> {
|
||||
return createRSocketRequester().route("stockPrices")
|
||||
.data(symbol)
|
||||
.retrieveFlux(StockPrice::class.java)
|
||||
}
|
||||
}
|
||||
9
src/main/kotlin/com/cubetiqs/wsclient/StockPrice.kt
Normal file
9
src/main/kotlin/com/cubetiqs/wsclient/StockPrice.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.cubetiqs.wsclient
|
||||
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class StockPrice (
|
||||
val symbol: String,
|
||||
val price: Double,
|
||||
val time: LocalDateTime
|
||||
)
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.cubetiqs.wsclient
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class WsClientApplication
|
||||
1
src/main/resources/application.properties
Normal file
1
src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
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
|
||||
|
||||
@SpringBootTest
|
||||
class RSocketClientApplicationTests @Autowired constructor(
|
||||
private val stockClient: StockClient
|
||||
) {
|
||||
@Test
|
||||
fun shouldRetrieveStockPricesFromTheService() {
|
||||
val prices: Flux<StockPrice> = stockClient.priceFor("USD")
|
||||
|
||||
Assertions.assertNotNull(prices)
|
||||
val fivePrices = prices.take(5)
|
||||
Assertions.assertEquals(5, fivePrices.count().block())
|
||||
Assertions.assertEquals("USD", fivePrices.blockFirst()?.symbol)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.cubetiqs.wsclient
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class WsClientApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user