diff options
author | Liam Fallon <liam.fallon@est.tech> | 2020-03-04 13:32:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-04 13:32:27 +0000 |
commit | a9b60303e7e3699cc4df904144592ea6a9b6c586 (patch) | |
tree | 1b710f2f899598d3032a6485db54c2e4a8cc92a2 /examples | |
parent | 9f17d75f75dd087a58822dcc5aa2821267aa2193 (diff) | |
parent | 153ad0056c3928116d28eb7e1bb14c4a04a76fc2 (diff) |
Merge "replace test sleep() with awaitality package"
Diffstat (limited to 'examples')
5 files changed, 31 insertions, 31 deletions
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java index 03372d745..bca901e6b 100644 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +23,11 @@ package org.onap.policy.apex.examples.aadm; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import org.onap.policy.apex.core.engine.engine.EnEventListener; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import static org.awaitility.Awaitility.await; /** * The listener interface for receiving testApexAction events. The class that is interested in processing a @@ -55,9 +57,7 @@ public class TestApexActionListener implements EnEventListener { * @return the result */ public EnEvent getResult() { - while (resultEvents.isEmpty()) { - ThreadUtilities.sleep(100); - } + await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty()); return resultEvents.remove(0); } @@ -66,12 +66,9 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - ThreadUtilities.sleep(100); - - if (actionEvent != null) { - System.out.println("Action event from engine:" + actionEvent.getName()); - resultEvents.add(actionEvent); - } + await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> actionEvent != null); + System.out.println("Action event from engine:" + actionEvent.getName()); + resultEvents.add(actionEvent); } /** diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java index 7ada6a795..d1b2aaae7 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ package org.onap.policy.apex.examples.adaptive; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Random; +import java.util.concurrent.TimeUnit; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -38,11 +41,11 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; @@ -149,7 +152,7 @@ public class AnomalyDetectionTslUseCaseTest { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - ThreadUtilities.sleep(1); + await().atLeast(1, TimeUnit.MILLISECONDS).until(() -> result.isEmpty()); apexEngine1.stop(); } @@ -216,7 +219,7 @@ public class AnomalyDetectionTslUseCaseTest { result.clear(); } apexEngine1.stop(); - ThreadUtilities.sleep(1000); + await().atLeast(1000, TimeUnit.MILLISECONDS).until(() -> apexEngine1.getState().equals(AxEngineState.STOPPED)); } /** diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java index d40dcc672..ab0bf303f 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,14 @@ package org.onap.policy.apex.examples.adaptive; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.Random; +import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; @@ -39,11 +41,11 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; @@ -148,7 +150,7 @@ public class AutoLearnTslUseCaseTest { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - ThreadUtilities.sleep(10); + await().atLeast(10, TimeUnit.MILLISECONDS).until(() -> triggerEvent.isEmpty() && result.isEmpty()); apexEngine1.stop(); } @@ -236,11 +238,11 @@ public class AutoLearnTslUseCaseTest { LOGGER.info("Iteration " + iteration + ": \tpreval\t" + prevval + "\tval\t" + val + "\tavval\t" + avval); result.clear(); - ThreadUtilities.sleep(10); + await().atLeast(10, TimeUnit.MILLISECONDS).until(() -> !result.isEmpty()); } apexEngine1.stop(); - ThreadUtilities.sleep(1000); + await().atMost(1000, TimeUnit.MILLISECONDS).until(() -> apexEngine1.getState().equals(AxEngineState.STOPPED)); } /** diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java index cd1327123..28924728e 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +23,12 @@ package org.onap.policy.apex.examples.adaptive; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import org.onap.policy.apex.core.engine.engine.EnEventListener; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; + +import static org.awaitility.Awaitility.await; /** * The listener interface for receiving testApexAction events. The class that is interested in processing a @@ -55,9 +58,7 @@ public class TestApexActionListener implements EnEventListener { * @return the result */ public EnEvent getResult() { - while (resultEvents.isEmpty()) { - ThreadUtilities.sleep(100); - } + await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty()); return resultEvents.remove(0); } @@ -66,8 +67,6 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - ThreadUtilities.sleep(100); - if (actionEvent != null) { System.out.println("Action event from engine:" + actionEvent.getName()); resultEvents.add(actionEvent); diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java index 3fce59c93..0169d14cb 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +23,12 @@ package org.onap.policy.apex.examples.myfirstpolicy; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import org.onap.policy.apex.core.engine.engine.EnEventListener; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; + +import static org.awaitility.Awaitility.await; /** * The listener interface for receiving SaleAuth events. The class that is interested in processing a SaleAuth event @@ -57,9 +60,7 @@ public class TestSaleAuthListener implements EnEventListener { * @return the result */ public EnEvent getResult() { - while (resultEvents.isEmpty()) { - ThreadUtilities.sleep(100); - } + await().atMost(200, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty()); return resultEvents.remove(0); } @@ -68,8 +69,6 @@ public class TestSaleAuthListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent saleauthEvent) { - ThreadUtilities.sleep(100); - if (saleauthEvent != null) { System.out.println("SaleAuth event from engine:" + saleauthEvent.getName()); resultEvents.add(saleauthEvent); |