diff options
author | 2022-08-23 18:02:28 -0400 | |
---|---|---|
committer | 2022-09-08 09:30:17 -0400 | |
commit | 9d6cf9dc122d8c980e1bc96b86b5c0233c372fd0 (patch) | |
tree | 9a0c4985113da0f1bd2e61c87adf1e1dec25c0d8 /components/slice-analysis-ms/src/test/java/org | |
parent | c21ca66f190f76feb5800ee500ff87ff7e67f5c5 (diff) |
[SLICEANALYSIS] Enhance BandwidthEvaluator to listen on user's bandwidth threshold
Put bandwidth evaluation into seperated evaluationStrategy; minor enhance to bandwidth evalution and adjustment; adding ratelimiter for each network function calling.
Issue-ID: DCAEGEN2-3239
Issue-ID: DCAEGEN2-3195
Signed-off-by: decheng zhang <decheng.zhang@huawei.com>
Change-Id: Id5e64fea0a03b0b41054840911ea6a7336956415
Signed-off-by: decheng zhang <decheng.zhang@huawei.com>
Diffstat (limited to 'components/slice-analysis-ms/src/test/java/org')
6 files changed, 203 insertions, 8 deletions
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java index 3b0c32fa..16745193 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/AaiEventNotificationCallbackTest.java @@ -87,6 +87,7 @@ public class AaiEventNotificationCallbackTest { jsonObject.addProperty("sliceanalysisms.ccvpnEvalPrecision", "1"); jsonObject.addProperty("sliceanalysisms.ccvpnEvalPeriodicCheckOn", "1"); jsonObject.addProperty("sliceanalysisms.ccvpnEvalOnDemandCheckOn", "1"); + jsonObject.addProperty("sliceanalysisms.ccvpnEvalStrategy", "1"); Configuration configuration = Configuration.getInstance(); configuration.updateConfigurationFromJsonObject(jsonObject); doNothing().when(bandwidthEvaluator).post(any()); diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/RateLimiterTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/RateLimiterTest.java new file mode 100644 index 00000000..3f27a3e1 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/RateLimiterTest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.service; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class RateLimiterTest { + + RateLimiter rateLimiter; + + @Before + public void setUp() throws Exception { + rateLimiter = new RateLimiter(1, 5000); + } + + @Test + public void getTokenTest() throws InterruptedException { + rateLimiter.getToken(); + long requestTime1 = System.currentTimeMillis(); + rateLimiter.getToken(); + long requestTime2 = System.currentTimeMillis(); + assertTrue("Actually is: " + (requestTime2 - requestTime1) + , requestTime2 - requestTime1 >= 5000); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java index f0ce5509..2d129393 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/BandwidthEvaluatorTest.java @@ -30,12 +30,24 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import static org.mockito.Mockito.mock; +import java.util.ArrayList; +import java.util.List; + @RunWith(SpringRunner.class) @SpringBootTest(classes = BandwidthEvaluatorTest.class) public class BandwidthEvaluatorTest { + FixedUpperBoundStrategy s1 = new FixedUpperBoundStrategy(); + FlexibleThresholdStrategy s2 = new FlexibleThresholdStrategy(); + + @Spy + private List<EvaluationStrategy> strategies = new ArrayList<>(); + + @Spy + @InjectMocks + StrategyFactory strategyFactory; + @Spy @InjectMocks BandwidthEvaluator bandwidthEvaluator; @@ -43,6 +55,8 @@ public class BandwidthEvaluatorTest { @Before public void setup(){ MockitoAnnotations.initMocks(this); + strategies.add(s1); + strategies.add(s2); } @Test diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java index 1b03de06..673ec6a8 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/CCVPNPmDatastoreTest.java @@ -21,7 +21,6 @@ package org.onap.slice.analysis.ms.service.ccvpn; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -30,9 +29,7 @@ import org.mockito.Spy; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import java.lang.reflect.Field; import java.util.Arrays; -import java.util.concurrent.ConcurrentMap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -58,8 +55,8 @@ public class CCVPNPmDatastoreTest { @Test public void getMaxBwOfSvcTest() { - datastore.updateMaxBw("cll-test", 100, false); - assertEquals(datastore.getMaxBwOfSvc("cll-test"), Integer.valueOf(100)); + datastore.updateProvBw("cll-test", 100, false); + assertEquals(datastore.getProvBwOfSvc("cll-test"), Integer.valueOf(100)); } @Test @@ -100,8 +97,14 @@ public class CCVPNPmDatastoreTest { @Test public void updateMaxBwTest() throws NoSuchFieldException, IllegalAccessException { - datastore.updateMaxBw("cll-01", "300"); - Mockito.verify(datastore, Mockito.atLeastOnce()).updateMaxBw(Mockito.any(String.class), Mockito.any(String.class)); + datastore.updateProvBw("cll-01", "300"); + Mockito.verify(datastore, Mockito.atLeastOnce()).updateProvBw(Mockito.any(String.class), Mockito.any(String.class)); + } + + @Test + public void updateUpperBoundBwTest() throws NoSuchFieldException, IllegalAccessException { + datastore.updateUpperBoundBw("cll-01", 300); + Mockito.verify(datastore, Mockito.atLeastOnce()).updateUpperBoundBw(Mockito.any(String.class), Mockito.any(Integer.class)); } @Test diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategyTest.java new file mode 100644 index 00000000..6d5c8cde --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/FixedUpperBoundStrategyTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.service.ccvpn; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = FixedUpperBoundStrategyTest.class) +public class FixedUpperBoundStrategyTest { + + @Spy + @InjectMocks + BandwidthEvaluator bandwidthEvaluator; + + @Spy + @InjectMocks + FixedUpperBoundStrategy fixedUpperBoundStrategy; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void initTest() { + fixedUpperBoundStrategy.init(); + Mockito.verify(fixedUpperBoundStrategy, Mockito.atLeastOnce()).init(); + } + + @Test + public void executeTest() { + Event evt = new SimpleEvent(null, "{}"); + fixedUpperBoundStrategy.execute(evt); + Mockito.verify(fixedUpperBoundStrategy, Mockito.atLeastOnce()) + .execute(Mockito.any(Event.class)); + } + + @Test + public void getNameTest() { + fixedUpperBoundStrategy.getName(); + Mockito.verify(fixedUpperBoundStrategy, Mockito.atLeastOnce()).getName(); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactoryTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactoryTest.java new file mode 100644 index 00000000..8a938a6e --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/ccvpn/StrategyFactoryTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Huawei Canada Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ +package org.onap.slice.analysis.ms.service.ccvpn; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +public class StrategyFactoryTest { + + private static final String STRATEGY = "FixedUpperBoundStrategy"; + @Mock + FixedUpperBoundStrategy fixedUpperBoundStrategy; + + @Spy + private List<EvaluationStrategy> strategies = new ArrayList<>(); + + @Spy + @InjectMocks + StrategyFactory strategyFactory; + + @Before + public void setup(){ + MockitoAnnotations.initMocks(this); + strategies.add(fixedUpperBoundStrategy); + } + + @Test + public void getStrategyTest(){ + when(fixedUpperBoundStrategy.getName()).thenReturn(STRATEGY); + assertEquals(STRATEGY, strategyFactory.getStrategy(STRATEGY).getName()); + } +} |