2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.tests.component
22 import com.google.protobuf.ByteString
23 import org.assertj.core.api.Assertions.assertThat
24 import org.jetbrains.spek.api.Spek
25 import org.jetbrains.spek.api.dsl.describe
26 import org.jetbrains.spek.api.dsl.it
27 import org.onap.dcae.collectors.veshv.domain.VesEventDomain
28 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
29 import org.onap.dcae.collectors.veshv.model.CollectorConfiguration
30 import org.onap.dcae.collectors.veshv.tests.fakes.NoOpSink
31 import org.onap.dcae.collectors.veshv.tests.fakes.FakeMetrics
32 import org.onap.dcae.collectors.veshv.tests.fakes.MEASUREMENTS_FOR_VF_SCALING_TOPIC
33 import org.onap.dcae.collectors.veshv.tests.fakes.PERF3GPP_TOPIC
34 import org.onap.dcae.collectors.veshv.tests.fakes.basicConfiguration
35 import org.onap.dcae.collectors.veshv.tests.fakes.twoDomainsToOneTopicConfiguration
36 import org.onap.dcae.collectors.veshv.tests.utils.invalidWireFrame
37 import org.onap.dcae.collectors.veshv.tests.utils.vesEvent
38 import org.onap.dcae.collectors.veshv.tests.utils.vesWireFrameMessage
39 import kotlin.test.fail
41 object MetricsSpecification : Spek({
44 describe("Bytes received metrics") {
45 it("should sum up all bytes received") {
46 val sut = vesHvWithNoOpSink()
47 val vesWireFrameMessage = vesWireFrameMessage()
48 val invalidWireFrame = invalidWireFrame()
50 val bytesSent = invalidWireFrame.readableBytes() +
51 vesWireFrameMessage.readableBytes()
57 val metrics = sut.metrics
58 assertThat(metrics.bytesReceived)
59 .describedAs("bytesReceived metric")
64 describe("Messages received metrics") {
65 it("should sum up all received messages bytes") {
66 val sut = vesHvWithNoOpSink()
67 val firstVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(10)))
68 val secondVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(40)))
69 val firstVesMessage = vesWireFrameMessage(firstVesEvent)
70 val secondVesMessage = vesWireFrameMessage(secondVesEvent)
72 val serializedMessagesSize = firstVesEvent.serializedSize + secondVesEvent.serializedSize
78 val metrics = sut.metrics
79 assertThat(metrics.messageBytesReceived)
80 .describedAs("messageBytesReceived metric")
81 .isEqualTo(serializedMessagesSize)
85 describe("Messages sent metrics") {
86 it("should gather info for each topic separately") {
87 val sut = vesHvWithNoOpSink(twoDomainsToOneTopicConfiguration)
90 vesWireFrameMessage(PERF3GPP),
91 vesWireFrameMessage(PERF3GPP),
92 vesWireFrameMessage(VesEventDomain.MEASUREMENT)
95 val metrics = sut.metrics
96 assertThat(metrics.messageSentCount)
97 .describedAs("messageSentCount metric")
99 assertThat(messagesOnTopic(metrics, PERF3GPP_TOPIC))
100 .describedAs("messagesSentToTopic $PERF3GPP_TOPIC metric")
102 assertThat(messagesOnTopic(metrics, MEASUREMENTS_FOR_VF_SCALING_TOPIC))
103 .describedAs("messagesSentToTopic $MEASUREMENTS_FOR_VF_SCALING_TOPIC metric")
109 private fun messagesOnTopic(metrics: FakeMetrics, topic: String) =
110 metrics.messagesSentToTopic.get(topic) ?: fail("No messages were sent to topic $topic")