2 * ============LICENSE_START====================================
3 * DCAEGEN2-SERVICES-SDK
4 * =========================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
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=====================================
21 package org.onap.dcaegen2.services.sdk.standardization.moher.metrics.impl;
23 import io.micrometer.core.instrument.Counter;
24 import io.micrometer.prometheus.PrometheusMeterRegistry;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.Metrics;
28 import org.onap.dcaegen2.services.sdk.standardization.moher.metrics.api.MetricsFactory;
29 import reactor.test.StepVerifier;
31 import java.time.Duration;
33 import static org.junit.jupiter.api.Assertions.assertTrue;
37 private static final String COUNTER_NAME = "Duplicates_Amount";
38 private static final String GAUGE_NAME = "gauge_Duplicates_Amount";
39 private static final String TIMER_NAME = "Duplicates_Amount_timer";
40 private static final String SUMMARY_NAME = "Duplicates_Amount_summary";
41 private static final Duration INTERVAL = Duration.ofMillis(100);
43 private PrometheusMeterRegistry defaultRegistry;
48 defaultRegistry = MetricsFactory.createDefaultRegistry();
49 cut = MetricsFactory.createMetrics(defaultRegistry);
53 void metrics_givenDefaultRegistry_shouldReturnCreatedMeters() {
55 Counter counter = defaultRegistry.counter(COUNTER_NAME);
56 defaultRegistry.gauge(GAUGE_NAME, counter.count());
57 defaultRegistry.timer(TIMER_NAME);
58 defaultRegistry.summary(SUMMARY_NAME);
60 StepVerifier.create(cut.collect())
61 .expectNextMatches((collectedMetrics) ->
62 collectedMetrics.contains(COUNTER_NAME) &&
63 collectedMetrics.contains(GAUGE_NAME) &&
64 collectedMetrics.contains(TIMER_NAME) &&
65 collectedMetrics.contains(SUMMARY_NAME)
71 void metrics_givenDefaultRegistry_shouldReturnCreatedMetersInIntervals() {
73 Counter counter = defaultRegistry.counter(COUNTER_NAME);
76 cut.collect(INTERVAL).take(2)
78 .consumeNextWith((collectedMetrics) -> {
79 assertTrue(collectedMetrics.contains(COUNTER_NAME));
83 .expectNextMatches((collectedMetrics) ->
84 collectedMetrics.contains(COUNTER_NAME + "_total 1.0"))