2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
24 import java.time.Duration;
25 import java.time.Instant;
26 import org.junit.Test;
27 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.utils.RateFilter;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * {@link #RateFilter} Problems of to many notifications during mount of thousand of devices.
35 * Testcase (e: 17 Event received, rateMaxCount=3)
36 * eee e e e e e e e e e e e e e e
37 * ---//--|--------------|-----//-------|--------------|--------------|--------------|---//----|--------------|
38 * P1:1 P2:1 P1:2 P2:2 P3:2 P4:2 P1:3
39 * 1000-1002 2000 3500 10 millis
40 *Overload no no yes yes no no
44 public class RateFilterTest {
46 private static final Logger LOG = LoggerFactory.getLogger(RateFilterTest.class.getName());
48 private static int MILLIS = 1000;
49 private static long[] now = { 1000, 1001, 1002, //P1:1 0-2
50 3500, 3550, 3560, 3570, 3580, 3590, 3800, //P1:2 3500 3-9
51 4510, 4520, 4530, 4540, 4900, //P2:2 4500 10-14
53 7000, 8000};//P1:3 16-17
54 private static int idx;
58 RateFilter rateFilter = new RateFilter(Duration.ofMillis(MILLIS), 4, () -> getNow());
59 LOG.info("Init done");
61 for (int t=0; t < 20; t++) {
63 rateFilter.filterEvent();
64 LOG.info("{}", rateFilter.getOverloadStatus());
71 if (idx < now.length) {
74 int lastIdx = now.length - 1;
75 res = now[lastIdx] + (idx - lastIdx) * MILLIS;
78 return Instant.ofEpochMilli(res);