From 0d61c432b2604f0459dea95bbd328c279b04fbef Mon Sep 17 00:00:00 2001 From: emaclee Date: Wed, 11 Dec 2024 14:58:25 +0000 Subject: Add gauge metric for NCMP "cmhandle states" Issue-ID: CPS-2456 Change-Id: I1aebcc68dfdc9c48c230c74376742d67b05c0615 Signed-off-by: emaclee --- .../onap/cps/config/MicroMeterConfigSpec.groovy | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'cps-application/src/test/groovy') diff --git a/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy b/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy index 61bc2cf027..67ca64624a 100644 --- a/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy +++ b/cps-application/src/test/groovy/org/onap/cps/config/MicroMeterConfigSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * Copyright (C) 2023-2025 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,16 +20,36 @@ package org.onap.cps.config +import com.hazelcast.map.IMap import io.micrometer.core.instrument.simple.SimpleMeterRegistry import spock.lang.Specification class MicroMeterConfigSpec extends Specification { - def objectUnderTest = new MicroMeterConfig() + def cmHandlesByState = Mock(IMap) + def objectUnderTest = new MicroMeterConfig(cmHandlesByState) + def simpleMeterRegistry = new SimpleMeterRegistry() - def 'Creating a tined aspect.'() { + def 'Creating a timed aspect.'() { expect: ' a timed aspect can be created' - assert objectUnderTest.timedAspect(new SimpleMeterRegistry()) != null + assert objectUnderTest.timedAspect(simpleMeterRegistry) != null + } + + def 'Creating gauges for cm handle states.'() { + given: 'cache returns value for each state' + cmHandlesByState.get(_) >> 1 + when: 'gauges for each state are created' + objectUnderTest.advisedCmHandles(simpleMeterRegistry) + objectUnderTest.readyCmHandles(simpleMeterRegistry) + objectUnderTest.lockedCmHandles(simpleMeterRegistry) + objectUnderTest.deletingCmHandles(simpleMeterRegistry) + objectUnderTest.deletedCmHandles(simpleMeterRegistry) + then: 'each state has the correct value when queried' + def states = ["ADVISED", "READY", "LOCKED", "DELETING", "DELETED"] + states.each { state -> + def gaugeValue = simpleMeterRegistry.get("cmHandlesByState").tag("state",state).gauge().value() + assert gaugeValue == 1 + } } } -- cgit 1.2.3-korg