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.HEARTBEAT
29 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
30 import org.onap.dcae.collectors.veshv.model.MessageDropCause.INVALID_MESSAGE
31 import org.onap.dcae.collectors.veshv.model.MessageDropCause.ROUTE_NOT_FOUND
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.*
38 object MetricsSpecification : Spek({
41 describe("Bytes received metrics") {
42 it("should sum up all bytes received") {
43 val sut = vesHvWithNoOpSink()
44 val vesWireFrameMessage = vesWireFrameMessage()
45 val invalidWireFrame = messageWithInvalidWireFrameHeader()
47 val bytesSent = invalidWireFrame.readableBytes() +
48 vesWireFrameMessage.readableBytes()
54 val metrics = sut.metrics
55 assertThat(metrics.bytesReceived)
56 .describedAs("bytesReceived metric")
61 describe("Messages received metrics") {
62 it("should sum up all received messages bytes") {
63 val sut = vesHvWithNoOpSink()
64 val firstVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(10)))
65 val secondVesEvent = vesEvent(eventFields = ByteString.copyFrom(ByteArray(40)))
66 val firstVesMessage = vesWireFrameMessage(firstVesEvent)
67 val secondVesMessage = vesWireFrameMessage(secondVesEvent)
69 val serializedMessagesSize = firstVesEvent.serializedSize + secondVesEvent.serializedSize
75 val metrics = sut.metrics
76 assertThat(metrics.messageBytesReceived)
77 .describedAs("messageBytesReceived metric")
78 .isEqualTo(serializedMessagesSize)
82 describe("Messages sent metrics") {
83 it("should gather info for each topic separately") {
84 val sut = vesHvWithNoOpSink(twoDomainsToOneTopicConfiguration)
87 vesWireFrameMessage(PERF3GPP),
88 vesWireFrameMessage(PERF3GPP),
89 vesWireFrameMessage(VesEventDomain.MEASUREMENT)
92 val metrics = sut.metrics
93 assertThat(metrics.messagesSentCount)
94 .describedAs("messagesSentCount metric")
96 assertThat(metrics.messagesOnTopic(PERF3GPP_TOPIC))
97 .describedAs("messagesSentToTopic $PERF3GPP_TOPIC metric")
99 assertThat(metrics.messagesOnTopic(MEASUREMENTS_FOR_VF_SCALING_TOPIC))
100 .describedAs("messagesSentToTopic $MEASUREMENTS_FOR_VF_SCALING_TOPIC metric")
105 describe("Messages dropped metrics") {
106 it("should gather metrics for invalid messages") {
107 val sut = vesHvWithNoOpSink(basicConfiguration)
109 sut.handleConnection(
110 messageWithInvalidWireFrameHeader(),
111 wireFrameMessageWithInvalidPayload(),
112 vesWireFrameMessage(domain = PERF3GPP),
113 messageWithInvalidListenerVersion()
116 val metrics = sut.metrics
117 assertThat(metrics.messagesDropped(INVALID_MESSAGE))
118 .describedAs("messagesDroppedCause $INVALID_MESSAGE metric")
122 it("should gather metrics for route not found") {
123 val sut = vesHvWithNoOpSink(basicConfiguration)
125 sut.handleConnection(
126 vesWireFrameMessage(domain = PERF3GPP),
127 vesWireFrameMessage(domain = HEARTBEAT)
130 val metrics = sut.metrics
131 assertThat(metrics.messagesDropped(ROUTE_NOT_FOUND))
132 .describedAs("messagesDroppedCause $ROUTE_NOT_FOUND metric")
136 it("should gather summed metrics for dropped messages"){
137 val sut = vesHvWithNoOpSink(basicConfiguration)
139 sut.handleConnection(
140 vesWireFrameMessage(domain = PERF3GPP),
141 vesWireFrameMessage(domain = HEARTBEAT),
142 wireFrameMessageWithInvalidPayload()
145 val metrics = sut.metrics
146 assertThat(metrics.messagesDroppedCount)
147 .describedAs("messagesDroppedCount metric")