From 4ab95420e42f6df59bd4851eee41be6579bdbbe1 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Mon, 17 Dec 2018 16:03:10 +0100 Subject: Add metrics for active connections count * Fix and refactor gauges tests in MicrometerMetricsTests as they were not executing * Fix client disconnection handler in NettyTcpServer * Add metrics gauge and counters required to measure active connections Change-Id: I5620d398525c6859679cd5a49dc55a9fefd8b592 Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-1041 --- .../veshv/tests/component/MetricsSpecification.kt | 3 +-- .../dcae/collectors/veshv/tests/fakes/metrics.kt | 26 +++++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'sources/hv-collector-ct/src/test') diff --git a/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/MetricsSpecification.kt b/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/MetricsSpecification.kt index 572cc796..f457aeaf 100644 --- a/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/MetricsSpecification.kt +++ b/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/MetricsSpecification.kt @@ -175,7 +175,6 @@ object MetricsSpecification : Spek({ } describe("clients rejected metrics") { - given("rejection causes") { mapOf( ClientRejectionCause.PAYLOAD_SIZE_EXCEEDED_IN_MESSAGE to @@ -192,7 +191,7 @@ object MetricsSpecification : Spek({ assertThat(metrics.clientRejectionCause.size) .describedAs("metrics were notified with only one rejection cause") .isOne() - assertThat(metrics.clientRejectionCause.get(cause)) + assertThat(metrics.clientRejectionCause[cause]) .describedAs("metrics were notified only once with correct client rejection cause") .isOne() } diff --git a/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/fakes/metrics.kt b/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/fakes/metrics.kt index a27d167a..8573d86f 100644 --- a/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/fakes/metrics.kt +++ b/sources/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/fakes/metrics.kt @@ -21,12 +21,11 @@ package org.onap.dcae.collectors.veshv.tests.fakes import org.onap.dcae.collectors.veshv.boundary.Metrics import org.onap.dcae.collectors.veshv.domain.WireFrameMessage +import org.onap.dcae.collectors.veshv.model.ClientRejectionCause import org.onap.dcae.collectors.veshv.model.MessageDropCause import org.onap.dcae.collectors.veshv.model.RoutedMessage import java.time.Duration import java.time.Instant -import org.onap.dcae.collectors.veshv.model.ClientRejectionCause -import java.util.concurrent.ConcurrentHashMap import kotlin.test.fail /** @@ -35,14 +34,15 @@ import kotlin.test.fail */ class FakeMetrics : Metrics { - var bytesReceived: Int = 0 ; private set - var messageBytesReceived: Int = 0 ; private set - var messagesDroppedCount: Int = 0 ; private set - var lastProcessingTimeMicros: Double = -1.0 ; private set - private val messagesDroppedCause: MutableMap = ConcurrentHashMap() - var messagesSentCount: Int = 0 ; private set - val messagesSentToTopic: MutableMap = ConcurrentHashMap() - var clientRejectionCause = mutableMapOf() ; private set + var bytesReceived: Int = 0; private set + var messageBytesReceived: Int = 0; private set + var messagesDroppedCount: Int = 0; private set + var lastProcessingTimeMicros: Double = -1.0; private set + var messagesSentCount: Int = 0; private set + var clientRejectionCause = mutableMapOf(); private set + + private val messagesSentToTopic = mutableMapOf() + private val messagesDroppedCause = mutableMapOf() override fun notifyBytesReceived(size: Int) { bytesReceived += size @@ -69,6 +69,12 @@ class FakeMetrics : Metrics { clientRejectionCause.compute(cause) { k, _ -> clientRejectionCause[k]?.inc() ?: 1 } } + override fun notifyClientDisconnected() { + } + + override fun notifyClientConnected() { + } + fun messagesOnTopic(topic: String) = messagesSentToTopic[topic] ?: fail("No messages were sent to topic $topic") -- cgit 1.2.3-korg