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.fakes
22 import org.onap.dcae.collectors.veshv.boundary.Metrics
23 import org.onap.dcae.collectors.veshv.model.MessageDropCause
24 import java.util.concurrent.ConcurrentHashMap
25 import kotlin.test.fail
28 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
31 class FakeMetrics : Metrics {
32 var bytesReceived: Int = 0
33 var messageBytesReceived: Int = 0
34 var messagesSentCount: Int = 0
35 var messagesDroppedCount: Int = 0
37 private val messagesSentToTopic: MutableMap<String, Int> = ConcurrentHashMap()
38 private val messagesDroppedCause: MutableMap<MessageDropCause, Int> = ConcurrentHashMap()
40 override fun notifyBytesReceived(size: Int) {
44 override fun notifyMessageReceived(size: Int) {
45 messageBytesReceived += size
48 override fun notifyMessageSent(topic: String) {
50 messagesSentToTopic.compute(topic) { k, _ -> messagesSentToTopic[k]?.inc() ?: 1 }
53 override fun notifyMessageDropped(cause: MessageDropCause) {
54 messagesDroppedCount++
55 messagesDroppedCause.compute(cause) { k, _ -> messagesDroppedCause[k]?.inc() ?: 1 }
58 fun messagesOnTopic(topic: String) =
59 messagesSentToTopic[topic] ?: fail("No messages were sent to topic $topic")
61 fun messagesDropped(cause: MessageDropCause) =
62 messagesDroppedCause[cause]
63 ?: fail("No messages were dropped due to cause: ${cause.name}")