diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-10-05 09:02:06 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-10-05 09:02:06 +0200 |
commit | ffe57b5673af80942925eed5b8e793ce2cf750b1 (patch) | |
tree | 31c7ee54da63a127da20662c29a58147c5c4f2ce /hv-collector-ves-message-generator | |
parent | 7b178765c00751fd99399eec76f1006270ae41dd (diff) |
Introduce configurable payload size limitation
Maximum payload size will be configurable (from command line parameter
or environment variable). The default value is same as previous
hardcoded value, ie. 1 MiB = 1024 * 1024 bytes.
Change-Id: Iec83d8295252bac353d3794b13454fdbbc80ecc4
Issue-ID: DCAEGEN2-856
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'hv-collector-ves-message-generator')
7 files changed, 52 insertions, 22 deletions
diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt index ace7f1cb..076c06be 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt @@ -20,8 +20,6 @@ package org.onap.dcae.collectors.veshv.ves.message.generator.api import org.onap.dcae.collectors.veshv.domain.WireFrameMessage -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.MessageGeneratorImpl -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator import reactor.core.publisher.Flux /** @@ -32,10 +30,6 @@ interface MessageGenerator { fun createMessageFlux(messageParameters: List<MessageParameters>): Flux<WireFrameMessage> companion object { - val INSTANCE: MessageGenerator by lazy { - MessageGeneratorImpl(PayloadGenerator()) - } - const val FIXED_PAYLOAD_SIZE = 100 } } diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt new file mode 100644 index 00000000..e2269c20 --- /dev/null +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.ves.message.generator.factory + +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.MessageGeneratorImpl +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator + +/** + * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> + * @since October 2018 + */ +object MessageGeneratorFactory { + fun create(maxPayloadSizeBytes: Int): MessageGenerator = + MessageGeneratorImpl(PayloadGenerator(), maxPayloadSizeBytes) +} diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt index 2bb9f781..cc1d16fe 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt @@ -42,7 +42,10 @@ import java.nio.charset.Charset * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -class MessageGeneratorImpl internal constructor(private val payloadGenerator: PayloadGenerator) : MessageGenerator { +class MessageGeneratorImpl internal constructor( + private val payloadGenerator: PayloadGenerator, + private val maxPayloadSizeBytes: Int +) : MessageGenerator { override fun createMessageFlux(messageParameters: List<MessageParameters>): Flux<WireFrameMessage> = Flux .fromIterable(messageParameters) @@ -89,7 +92,7 @@ class MessageGeneratorImpl internal constructor(private val payloadGenerator: Pa .build() private fun oversizedPayload() = - payloadGenerator.generateRawPayload(WireFrameMessage.MAX_PAYLOAD_SIZE + 1) + payloadGenerator.generateRawPayload(maxPayloadSizeBytes + 1) private fun fixedPayload() = payloadGenerator.generateRawPayload(MessageGenerator.FIXED_PAYLOAD_SIZE) diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImplTest.kt index ec09ac9c..ee76b789 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImplTest.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import com.google.protobuf.ByteString import com.google.protobuf.InvalidProtocolBufferException @@ -47,7 +47,8 @@ import reactor.test.test */ object MessageGeneratorImplTest : Spek({ describe("message factory") { - val generator = MessageGenerator.INSTANCE + val maxPayloadSizeBytes = 1024 + val generator = MessageGeneratorImpl(PayloadGenerator(), maxPayloadSizeBytes) given("single message parameters") { on("messages amount not specified in parameters") { it("should create infinite flux") { @@ -87,7 +88,7 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.isValid()).isTrue() - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.domainName) } .verifyComplete() @@ -105,7 +106,7 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.isValid()).isTrue() - assertThat(it.payloadSize).isGreaterThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isGreaterThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(PERF3GPP.domainName) } .verifyComplete() @@ -122,7 +123,7 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.isValid()).isTrue() - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThatExceptionOfType(InvalidProtocolBufferException::class.java) .isThrownBy { extractCommonEventHeader(it.payload) } } @@ -140,7 +141,7 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.isValid()).isFalse() - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(PERF3GPP.domainName) assertThat(it.versionMajor).isNotEqualTo(WireFrameMessage.SUPPORTED_VERSION_MINOR) } @@ -158,7 +159,7 @@ object MessageGeneratorImplTest : Spek({ .test() .assertNext { assertThat(it.isValid()).isTrue() - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThat(extractEventFields(it.payload).size()).isEqualTo(MessageGenerator.FIXED_PAYLOAD_SIZE) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.domainName) } @@ -177,17 +178,17 @@ object MessageGeneratorImplTest : Spek({ generator.createMessageFlux(messageParameters) .test() .assertNext { - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(PERF3GPP.domainName) } .expectNextCount(singleFluxSize - 1) .assertNext { - assertThat(it.payloadSize).isGreaterThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isGreaterThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(FAULT.domainName) } .expectNextCount(singleFluxSize - 1) .assertNext { - assertThat(it.payloadSize).isLessThan(WireFrameMessage.MAX_PAYLOAD_SIZE) + assertThat(it.payloadSize).isLessThan(maxPayloadSizeBytes) assertThat(extractCommonEventHeader(it.payload).domain).isEqualTo(HEARTBEAT.domainName) } .expectNextCount(singleFluxSize - 1) diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageParametersParserTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserTest.kt index 3b1a48b3..134ebb2d 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageParametersParserTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserTest.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.fail @@ -27,7 +27,6 @@ import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.jetbrains.spek.api.dsl.on import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.MessageParametersParserImpl private const val EXPECTED_MESSAGES_AMOUNT = 25000L diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGeneratorTest.kt index 2b41e290..5249a8d2 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGeneratorTest.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given diff --git a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/parameters.kt index dd8bc89f..5d112bae 100644 --- a/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/parameters.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/parameters.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import javax.json.Json |