diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-06-15 16:09:41 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-02 10:27:38 +0200 |
commit | 553154ae42e5362dacab6c190b8cf1e1388f5b87 (patch) | |
tree | 9f78fdd5da58082883724ead537dd5368c2cf940 /hv-collector-core/src/test | |
parent | 69f43f2532106b9d2d4c64fabbf4ea092e4dbf4a (diff) |
Change Consul configuration update policy
- At startup default config is applied
- Configuration is updated in intervals given at VES-HV
service startup to allow dynamic changes
- Included consul service startup in docker-compose file
- VES-HV now exits when fails to acquire confguration from consul
Closes ONAP-229
Change-Id: I896cfd177fa45381f9822278c2dffc113dd3df72
Signed-off-by: jakub.dudycz@nokia.com
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-core/src/test')
2 files changed, 81 insertions, 23 deletions
diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt index b2da430d..dd190848 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/ConsulConfigurationProviderTest.kt @@ -20,12 +20,16 @@ package org.onap.dcae.collectors.veshv.impl.adapters import com.nhaarman.mockito_kotlin.mock +import com.nhaarman.mockito_kotlin.verify import com.nhaarman.mockito_kotlin.whenever import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain import reactor.core.publisher.Mono +import reactor.ipc.netty.http.client.HttpClient +import reactor.test.StepVerifier +import java.time.Duration import java.util.* import kotlin.test.assertEquals @@ -35,20 +39,63 @@ import kotlin.test.assertEquals */ internal object ConsulConfigurationProviderTest : Spek({ + val updateInterval = Duration.ofMillis(1) + val httpAdapterMock: HttpAdapter = mock() + given("valid resource url") { - val testUrl = "http://valid-url/" - val httpAdapterMock: HttpAdapter = mock() - val consulConfigProvider = ConsulConfigurationProvider(testUrl, httpAdapterMock) - whenever(httpAdapterMock.getResponse(testUrl)).thenReturn(Mono.just(constructConsulResponse())) + val validUrl = "http://valid-url/" + val consulConfigProvider = ConsulConfigurationProvider(validUrl, updateInterval, httpAdapterMock) + + whenever(httpAdapterMock.get(validUrl)).thenReturn(Mono.just(constructConsulResponse())) + + it("should use default configuration at the beginning, " + + "then apply received configuration") { + + StepVerifier.create(consulConfigProvider().take(2)) + .consumeNextWith { + + assertEquals("kafka:9092", it.kafkaBootstrapServers) + + val route1 = it.routing.routes[0] + assertEquals(Domain.HVRANMEAS, route1.domain) + assertEquals("ves_hvRanMeas", route1.targetTopic) + } + .consumeNextWith { + + assertEquals("kafka:9093", it.kafkaBootstrapServers) + + val route1 = it.routing.routes[0] + assertEquals(Domain.HEARTBEAT, route1.domain) + assertEquals("test-topic-1", route1.targetTopic) + + val route2 = it.routing.routes[1] + assertEquals(Domain.MEASUREMENTS_FOR_VF_SCALING, route2.domain) + assertEquals("test-topic-2", route2.targetTopic) + }.verifyComplete() + } + } + given("invalid resource url") { + + val invalidUrl = "http://invalid-url/" + val consulConfigProvider = ConsulConfigurationProvider(invalidUrl, updateInterval, httpAdapterMock) + + whenever(httpAdapterMock.get(invalidUrl)).thenReturn(Mono.error(RuntimeException("Test exception"))) + + it("should use default configuration at the beginning, then should interrupt the flux") { - it("should create valid collector configuration") { - val response = consulConfigProvider().blockFirst() - assertEquals("val1", response.kafkaBootstrapServers) - val route = response.routing.routes[0] - assertEquals(Domain.MEASUREMENTS_FOR_VF_SCALING, route.domain) - assertEquals("val3", route.targetTopic) + StepVerifier.create(consulConfigProvider()) + .consumeNextWith { + + + assertEquals("kafka:9092", it.kafkaBootstrapServers) + + val route1 = it.routing.routes[0] + assertEquals(Domain.HVRANMEAS, route1.domain) + assertEquals("ves_hvRanMeas", route1.targetTopic) + } + .verifyErrorMessage("Test exception") } } }) @@ -56,11 +103,17 @@ internal object ConsulConfigurationProviderTest : Spek({ fun constructConsulResponse(): String { val config = """{ - "kafkaBootstrapServers": "val1", - "routing": { - "fromDomain": 2, - "toTopic": "val3" - } + "kafkaBootstrapServers": "kafka:9093", + "routing": [ + { + "fromDomain": 1, + "toTopic": "test-topic-1" + }, + { + "fromDomain": 2, + "toTopic": "test-topic-2" + } + ] }""" val encodedValue = String(Base64.getEncoder().encode(config.toByteArray())) diff --git a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt index 66288453..79eda995 100644 --- a/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt +++ b/hv-collector-core/src/test/kotlin/org/onap/dcae/collectors/veshv/impl/adapters/HttpAdapterTest.kt @@ -30,6 +30,7 @@ import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.ipc.netty.http.client.HttpClient import reactor.ipc.netty.http.client.HttpClientResponse +import reactor.test.StepVerifier import java.nio.charset.Charset import kotlin.test.assertEquals @@ -43,13 +44,15 @@ internal object HttpAdapterTest : Spek({ val httpClientMock: HttpClient = mock() val httpAdapter = HttpAdapter(httpClientMock) - val testUrl = "http://valid-url/" + val validUrl = "http://valid-url/" val responseContent = """{"key1": "value1", "key2": "value2"}""" val httpResponse = createHttpResponseMock(responseContent) - whenever(httpClientMock.get(testUrl)).thenReturn(Mono.just(httpResponse)) + whenever(httpClientMock.get(validUrl)).thenReturn(Mono.just(httpResponse)) it("should return response string") { - assertEquals(responseContent, httpAdapter.getResponse(testUrl).block()) + StepVerifier + .create(httpAdapter.get(validUrl)) + .expectNext(responseContent) } } @@ -57,12 +60,14 @@ internal object HttpAdapterTest : Spek({ val httpClientMock: HttpClient = mock() val httpAdapter = HttpAdapter(httpClientMock) - val testUrl = "http://invalid-url/" - whenever(httpClientMock.get(testUrl)).thenReturn(Mono.error(Exception("Test exception"))) + val invalidUrl = "http://invalid-url/" + val exceptionMessage = "Test exception" + whenever(httpClientMock.get(invalidUrl)).thenReturn(Mono.error(Exception(exceptionMessage))) - - it("should return null response") { - assertEquals(null, httpAdapter.getResponse(testUrl).block()) + it("should interrupt the flux") { + StepVerifier + .create(httpAdapter.get(invalidUrl)) + .verifyErrorMessage(exceptionMessage) } } }) |