From 678af1b5172eb3b214584de91ece3f8df163c5e9 Mon Sep 17 00:00:00 2001 From: Piotr Jaszczyk Date: Wed, 27 Jun 2018 12:30:56 +0200 Subject: Write performance tests Closes ONAP-434 Change-Id: I1139848f32ac19a4d0a0fd595f4b07c10cd83db0 Signed-off-by: Piotr Jaszczyk Issue-ID: DCAEGEN2-601 --- .../veshv/simulators/xnf/api/MessageGenerator.kt | 32 +++++++++ .../simulators/xnf/config/ClientConfiguration.kt | 2 +- .../collectors/veshv/simulators/xnf/factory.kt | 30 ++++++++ .../veshv/simulators/xnf/impl/HttpServer.kt | 6 +- .../veshv/simulators/xnf/impl/MessageFactory.kt | 80 ---------------------- .../simulators/xnf/impl/MessageGeneratorImpl.kt | 79 +++++++++++++++++++++ .../veshv/simulators/xnf/impl/PayloadGenerator.kt | 4 +- .../veshv/simulators/xnf/impl/VesHvClient.kt | 3 +- .../dcae/collectors/veshv/simulators/xnf/main.kt | 3 - .../simulators/xnf/impl/MessageFactoryTest.kt | 2 +- 10 files changed, 149 insertions(+), 92 deletions(-) create mode 100644 hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt create mode 100644 hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt delete mode 100644 hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactory.kt create mode 100644 hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt (limited to 'hv-collector-client-simulator') diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt new file mode 100644 index 00000000..f4c92fd4 --- /dev/null +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt @@ -0,0 +1,32 @@ +/* + * ============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.simulators.xnf.api + +import org.onap.dcae.collectors.veshv.domain.WireFrame +import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import reactor.core.publisher.Flux + +/** + * @author Piotr Jaszczyk + * @since June 2018 + */ +interface MessageGenerator { + fun createMessageFlux(messageParameters: MessageParameters): Flux +} diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ClientConfiguration.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ClientConfiguration.kt index ed96e6c3..657ed317 100644 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ClientConfiguration.kt +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/ClientConfiguration.kt @@ -25,7 +25,7 @@ import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration * @author Jakub Dudycz * @since June 2018 */ -data class ClientConfiguration( +internal data class ClientConfiguration( val vesHost: String, val vesPort: Int, val security: SecurityConfiguration, diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt new file mode 100644 index 00000000..dce386b1 --- /dev/null +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt @@ -0,0 +1,30 @@ +/* + * ============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.simulators.xnf + +import org.onap.dcae.collectors.veshv.simulators.xnf.api.MessageGenerator +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.MessageGeneratorImpl +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.PayloadGenerator + +/** + * @author Piotr Jaszczyk + * @since June 2018 + */ +fun createMessageGenerator(): MessageGenerator = MessageGeneratorImpl(PayloadGenerator()) diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt index 3f872b51..c545ac8d 100644 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt @@ -37,7 +37,7 @@ import javax.json.JsonObject * @author Jakub Dudycz * @since June 2018 */ -class HttpServer(private val vesClient: VesHvClient) { +internal class HttpServer(private val vesClient: VesHvClient) { fun start(port: Int = DEFAULT_PORT): IO = IO { RatpackServer.start { server -> @@ -69,7 +69,7 @@ class HttpServer(private val vesClient: VesHvClient) { return ctx.request.body .map { Json.createReader(it.inputStream).readObject() } .map { extractMessageParameters(it) } - .map { MessageFactory.INSTANCE.createMessageFlux(it) } + .map { MessageGeneratorImpl.INSTANCE.createMessageFlux(it) } } private fun sendAcceptedResponse(ctx: Context) { @@ -95,7 +95,7 @@ class HttpServer(private val vesClient: VesHvClient) { private fun extractMessageParameters(request: JsonObject): MessageParameters = try { - val commonEventHeader = MessageFactory.INSTANCE + val commonEventHeader = MessageGeneratorImpl.INSTANCE .parseCommonHeader(request.getJsonObject("commonEventHeader")) val messagesAmount = request.getJsonNumber("messagesAmount").longValue() MessageParameters(commonEventHeader, messagesAmount) diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactory.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactory.kt deleted file mode 100644 index f731e11c..00000000 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactory.kt +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ============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.simulators.xnf.impl - -import com.google.protobuf.ByteString -import org.onap.dcae.collectors.veshv.domain.WireFrame -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters -import org.onap.ves.VesEventV5.VesEvent -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import javax.json.JsonObject - -/** - * @author Jakub Dudycz - * @since June 2018 - */ -class MessageFactory(private val payloadGenerator: PayloadGenerator) { - - fun createMessageFlux(messageParameters: MessageParameters): Flux = - Mono.fromCallable { createMessage(messageParameters.commonEventHeader) }.let { - if (messageParameters.amount < 0) - it.repeat() - else - it.repeat(messageParameters.amount) - } - - fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder() - .setVersion(json.getString("version")) - .setDomain(CommonEventHeader.Domain.forNumber(json.getInt("domain"))) - .setSequence(json.getInt("sequence")) - .setPriority(CommonEventHeader.Priority.forNumber(json.getInt("priority"))) - .setEventId(json.getString("eventId")) - .setEventName(json.getString("eventName")) - .setEventType(json.getString("eventType")) - .setStartEpochMicrosec(json.getJsonNumber("startEpochMicrosec").longValue()) - .setLastEpochMicrosec(json.getJsonNumber("lastEpochMicrosec").longValue()) - .setNfNamingCode(json.getString("nfNamingCode")) - .setNfcNamingCode(json.getString("nfcNamingCode")) - .setReportingEntityId(json.getString("reportingEntityId")) - .setReportingEntityName(ByteString.copyFromUtf8(json.getString("reportingEntityName"))) - .setSourceId(ByteString.copyFromUtf8(json.getString("sourceId"))) - .setSourceName(json.getString("sourceName")) - .build() - - - private fun createMessage(commonHeader: CommonEventHeader): WireFrame = - WireFrame(vesMessageBytes(commonHeader)) - - - private fun vesMessageBytes(commonHeader: CommonEventHeader): ByteArray { - val msg = VesEvent.newBuilder() - .setCommonEventHeader(commonHeader) - .setHvRanMeasFields(PayloadGenerator().generatePayload().toByteString()) - .build() - - return msg.toByteArray() - } - - companion object { - val INSTANCE = MessageFactory(PayloadGenerator()) - } -} diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt new file mode 100644 index 00000000..0d28bad0 --- /dev/null +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt @@ -0,0 +1,79 @@ +/* + * ============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.simulators.xnf.impl + +import com.google.protobuf.ByteString +import org.onap.dcae.collectors.veshv.domain.WireFrame +import org.onap.dcae.collectors.veshv.simulators.xnf.api.MessageGenerator +import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import org.onap.ves.VesEventV5.VesEvent +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import javax.json.JsonObject + +/** + * @author Jakub Dudycz + * @since June 2018 + */ +internal class MessageGeneratorImpl(private val payloadGenerator: PayloadGenerator) : MessageGenerator { + + override fun createMessageFlux(messageParameters: MessageParameters): Flux = + Mono.fromCallable { createMessage(messageParameters.commonEventHeader) }.let { + if (messageParameters.amount < 0) + it.repeat() + else + it.repeat(messageParameters.amount) + } + + fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder() + .setVersion(json.getString("version")) + .setDomain(CommonEventHeader.Domain.forNumber(json.getInt("domain"))) + .setSequence(json.getInt("sequence")) + .setPriority(CommonEventHeader.Priority.forNumber(json.getInt("priority"))) + .setEventId(json.getString("eventId")) + .setEventName(json.getString("eventName")) + .setEventType(json.getString("eventType")) + .setStartEpochMicrosec(json.getJsonNumber("startEpochMicrosec").longValue()) + .setLastEpochMicrosec(json.getJsonNumber("lastEpochMicrosec").longValue()) + .setNfNamingCode(json.getString("nfNamingCode")) + .setNfcNamingCode(json.getString("nfcNamingCode")) + .setReportingEntityId(json.getString("reportingEntityId")) + .setReportingEntityName(ByteString.copyFromUtf8(json.getString("reportingEntityName"))) + .setSourceId(ByteString.copyFromUtf8(json.getString("sourceId"))) + .setSourceName(json.getString("sourceName")) + .build() + + + private fun createMessage(commonHeader: CommonEventHeader): WireFrame = + WireFrame(vesMessageBytes(commonHeader)) + + + private fun vesMessageBytes(commonHeader: CommonEventHeader): ByteArray = + VesEvent.newBuilder() + .setCommonEventHeader(commonHeader) + .setHvRanMeasFields(payloadGenerator.generatePayload().toByteString()) + .build() + .toByteArray() + + companion object { + val INSTANCE = MessageGeneratorImpl(PayloadGenerator()) + } +} diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt index 17dbbf41..c8b97639 100644 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt @@ -22,9 +22,9 @@ package org.onap.dcae.collectors.veshv.simulators.xnf.impl import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload.PMObject import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload.PMObject.HVRanMeas -import java.util.Random +import java.util.* -class PayloadGenerator { +internal class PayloadGenerator { private val randomGenerator = Random() diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/VesHvClient.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/VesHvClient.kt index be351b50..43b73e1f 100644 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/VesHvClient.kt +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/VesHvClient.kt @@ -31,7 +31,6 @@ import org.onap.dcae.collectors.veshv.domain.WireFrameEncoder import org.onap.dcae.collectors.veshv.simulators.xnf.config.ClientConfiguration import org.onap.dcae.collectors.veshv.utils.logging.Logger import org.reactivestreams.Publisher -import reactor.core.publisher.EmitterProcessor import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.core.publisher.ReplayProcessor @@ -43,7 +42,7 @@ import reactor.ipc.netty.tcp.TcpClient * @author Jakub Dudycz * @since June 2018 */ -class VesHvClient(private val configuration: ClientConfiguration) { +internal class VesHvClient(private val configuration: ClientConfiguration) { private val client: TcpClient = TcpClient.builder() .options { opts -> diff --git a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt index f2229507..dbeba2b2 100644 --- a/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt +++ b/hv-collector-client-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt @@ -21,11 +21,8 @@ package org.onap.dcae.collectors.veshv.simulators.xnf import arrow.core.Failure import arrow.core.Success -import arrow.effects.IO import org.onap.dcae.collectors.veshv.simulators.xnf.config.ArgBasedClientConfiguration -import org.onap.dcae.collectors.veshv.simulators.xnf.config.ClientConfiguration import org.onap.dcae.collectors.veshv.simulators.xnf.impl.HttpServer -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.MessageFactory import org.onap.dcae.collectors.veshv.simulators.xnf.impl.VesHvClient import org.onap.dcae.collectors.veshv.utils.commandline.handleErrorsInMain import org.onap.dcae.collectors.veshv.utils.logging.Logger diff --git a/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt b/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt index 2f592641..6f8a95a4 100644 --- a/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt +++ b/hv-collector-client-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt @@ -40,7 +40,7 @@ const val SAMPLE_LAST_EPOCH: Long = 120034455 object MessageFactoryTest : Spek({ describe("message factory") { - val factory = MessageFactory.INSTANCE + val factory = MessageGeneratorImpl.INSTANCE given("only common header") { it("should return infinite flux") { -- cgit 1.2.3-korg