2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.runtime.supervision;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import org.junit.jupiter.api.Test;
27 class HandleCounterTest {
29 private static final int ID = 1;
33 var handleCounter = new HandleCounter<Integer>();
34 handleCounter.setMaxRetryCount(2);
35 assertThat(handleCounter.count(ID)).isTrue();
36 assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
37 assertThat(handleCounter.count(ID)).isTrue();
38 assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
39 assertThat(handleCounter.count(ID)).isFalse();
40 assertThat(handleCounter.getCounter(ID)).isEqualTo(2);
42 handleCounter.clear(ID);
43 assertThat(handleCounter.count(ID)).isTrue();
44 assertThat(handleCounter.getCounter(ID)).isEqualTo(1);
49 var handleCounter = new HandleCounter<Integer>();
50 handleCounter.setFault(ID);
51 assertThat(handleCounter.isFault(ID)).isTrue();
52 handleCounter.clear(ID);
53 assertThat(handleCounter.isFault(ID)).isFalse();
57 void testDuration() throws InterruptedException {
59 var handleCounter = new HandleCounter<Integer>() {
63 protected long getEpochMilli() {
67 handleCounter.epochMilli = 100;
68 var result = handleCounter.getDuration(ID);
69 assertThat(result).isZero();
71 handleCounter.epochMilli += 100;
72 result = handleCounter.getDuration(ID);
73 assertThat(result).isEqualTo(100);
75 handleCounter.epochMilli += 100;
76 result = handleCounter.getDuration(ID);
77 assertThat(result).isEqualTo(200);
79 handleCounter.epochMilli += 100;
80 handleCounter.clear(ID);
81 result = handleCounter.getDuration(ID);
82 assertThat(result).isZero();