/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.awaitility.Awaitility.await;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
assertThatCode(() -> {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(2, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexDeploymentRestMain.ServicesState.RUNNING));
monRestMain.shutdown();
}).doesNotThrowAnyException();
-
}
@After
/*-
* ============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.
package org.onap.policy.apex.client.editor.rest;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.onap.policy.apex.client.editor.rest.ApexEditorMain.EditorState;
}
};
new Thread(testThread).start();
- while (editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)) {
- Thread.sleep(100);
- }
-
+ await().atMost(15000, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)));
editorMain.shutdown();
final String outString = outBaStream.toString();
System.out.println(outString);
/*-
* ============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.
package org.onap.policy.apex.client.editor.rest;
+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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
};
new Thread(testThread).start();
// wait until editorMain is in state RUNNING
- final long startwait = System.currentTimeMillis();
- while (editorMain.getState().equals(EditorState.STOPPED) || editorMain.getState().equals(EditorState.READY)
- || editorMain.getState().equals(EditorState.INITIALIZING)) {
- if (editorMain.getState().equals(EditorState.STOPPED)) {
- Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
- }
- if (System.currentTimeMillis() - startwait > MAX_WAIT) {
- Assert.fail("Rest endpoint (" + editorMain + ") for test failed to start fast enough");
- }
- Thread.sleep(100);
+ await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> !(editorMain.getState().equals(EditorState.READY)
+ || editorMain.getState().equals(EditorState.INITIALIZING)));
+
+ if (editorMain.getState().equals(EditorState.STOPPED)) {
+ Assert.fail("Rest endpoint (" + editorMain + ") shut down before it could be used");
}
// create the client
public static void cleanUpStreams() throws IOException, InterruptedException {
editorMain.shutdown();
// wait until editorMain is in state STOPPED
- final long startwait = System.currentTimeMillis();
- while (!editorMain.getState().equals(EditorState.STOPPED)) {
- if (System.currentTimeMillis() - startwait > MAX_WAIT) {
- Assert.fail("Rest endpoint (" + editorMain + ") for test failed to shutdown fast enough");
- }
- Thread.sleep(50);
- }
+ await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> editorMain.getState().equals(EditorState.STOPPED));
System.setIn(SYSIN);
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.awaitility.Awaitility.await;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
assertThatCode(() -> {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(6, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexServicesRestMain.EditorState.RUNNING));
monRestMain.shutdown();
}).doesNotThrowAnyException();
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
package org.onap.policy.apex.client.monitoring.rest;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
/**
* Test the periodic event manager utility.
try {
monThread.start();
- ThreadUtilities.sleep(2000);
+ await().atMost(6, TimeUnit.SECONDS).until(
+ () -> monRestMain.getState().equals(ApexMonitoringRestMain.ServicesState.RUNNING));
monRestMain.shutdown();
} catch (Exception ex) {
fail("test should not throw an exception");
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
package org.onap.policy.apex.core.deployment;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingService;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingServiceFactory;
import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.core.protocols.Message;
import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus;
import org.onap.policy.apex.core.protocols.engdep.messages.Response;
Thread clientThread = new Thread(deploymentClient);
clientThread.start();
- ThreadUtilities.sleep(100);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> deploymentClient.isStarted());
assertTrue(deploymentClient.isStarted());
assertTrue(clientThread.isAlive());
GetEngineStatus getEngineStatus = new GetEngineStatus(engineKey);
deploymentClient.sendMessage(new GetEngineStatus(engineKey));
- ThreadUtilities.sleep(20);
Response response = new Response(engineKey, true, getEngineStatus);
List<Message> messageList = new ArrayList<>();
messageList.add(response);
assertEquals("String mesages are not supported on the EngDep protocol", use.getMessage());
}
- ThreadUtilities.sleep(300);
- assertEquals(1, deploymentClient.getMessagesSent());
+ await().atMost(300, TimeUnit.MILLISECONDS).until(() -> deploymentClient.getMessagesReceived() == 2);
assertEquals(2, deploymentClient.getMessagesReceived());
deploymentClient.stopClient();
Thread clientThread = new Thread(deploymentClient);
clientThread.start();
- ThreadUtilities.sleep(50);
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> !deploymentClient.isStarted());
assertFalse(deploymentClient.isStarted());
assertFalse(clientThread.isAlive());
assertEquals(0, deploymentClient.getReceiveQueue().size());
- ThreadUtilities.sleep(100);
-
deploymentClient.stopClient();
}
}
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.core.protocols.Message;
import org.onap.policy.apex.core.protocols.engdep.messages.EngineServiceInfoResponse;
import org.onap.policy.apex.core.protocols.engdep.messages.GetEngineInfo;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.common.utils.resources.TextFileUtils;
+import static org.awaitility.Awaitility.await;
+
/**
* Dummy deployment client.
*/
started = true;
// Loop forever, sending messages as they appear on the queue
- while (started && !thisThread.isInterrupted()) {
- ThreadUtilities.sleep(50);
- }
-
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> !(started && !thisThread.isInterrupted()));
// Thread has been interrupted
thisThread = null;
started = false;
/*-
* ============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.
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;
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;
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));
}
}).start();
- Thread.sleep(50);
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING));
assertEquals(AxEngineState.EXECUTING, engine.getState());
try {
engine.stop();
/*-
* ============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.
Thread.sleep(waitTime);
}
catch (InterruptedException ie) {
- // Do nothing
+ //Do nothing
}
}
/*-
* ============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.
package org.onap.policy.apex.core.infrastructure.messaging;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
+import java.util.concurrent.TimeUnit;
+
/**
* The Class EndToEndMessagingTest.
*
client.sendString("Hello, client here");
- while (!finished) {
- ThreadUtilities.sleep(50);
- }
+ await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> finished);
+
} finally {
if (client != null) {
client.stop();
/*-
* ============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.
System.out.println("StringTestServer started on port " + port + " for " + timeToLive + " seconds");
- for (; timeToLive > 0; timeToLive--) {
- ThreadUtilities.sleep(1000);
- }
+ // convert to milliSeconds
+ ThreadUtilities.sleep(1000 * timeToLive);
server.stop();
System.out.println("StringTestServer completed");
/*-
* ============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.
package org.onap.policy.apex.core.infrastructure.threading;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.slf4j.ext.XLogger;
final Thread thread = threadFactory.newThread(runnable);
thread.start();
- }
+ if (i == 4) {
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> thread.isAlive());
+ }
- // Threads should need a little more than 300ms to count to 3
- ThreadUtilities.sleep(380);
+ }
for (int i = 0; i < 5; i++) {
threadList.get(i).interrupt();
/*-
* ============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.
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
+import java.util.concurrent.CountDownLatch;
+
/**
* The Class ThreadingTestThread.
*
private String threadName;
- /**
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ /**
* {@inheritDoc}.
*/
@Override
if (logger.isDebugEnabled()) {
logger.debug("in threading test thread \"" + threadName + "\", counter=" + counter + " . . .");
}
-
- if (!ThreadUtilities.sleep(50)) {
+ if(!ThreadUtilities.sleep(50)) {
interrupted = true;
}
}
+
if (logger.isDebugEnabled()) {
logger.debug("stopped threading test thread \"" + threadName + "\"");
}
/*-
* ============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.
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
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
*/
@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);
}
/**
/*-
* ============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.
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;
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;
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();
}
result.clear();
}
apexEngine1.stop();
- ThreadUtilities.sleep(1000);
+ await().atLeast(1000, TimeUnit.MILLISECONDS).until(() -> apexEngine1.getState().equals(AxEngineState.STOPPED));
}
/**
/*-
* ============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.
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.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;
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();
}
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));
}
/**
/*-
* ============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.
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
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
*/
@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);
/*-
* ============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.
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
* @return the result
*/
public EnEvent getResult() {
- while (resultEvents.isEmpty()) {
- ThreadUtilities.sleep(100);
- }
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> !resultEvents.isEmpty());
return resultEvents.remove(0);
}
*/
@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);
/*-
* ============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.
package org.onap.policy.apex.plugins.event.carrier.restclient;
+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.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Invocation.Builder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
}
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
-
assertEquals(0, incomingEventReceiver.getEventCount());
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
}
@Test
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("received an empty event from URL \"http://some.place.that.does.not/exist\""));
arcc.stop();
assertEquals(0, incomingEventReceiver.getEventCount());
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(400, TimeUnit.MILLISECONDS).until(
+ () -> incomingEventReceiver.getLastEvent().equals("This is an event"));
arcc.stop();
-
- assertEquals("This is an event", incomingEventReceiver.getLastEvent());
}
@Test
try {
// We have not set the URL, this test should not receive any events
arcc.start();
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> incomingEventReceiver.getEventCount() == 0);
arcc.stop();
} catch (Exception e) {
// test invalid status code
/*-
* ============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.
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
consumer.start();
ApexRestRequest request = new ApexRestRequest(123, null, EVENT_NAME, EVENT_BODY);
consumer.processRestRequest(request);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> consumer.getEventsReceived() == 0);
consumer.stop();
assertEquals(0, consumer.getEventsReceived());
}
consumer.start();
ApexRestRequest request = new ApexRestRequest(123, properties, EVENT_NAME, EVENT_BODY);
consumer.processRestRequest(request);
- ThreadUtilities.sleep(2000);
+ await().atMost(2000, TimeUnit.MILLISECONDS).until(() -> consumer.getEventsReceived() == 0);
consumer.stop();
assertEquals(0, consumer.getEventsReceived());
}
/*-
* ============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.
client.close();
assertEquals(Double.valueOf(8.0), getsSoFar);
-
- ThreadUtilities.sleep(1000);
}
/**
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
package org.onap.policy.apex.service.engine.main;
+import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
import org.junit.After;
import org.junit.Test;
-import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.parameters.ApexParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
System.setOut(new PrintStream(outContent));
ApexMain.main(null);
- ThreadUtilities.sleep(200);
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Apex configuration file was not specified as an argument"));
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Apex configuration file was not specified as an argument"));
}
@Test
String[] args = { "-whee" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("invalid command line arguments specified : Unrecognized option: -whee"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee"));
}
@Test
String[] args = { "-h" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
}
@Test
String[] args = { "-c", "src/test/resources/parameters/badParams.json" };
final ApexMain apexMain = new ApexMain(args);
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("parameter group has status INVALID"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("parameter group has status INVALID"));
}
@Test
final ApexMain apexMain = new ApexMain(args);
assertEquals("MyApexEngine",
apexMain.getApexParametersMap().values().iterator().next().getEngineServiceParameters().getName());
- ThreadUtilities.sleep(200);
+ await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test
assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore"));
assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword"));
- ThreadUtilities.sleep(200);
+ await().atMost(10000, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
+ .contains("Added the action listener to the engine"));
apexMain.shutdown();
-
- ThreadUtilities.sleep(10000);
- final String outString = outContent.toString();
-
- assertTrue(outString.contains("Added the action listener to the engine"));
}
@Test