From 153ad0056c3928116d28eb7e1bb14c4a04a76fc2 Mon Sep 17 00:00:00 2001 From: "Henry.Sun" Date: Mon, 2 Mar 2020 15:47:09 +0800 Subject: replace test sleep() with awaitality package Signed-off-by: Henry.Sun Change-Id: I305771ddef42bd3032ad52f4c5ecd55b01ed5a1a Issue-ID: POLICY-1914 Signed-off-by: Henry.Sun --- .../apex/core/engine/engine/impl/ApexEngineImplTest.java | 10 ++++++---- .../apex/core/engine/engine/impl/DummySlowEnEventListener.java | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'core/core-engine/src') diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java index 2663dfc0d..f91b58bb9 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 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. @@ -22,6 +22,7 @@ package org.onap.policy.apex.core.engine.engine.impl; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -32,6 +33,8 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.lang.reflect.Field; import java.util.HashMap; +import java.util.concurrent.TimeUnit; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -312,8 +315,7 @@ public class ApexEngineImplTest { assertEquals(AxEngineState.STOPPED, engine.getState()); } }).start(); - - Thread.sleep(50); + await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING)); assertEquals(AxEngineState.EXECUTING, engine.getState()); assertFalse(engine.handleEvent(event)); @@ -343,7 +345,7 @@ public class ApexEngineImplTest { } }).start(); - Thread.sleep(50); + await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING)); assertEquals(AxEngineState.EXECUTING, engine.getState()); try { engine.stop(); diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java index 9b6fc398c..178e16a43 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * 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. @@ -41,7 +42,7 @@ public class DummySlowEnEventListener implements EnEventListener { Thread.sleep(waitTime); } catch (InterruptedException ie) { - // Do nothing + //Do nothing } } -- cgit 1.2.3-korg