summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-07-17 16:16:01 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-17 16:16:01 +0000
commitf9024ec5854f9b528a0e3485a1d2fdc5830ab2ac (patch)
treea48f453a283691272037546cff17b7e947691141 /core
parent28eced32d2acdf731f7782e14f37bf2ea8c98019 (diff)
parent8cedec370948950ba52a89b689b478d884b2c055 (diff)
Merge "Fix double initiation error on EngineServiceFacade"
Diffstat (limited to 'core')
-rw-r--r--core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java48
-rw-r--r--core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java164
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java94
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java21
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java77
-rw-r--r--core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java108
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java6
7 files changed, 246 insertions, 272 deletions
diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java
index 6ec19fcfa..517deeb57 100644
--- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.java
+++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/BatchDeployer.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.
@@ -28,11 +29,13 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class {@link BatchDeployer} deploys an Apex model held as an XML or Json file onto an Apex engine. It uses the
- * EngDep protocol to communicate with the engine, with the EngDep protocol being carried on Java web sockets.
+ * The Class {@link BatchDeployer} deploys an Apex model held as an XML or Json
+ * file onto an Apex engine. It uses the EngDep protocol to communicate with the
+ * engine, with the EngDep protocol being carried on Java web sockets.
*
- * <p>This deployer is a simple command line deployer that reads the communication parameters and the location of the
- * Apex model file as arguments.
+ * <p>This deployer is a simple command line deployer that reads the
+ * communication parameters and the location of the Apex model file as
+ * arguments.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -51,8 +54,8 @@ public class BatchDeployer {
/**
* Instantiates a new deployer.
*
- * @param hostName the apex host name
- * @param port the apex EngDep port
+ * @param hostName the apex host name
+ * @param port the apex EngDep port
* @param outputStream the output stream
*/
public BatchDeployer(final String hostName, final int port, final PrintStream outputStream) {
@@ -63,7 +66,8 @@ public class BatchDeployer {
}
/**
- * Initializes the deployer, opens an EngDep communication session with the Apex engine.
+ * Initializes the deployer, opens an EngDep communication session with the Apex
+ * engine.
*
* @throws ApexDeploymentException thrown on deployment and communication errors
*/
@@ -72,8 +76,7 @@ public class BatchDeployer {
engineServiceFacade.init();
} catch (final ApexException e) {
final String errorMessage = "model deployment failed on parameters " + hostName + " " + port;
- LOGGER.error(errorMessage, e);
- throw new ApexDeploymentException(errorMessage);
+ throw new ApexDeploymentException(errorMessage, e);
}
}
@@ -89,9 +92,12 @@ public class BatchDeployer {
/**
* Deploy an Apex model on the Apex server.
*
- * @param modelFileName the name of the model file containing the model to deploy
- * @param ignoreConflicts true if conflicts between context in polices is to be ignored
- * @param force true if the model is to be applied even if it is incompatible with the existing model
+ * @param modelFileName the name of the model file containing the model to
+ * deploy
+ * @param ignoreConflicts true if conflicts between context in polices is to be
+ * ignored
+ * @param force true if the model is to be applied even if it is
+ * incompatible with the existing model
* @throws ApexException on Apex errors
*/
public void deployModel(final String modelFileName, final boolean ignoreConflicts, final boolean force)
@@ -102,9 +108,11 @@ public class BatchDeployer {
/**
* Deploy an Apex model on the Apex server.
*
- * @param policyModel the model to deploy
- * @param ignoreConflicts true if conflicts between context in polices is to be ignored
- * @param force true if the model is to be applied even if it is incompatible with the existing model
+ * @param policyModel the model to deploy
+ * @param ignoreConflicts true if conflicts between context in polices is to be
+ * ignored
+ * @param force true if the model is to be applied even if it is
+ * incompatible with the existing model
* @throws ApexException on Apex errors
*/
public void deployModel(final AxPolicyModel policyModel, final boolean ignoreConflicts, final boolean force)
@@ -113,7 +121,8 @@ public class BatchDeployer {
}
/**
- * Get the engine service facade of the event manager. This method is used for testing only.
+ * Get the engine service facade of the event manager. This method is used for
+ * testing only.
*
* @return the engine service facade
*/
@@ -122,10 +131,11 @@ public class BatchDeployer {
}
/**
- * The main method, reads the Apex server host address, port and location of the Apex model file from the command
- * line arguments.
+ * The main method, reads the Apex server host address, port and location of the
+ * Apex model file from the command line arguments.
*
- * @param args the arguments that specify the Apex engine and the Apex model file
+ * @param args the arguments that specify the Apex engine and the Apex model
+ * file
* @throws ApexException on deployment errors
*/
public static void main(final String[] args) throws ApexException {
diff --git a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java
index 9dfcf4d1a..1a09ffe56 100644
--- a/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.java
+++ b/core/core-deployment/src/main/java/org/onap/policy/apex/core/deployment/EngineServiceFacade.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.
@@ -48,11 +49,12 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * The Class Deployer deploys an Apex model held as an XML file onto an Apex engine. It uses the EngDep protocol to
- * communicate with the engine, with the EngDep protocol being carried on Java web sockets.
+ * The Class Deployer deploys an Apex model held as an XML file onto an Apex
+ * engine. It uses the EngDep protocol to communicate with the engine, with the
+ * EngDep protocol being carried on Java web sockets.
*
- * <p>This deployer is a simple command line deployer that reads the communication parameters and the location of
- * the XML model file as arguments.
+ * <p>This deployer is a simple command line deployer that reads the
+ * communication parameters and the location of the XML model file as arguments.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
@@ -64,7 +66,8 @@ public class EngineServiceFacade {
private static final String RECEIVED_FROM_SERVER = " received from server";
private static final String FAILED_RESPONSE = "failed response ";
- // The default message timeout and timeout increment (the amount of time between polls) in
+ // The default message timeout and timeout increment (the amount of time between
+ // polls) in
// milliseconds
private static final int CLIENT_START_WAIT_INTERVAL = 100;
private static final int REPLY_MESSAGE_TIMEOUT_DEFAULT = 10000;
@@ -74,7 +77,8 @@ public class EngineServiceFacade {
private final String hostName;
private final int port;
- // The deployment client handles the EngDep communication session towards the Apex server
+ // The deployment client handles the EngDep communication session towards the
+ // Apex server
private DeploymentClient client = null;
private Thread clientThread = null;
@@ -87,27 +91,36 @@ public class EngineServiceFacade {
* Instantiates a new deployer.
*
* @param hostName the host name of the host running the Apex Engine
- * @param port the port to use for EngDep communication with the Apex engine
+ * @param port the port to use for EngDep communication with the Apex engine
*/
public EngineServiceFacade(final String hostName, final int port) {
this.hostName = hostName;
this.port = port;
- // Use the deployment client to handle the EngDep communication towards the Apex server.
+ // Use the deployment client to handle the EngDep communication towards the Apex
+ // server.
client = new DeploymentClient(hostName, port);
}
/**
- * Initializes the facade, opens an EngDep communication session with the Apex engine.
+ * Initializes the facade, opens an EngDep communication session with the Apex
+ * engine.
*
* @throws ApexDeploymentException thrown on deployment and communication errors
*/
public void init() throws ApexDeploymentException {
+
+ if (client.isStarted()) {
+ throw new ApexDeploymentException("connection already active to " + hostName + ":" + port);
+ }
+
try {
LOGGER.debug("handshaking with server {}:{} . . .", hostName, port);
- // Use the deployment client to handle the EngDep communication towards the Apex server.
- // The deployment client runs a thread to monitor the session and to send messages
+ // Use the deployment client to handle the EngDep communication towards the Apex
+ // server.
+ // The deployment client runs a thread to monitor the session and to send
+ // messages
clientThread = new Thread(client);
clientThread.start();
@@ -116,8 +129,7 @@ public class EngineServiceFacade {
if (clientThread.isAlive()) {
ThreadUtilities.sleep(CLIENT_START_WAIT_INTERVAL);
} else {
- LOGGER.error("cound not handshake with server {}:{}", hostName, port);
- throw new ApexDeploymentException("cound not handshake with server " + hostName + ":" + port);
+ throw new ApexDeploymentException("could not handshake with server " + hostName + ":" + port);
}
}
@@ -126,21 +138,24 @@ public class EngineServiceFacade {
// Get engine service information to see what engines we're dealing with
final GetEngineServiceInfo engineServiceInfo = new GetEngineServiceInfo(null);
LOGGER.debug("sending get engine service info message {} to server {}:{} . . .", engineServiceInfo,
- hostName, port);
+ hostName, port);
client.sendMessage(engineServiceInfo);
LOGGER.debug("sent get engine service info message to server {}:{} . . .", hostName, port);
- final EngineServiceInfoResponse engineServiceInfoResponse =
- (EngineServiceInfoResponse) getResponse(engineServiceInfo);
+ final EngineServiceInfoResponse engineServiceInfoResponse = (EngineServiceInfoResponse) getResponse(
+ engineServiceInfo);
if (engineServiceInfoResponse.isSuccessful()) {
engineServiceKey = engineServiceInfoResponse.getEngineServiceKey();
engineKeyArray = engineServiceInfoResponse.getEngineKeyArray();
apexModelKey = engineServiceInfoResponse.getApexModelKey();
+ } else {
+ throw new ApexDeploymentException(
+ "could not get engine service information from server " + hostName + ":" + port);
}
+
} catch (final Exception e) {
- LOGGER.error("cound not handshake with server {}:{}", hostName, port, e);
client.stopClient();
- throw new ApexDeploymentException("cound not handshake with server " + hostName + ":" + port, e);
+ throw new ApexDeploymentException("could not handshake with server " + hostName + ":" + port, e);
}
}
@@ -178,7 +193,9 @@ public class EngineServiceFacade {
public void close() {
LOGGER.debug("closing connection to server {}:{} . . .", hostName, port);
- client.stopClient();
+ if (client.isStarted()) {
+ client.stopClient();
+ }
LOGGER.debug("closed connection to server {}:{} . . .", hostName, port);
}
@@ -186,16 +203,18 @@ public class EngineServiceFacade {
/**
* Deploy an Apex model on the Apex engine service.
*
- * @param modelFileName the name of the model file containing the model to deploy
- * @param ignoreConflicts true if conflicts between context in polices is to be ignored
- * @param force true if the model is to be applied even if it is incompatible with the existing model
+ * @param modelFileName the name of the model file containing the model to
+ * deploy
+ * @param ignoreConflicts true if conflicts between context in polices is to be
+ * ignored
+ * @param force true if the model is to be applied even if it is
+ * incompatible with the existing model
* @throws ApexException on Apex errors
*/
public void deployModel(final String modelFileName, final boolean ignoreConflicts, final boolean force)
- throws ApexException {
+ throws ApexException {
if (engineServiceKey == null || engineKeyArray == null || engineKeyArray.length == 0) {
- LOGGER.error("cound not deploy apex model, deployer is not initialized");
- throw new ApexDeploymentException("cound not deploy apex model, deployer is not initialized");
+ throw new ApexDeploymentException("could not deploy apex model, deployer is not initialized");
}
// Get the model file as a string
@@ -203,9 +222,8 @@ public class EngineServiceFacade {
if (apexModelUrl == null) {
apexModelUrl = ResourceUtils.getUrlResource(modelFileName);
if (apexModelUrl == null) {
- LOGGER.error("cound not create apex model, could not read from file {}", modelFileName);
throw new ApexDeploymentException(
- "cound not create apex model, could not read from file " + modelFileName);
+ "could not create apex model, could not read from file " + modelFileName);
}
}
@@ -213,7 +231,6 @@ public class EngineServiceFacade {
deployModel(modelFileName, apexModelUrl.openStream(), ignoreConflicts, force);
} catch (final Exception deployException) {
final String errorMessage = "could not deploy apex model from " + modelFileName;
- LOGGER.error(errorMessage, deployException);
throw new ApexDeploymentException(errorMessage, deployException);
}
}
@@ -221,14 +238,17 @@ public class EngineServiceFacade {
/**
* Deploy an Apex model on the Apex engine service.
*
- * @param modelFileName the name of the model file containing the model to deploy
+ * @param modelFileName the name of the model file containing the model to
+ * deploy
* @param modelInputStream the stream that holds the Apex model
- * @param ignoreConflicts true if conflicts between context in polices is to be ignored
- * @param force true if the model is to be applied even if it is incompatible with the existing model
+ * @param ignoreConflicts true if conflicts between context in polices is to be
+ * ignored
+ * @param force true if the model is to be applied even if it is
+ * incompatible with the existing model
* @throws ApexException on model deployment errors
*/
public void deployModel(final String modelFileName, final InputStream modelInputStream,
- final boolean ignoreConflicts, final boolean force) throws ApexException {
+ final boolean ignoreConflicts, final boolean force) throws ApexException {
// Read the policy model from the stream
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
modelReader.setValidateFlag(!ignoreConflicts);
@@ -242,20 +262,22 @@ public class EngineServiceFacade {
* Deploy an Apex model on the Apex engine service.
*
* @param apexPolicyModel the name of the model to deploy
- * @param ignoreConflicts true if conflicts between context in polices is to be ignored
- * @param force true if the model is to be applied even if it is incompatible with the existing model
+ * @param ignoreConflicts true if conflicts between context in polices is to be
+ * ignored
+ * @param force true if the model is to be applied even if it is
+ * incompatible with the existing model
* @throws ApexException on model deployment errors
*/
public void deployModel(final AxPolicyModel apexPolicyModel, final boolean ignoreConflicts, final boolean force)
- throws ApexException {
+ throws ApexException {
// Write the model into a byte array
final ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
final ApexModelWriter<AxPolicyModel> modelWriter = new ApexModelWriter<>(AxPolicyModel.class);
modelWriter.write(apexPolicyModel, baOutputStream);
// Create and send Update message
- final UpdateModel umMessage =
- new UpdateModel(engineServiceKey, baOutputStream.toString(), ignoreConflicts, force);
+ final UpdateModel umMessage = new UpdateModel(engineServiceKey, baOutputStream.toString(), ignoreConflicts,
+ force);
LOGGER.debug("sending update message {} to server {}:{} . . .", umMessage, hostName, port);
client.sendMessage(umMessage);
@@ -264,9 +286,8 @@ public class EngineServiceFacade {
// Check if we got a response
final Response response = getResponse(umMessage);
if (!response.isSuccessful()) {
- LOGGER.warn(FAILED_RESPONSE + "{} received from server {}:{}", response.getMessageData(), hostName, port);
throw new ApexException(
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port);
+ FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port);
}
}
@@ -285,9 +306,8 @@ public class EngineServiceFacade {
// Check if we got a response
final Response response = getResponse(startEngineMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexDeploymentException(message);
}
}
@@ -307,9 +327,8 @@ public class EngineServiceFacade {
// Check if we got a response
final Response response = getResponse(stopEngineMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexDeploymentException(message);
}
}
@@ -318,23 +337,22 @@ public class EngineServiceFacade {
* Start periodic events on an Apex engine on the engine service.
*
* @param engineKey the key of the engine to start periodic events on
- * @param period the period in milliseconds between periodic events
+ * @param period the period in milliseconds between periodic events
* @throws ApexDeploymentException on messaging errors
*/
public void startPerioidicEvents(final AxArtifactKey engineKey, final long period) throws ApexDeploymentException {
final StartPeriodicEvents startPerioidicEventsMessage = new StartPeriodicEvents(engineKey);
startPerioidicEventsMessage.setMessageData(Long.toString(period));
LOGGER.debug("sending start perioidic events {} to server {}:{} . . .", startPerioidicEventsMessage, hostName,
- port);
+ port);
client.sendMessage(startPerioidicEventsMessage);
LOGGER.debug("sent start perioidic events message to server {}:{} . . .", hostName, port);
// Check if we got a response
final Response response = getResponse(startPerioidicEventsMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexDeploymentException(message);
}
}
@@ -348,16 +366,15 @@ public class EngineServiceFacade {
public void stopPerioidicEvents(final AxArtifactKey engineKey) throws ApexDeploymentException {
final StopPeriodicEvents stopPerioidicEventsMessage = new StopPeriodicEvents(engineKey);
LOGGER.debug("sending stop perioidic events {} to server {}:{} . . .", stopPerioidicEventsMessage, hostName,
- port);
+ port);
client.sendMessage(stopPerioidicEventsMessage);
LOGGER.debug("sent stop perioidic events message to server {}:{} . . .", hostName, port);
// Check if we got a response
final Response response = getResponse(stopPerioidicEventsMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexDeploymentException(message);
}
}
@@ -378,9 +395,8 @@ public class EngineServiceFacade {
// Check if we got a response
final Response response = getResponse(engineStatusMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexException(message);
}
@@ -394,22 +410,22 @@ public class EngineServiceFacade {
* Get the runtime information of an Apex engine.
*
* @param engineKey the key of the engine to get information for
- * @return an engine model containing information on the engine for the given key
+ * @return an engine model containing information on the engine for the given
+ * key
* @throws ApexException the apex exception
*/
public String getEngineInfo(final AxArtifactKey engineKey) throws ApexException {
final GetEngineInfo engineInfoMessage = new GetEngineInfo(engineKey);
LOGGER.debug("sending get engine information message {} to server {}:{} . . .", engineInfoMessage, hostName,
- port);
+ port);
client.sendMessage(engineInfoMessage);
LOGGER.debug("sent get engine information message to server {}:{} . . .", hostName, port);
// Check if we got a response
final Response response = getResponse(engineInfoMessage);
if (!response.isSuccessful()) {
- final String message =
- FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':' + port;
- LOGGER.warn(message);
+ final String message = FAILED_RESPONSE + response.getMessageData() + RECEIVED_FROM_SERVER + hostName + ':'
+ + port;
throw new ApexException(message);
}
@@ -430,33 +446,30 @@ public class EngineServiceFacade {
timeoutTime = REPLY_MESSAGE_TIMEOUT_DEFAULT;
}
- // Wait for the required amount of milliseconds for the response from the Apex server
+ // Wait for the required amount of milliseconds for the response from the Apex
+ // server
Message receivedMessage = null;
- for (int timeWaitedSoFar = 0; receivedMessage == null && timeWaitedSoFar < timeoutTime; timeWaitedSoFar +=
- REPLY_MESSAGE_TIMEOUT_INCREMENT) {
+ for (int timeWaitedSoFar = 0; receivedMessage == null
+ && timeWaitedSoFar < timeoutTime; timeWaitedSoFar += REPLY_MESSAGE_TIMEOUT_INCREMENT) {
try {
receivedMessage = client.getReceiveQueue().poll(REPLY_MESSAGE_TIMEOUT_INCREMENT, TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
// restore the interrupt status
Thread.currentThread().interrupt();
- LOGGER.warn("reception of response from server interrupted {}:{}", hostName, port, e);
throw new ApexDeploymentException(
- "reception of response from server interrupted " + hostName + ':' + port, e);
+ "reception of response from server interrupted " + hostName + ':' + port, e);
}
}
// Check if response to sent message
if (receivedMessage == null) {
- LOGGER.warn("no response received to sent message " + sentMessage.getAction());
throw new ApexDeploymentException("no response received to sent message " + sentMessage.getAction());
}
// Check instance is a response message
if (!(receivedMessage instanceof Response)) {
- LOGGER.warn("response received from server is of incorrect type {}, should be of type {}",
- receivedMessage.getClass().getName(), Response.class.getName());
throw new ApexDeploymentException("response received from server is of incorrect type "
- + receivedMessage.getClass().getName() + ", should be of type " + Response.class.getName());
+ + receivedMessage.getClass().getName() + ", should be of type " + Response.class.getName());
}
// Cast the response message
@@ -464,18 +477,17 @@ public class EngineServiceFacade {
// Check if response to sent message
if (!responseMessage.getResponseTo().equals(sentMessage)) {
- LOGGER.warn("response received is not response to sent message " + sentMessage.getAction());
throw new ApexDeploymentException(
- "response received is not correct response to sent message " + sentMessage.getAction());
+ "response received is not correct response to sent message " + sentMessage.getAction());
}
// Check if successful
if (responseMessage.isSuccessful()) {
LOGGER.debug("response received: {} message was succssful: {}", sentMessage.getAction(),
- responseMessage.getMessageData());
+ responseMessage.getMessageData());
} else {
LOGGER.debug("response received: {} message failed: {}", sentMessage.getAction(),
- responseMessage.getMessageData());
+ responseMessage.getMessageData());
}
return responseMessage;
@@ -483,7 +495,7 @@ public class EngineServiceFacade {
/**
* Set a deployment client for this facade. This method is for testing.
- *
+ *
* @param deploymentClient the deployment client to set
*/
protected void setDeploymentClient(final DeploymentClient deploymentClient) {
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
index 5871204b5..000acab75 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/BatchDeployerTest.java
@@ -1,19 +1,20 @@
/*-
* ============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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -28,6 +29,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
+import java.time.Duration;
+import org.awaitility.Awaitility;
import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
@@ -41,8 +44,7 @@ public class BatchDeployerTest {
@Test
public void testBatchDeployerBad() {
try {
- final String[] eventArgs =
- { "-h" };
+ final String[] eventArgs = { "-h" };
BatchDeployer.main(eventArgs);
fail("test should throw an exception");
@@ -54,8 +56,7 @@ public class BatchDeployerTest {
@Test
public void testBatchDeployerBadPort() {
try {
- final String[] eventArgs =
- { "localhost", "aport", "afile" };
+ final String[] eventArgs = { "localhost", "aport", "afile" };
BatchDeployer.main(eventArgs);
fail("test should throw an exception");
@@ -67,88 +68,91 @@ public class BatchDeployerTest {
@Test
public void testBatchDeployerOk() {
try {
- final String[] eventArgs =
- { "Host", "43443", "src/test/resources/models/SamplePolicyModelJAVASCRIPT.json" };
+ final String[] eventArgs = { "Host", "43443",
+ "src/test/resources/models/SamplePolicyModelJAVASCRIPT.json" };
BatchDeployer.main(eventArgs);
+ fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("model deployment failed on parameters Host 43443", exc.getMessage());
}
}
-
+
@Test
- public void testBatchDeployerDeployString() {
+ public void testBatchDeployerDeployString() throws ApexException {
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
BatchDeployer deployer = new BatchDeployer("localhost", 12345, new PrintStream(baosOut, true));
- deployer.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
+ deployer.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
+ // We are testing towards a dummy client, make it return a failed initiation
+ dummyDeploymentClient.setInitSuccessful(false);
try {
deployer.init();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
+ assertEquals("model deployment failed on parameters localhost 12345", ade.getMessage());
}
- try {
- deployer.init();
- } catch (ApexDeploymentException ade) {
- ade.printStackTrace();
- fail("test should not throw an exception");
- }
+ // Wait until the connection to the server closes following the bad connection
+ // attempt
+ Awaitility.await().atLeast(Duration.ofMillis(100));
+
+ // We are testing towards a dummy client, make it return a successful initiation
+ dummyDeploymentClient.setInitSuccessful(true);
+ deployer.init();
try {
deployer.deployModel("src/test/resources/models/SmallModel.json", false, false);
+ fail("test should throw an exception");
} catch (ApexException ade) {
assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
- ade.getMessage());
+ ade.getMessage());
}
- try {
- deployer.deployModel("src/test/resources/models/SmallModel.json", false, false);
- } catch (ApexException ade) {
- fail("test should not throw an exception");
- }
+ deployer.deployModel("src/test/resources/models/SmallModel.json", false, false);
deployer.close();
}
@Test
- public void testBatchDeployerStream() throws ApexModelException, FileNotFoundException {
+ public void testBatchDeployerStream() throws FileNotFoundException, ApexException {
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
BatchDeployer deployer = new BatchDeployer("localhost", 12345, new PrintStream(baosOut, true));
- deployer.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
+ deployer.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
+ dummyDeploymentClient.setInitSuccessful(false);
try {
deployer.init();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
+ assertEquals("model deployment failed on parameters localhost 12345", ade.getMessage());
}
- try {
- deployer.init();
- } catch (ApexDeploymentException ade) {
- ade.printStackTrace();
- fail("test should not throw an exception");
- }
+ // Wait until the connection to the server closes following the bad connection
+ // attempt
+ Awaitility.await().atLeast(Duration.ofMillis(100));
+
+ dummyDeploymentClient.setInitSuccessful(true);
+ deployer.init();
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
modelReader.setValidateFlag(false);
- final AxPolicyModel apexPolicyModel = modelReader.read(
- new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
+ final AxPolicyModel apexPolicyModel = modelReader
+ .read(new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
try {
deployer.deployModel(apexPolicyModel, false, false);
+ fail("test should throw an exception");
} catch (ApexException ade) {
assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
}
- try {
- deployer.deployModel(apexPolicyModel, false, false);
- } catch (ApexException ade) {
- fail("test should not throw an exception");
- }
+ deployer.deployModel(apexPolicyModel, false, false);
deployer.close();
}
@@ -164,14 +168,14 @@ public class BatchDeployerTest {
deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
fail("test should throw an exception");
} catch (ApexException ade) {
- assertEquals("cound not deploy apex model, deployer is not initialized", ade.getMessage());
+ assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
}
try {
deployer.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
fail("test should throw an exception");
} catch (ApexException ade) {
- assertEquals("cound not deploy apex model, deployer is not initialized", ade.getMessage());
+ assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
}
deployer.close();
@@ -186,8 +190,8 @@ public class BatchDeployerTest {
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
modelReader.setValidateFlag(false);
- final AxPolicyModel apexPolicyModel = modelReader.read(
- new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
+ final AxPolicyModel apexPolicyModel = modelReader
+ .read(new FileInputStream(new File("src/test/resources/models/SmallModel.json")));
try {
deployer.deployModel(apexPolicyModel, false, false);
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
index 4432a38a6..ffb3d2c63 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/DummyDeploymentClient.java
@@ -29,6 +29,8 @@ import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
+import lombok.Getter;
+import lombok.Setter;
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;
@@ -46,6 +48,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Dummy deployment client.
*/
+@Getter
+@Setter
public class DummyDeploymentClient extends DeploymentClient implements Runnable {
private static final AxArtifactKey MODEL_KEY = new AxArtifactKey("Model", "0.0.1");
private static final AxArtifactKey ENGINE_KEY = new AxArtifactKey("Engine", "0.0.1");
@@ -130,14 +134,12 @@ public class DummyDeploymentClient extends DeploymentClient implements Runnable
infoResponse.setEngineServiceKey(ENGINE_SERVICE_KEY);
receiveQueue.add(infoResponse);
-
- initSuccessful = !initSuccessful;
}
/**
* Handle and return the response to the engine status message.
*
- * @param message the incoming status message
+ * @param message the incoming status message
* @param successFlag true if the result should be successful
* @return engine status success or not
*/
@@ -203,17 +205,8 @@ public class DummyDeploymentClient extends DeploymentClient implements Runnable
}
/**
- * Checks if the client thread is started.
- *
- * @return true, if the client thread is started
- */
- @Override
- public boolean isStarted() {
- return started;
- }
-
- /**
- * Allows users of this class to get a reference to the receive queue to receove messages.
+ * Allows users of this class to get a reference to the receive queue to receove
+ * messages.
*
* @return the receive queue
*/
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
index 6d2015562..fb2ef4459 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/EngineServiceFacadeTest.java
@@ -1,19 +1,20 @@
/*-
* ============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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -37,10 +38,17 @@ public class EngineServiceFacadeTest {
public void testEngineServiceFacade() throws Exception {
EngineServiceFacade facade = new EngineServiceFacade("localhost", 51273);
- facade.setDeploymentClient(new DummyDeploymentClient("localhost", 51273));
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
+ facade.setDeploymentClient(dummyDeploymentClient);
- // First init should fail
- facade.init();
+ // First init should fail due to our dummy client
+ dummyDeploymentClient.setInitSuccessful(false);
+ try {
+ facade.init();
+ fail("could not handshake with server localhost:51273");
+ } catch (final Exception ade) {
+ assertEquals("could not handshake with server localhost:51273", ade.getMessage());
+ }
assertNull(facade.getKey());
assertNull(facade.getApexModelKey());
@@ -50,10 +58,11 @@ public class EngineServiceFacadeTest {
facade.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
fail("test should throw an exception here");
} catch (final Exception ade) {
- assertEquals("cound not deploy apex model, deployer is not initialized", ade.getMessage());
+ assertEquals("could not deploy apex model, deployer is not initialized", ade.getMessage());
}
// Second init should work
+ dummyDeploymentClient.setInitSuccessful(true);
facade.init();
assertEquals("EngineService:0.0.1", facade.getKey().getId());
@@ -64,8 +73,8 @@ public class EngineServiceFacadeTest {
facade.deployModel("src/test/resources/models/NonExistantModel.json", false, false);
fail("test should throw an exception here");
} catch (final Exception ade) {
- assertEquals("cound not create apex model, could not read from file "
- + "src/test/resources/models/NonExistantModel.json", ade.getMessage());
+ assertEquals("could not create apex model, could not read from file "
+ + "src/test/resources/models/NonExistantModel.json", ade.getMessage());
}
try {
@@ -97,14 +106,10 @@ public class EngineServiceFacadeTest {
fail("test should throw an exception here");
} catch (final Exception ade) {
assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
- ade.getMessage());
+ ade.getMessage());
}
- try {
- facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
try {
facade.startEngine(facade.getEngineKeyArray()[0]);
@@ -113,11 +118,7 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.startEngine(facade.getEngineKeyArray()[0]);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.startEngine(facade.getEngineKeyArray()[0]);
try {
facade.stopEngine(facade.getEngineKeyArray()[0]);
@@ -126,11 +127,7 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.stopEngine(facade.getEngineKeyArray()[0]);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.stopEngine(facade.getEngineKeyArray()[0]);
try {
facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
@@ -139,11 +136,7 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
try {
facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
@@ -152,11 +145,7 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
try {
facade.getEngineStatus(facade.getEngineKeyArray()[0]);
@@ -165,11 +154,7 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.getEngineStatus(facade.getEngineKeyArray()[0]);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.getEngineStatus(facade.getEngineKeyArray()[0]);
try {
facade.getEngineInfo(facade.getEngineKeyArray()[0]);
@@ -178,19 +163,15 @@ public class EngineServiceFacadeTest {
assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
}
- try {
- facade.getEngineInfo(facade.getEngineKeyArray()[0]);
- } catch (final Exception ade) {
- fail("test should not throw an exception here");
- }
+ facade.getEngineInfo(facade.getEngineKeyArray()[0]);
try {
facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1"));
fail("test should throw an exception here");
} catch (final Exception ade) {
assertEquals("response received from server is of incorrect type "
- + "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
- + "org.onap.policy.apex.core.protocols.engdep.messages.Response", ade.getMessage());
+ + "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
+ + "org.onap.policy.apex.core.protocols.engdep.messages.Response", ade.getMessage());
}
try {
@@ -198,7 +179,7 @@ public class EngineServiceFacadeTest {
fail("test should throw an exception here");
} catch (final Exception ade) {
assertEquals("response received is not correct response to sent message GET_ENGINE_STATUS",
- ade.getMessage());
+ ade.getMessage());
}
try {
diff --git a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
index 22344cfc4..3444eb7fd 100644
--- a/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.java
+++ b/core/core-deployment/src/test/java/org/onap/policy/apex/core/deployment/PeriodicEventManagerTest.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.
@@ -38,8 +38,7 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerBad() {
try {
- final String[] eventArgs =
- { "-h" };
+ final String[] eventArgs = { "-h" };
PeriodicEventManager.main(eventArgs);
fail("test should throw an exception");
@@ -51,8 +50,7 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerOk() {
try {
- final String[] eventArgs =
- { "Host", "43443", "start", "1000" };
+ final String[] eventArgs = { "Host", "43443", "start", "1000" };
PeriodicEventManager.main(eventArgs);
fail("test should throw an exception");
@@ -63,30 +61,27 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerNoOptions() {
- final String[] eventArgs = new String[]
- {};
+ final String[] eventArgs = new String[] {};
final String outputString = testPeriodicEventManagerConstructor(eventArgs);
- assertTrue(outputString.contains(
- "usage: PeriodicEventManager <server address> <port address> <start/stop> <periods in ms>"));
+ assertTrue(outputString
+ .contains("usage: PeriodicEventManager <server address> <port address> <start/stop> <periods in ms>"));
}
@Test
public void testPeroidicEventManagerBadOptions() {
- final String[] eventArgs =
- { "-zabbu" };
+ final String[] eventArgs = { "-zabbu" };
final String outputString = testPeriodicEventManagerConstructor(eventArgs);
- assertTrue(outputString.contains(
- "usage: PeriodicEventManager <server address> <port address> <start/stop> <periods in ms>"));
+ assertTrue(outputString
+ .contains("usage: PeriodicEventManager <server address> <port address> <start/stop> <periods in ms>"));
}
@Test
public void testPeroidicEventManagerNonNumeric3() {
- final String[] eventArgs =
- { "aaa", "bbb", "ccc", "ddd" };
+ final String[] eventArgs = { "aaa", "bbb", "ccc", "ddd" };
final String outputString = testPeriodicEventManagerConstructor(eventArgs);
@@ -95,8 +90,7 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerNonNumeric2() {
- final String[] eventArgs =
- { "aaa", "12345", "start", "stop" };
+ final String[] eventArgs = { "aaa", "12345", "start", "stop" };
final String outputString = testPeriodicEventManagerConstructor(eventArgs);
@@ -105,8 +99,7 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerNotStartStop() {
- final String[] eventArgs =
- { "aaa", "12345", "1000", "1000" };
+ final String[] eventArgs = { "aaa", "12345", "1000", "1000" };
final String outputString = testPeriodicEventManagerConstructor(eventArgs);
@@ -115,25 +108,28 @@ public class PeriodicEventManagerTest {
@Test
public void testPeroidicEventManagerStart() {
- final String[] eventArgs =
- { "localhost", "12345", "start", "1000" };
+ final String[] eventArgs = { "localhost", "12345", "start", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
PeriodicEventManager peManager = null;
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
try {
peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
- peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
+ peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
} catch (ApexDeploymentException ade) {
fail("test should not throw an exception");
}
+ dummyDeploymentClient.setInitSuccessful(false);
try {
peManager.init();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
+ assertEquals("periodic event setting failed on parameters localhost 12345 true", ade.getMessage());
}
+ dummyDeploymentClient.setInitSuccessful(true);
try {
peManager.init();
} catch (ApexDeploymentException ade) {
@@ -143,6 +139,7 @@ public class PeriodicEventManagerTest {
try {
peManager.runCommand();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
}
@@ -157,63 +154,51 @@ public class PeriodicEventManagerTest {
}
@Test
- public void testPeroidicEventManagerStop() {
- final String[] eventArgs =
- { "localhost", "12345", "stop", "1000" };
+ public void testPeroidicEventManagerStop() throws ApexDeploymentException {
+ final String[] eventArgs = { "localhost", "12345", "stop", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
PeriodicEventManager peManager = null;
- try {
- peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
- peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
+ peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
+ peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
+ dummyDeploymentClient.setInitSuccessful(false);
try {
peManager.init();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
- assertEquals("model deployment failed on parameters localhost 12345 true", ade.getMessage());
+ assertEquals("periodic event setting failed on parameters localhost 12345 false", ade.getMessage());
}
- try {
- peManager.init();
- } catch (ApexDeploymentException ade) {
- ade.printStackTrace();
- fail("test should not throw an exception");
- }
+ dummyDeploymentClient.setInitSuccessful(true);
+ peManager.init();
try {
peManager.runCommand();
+ fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
assertEquals("failed response Operation failed received from serverlocalhost:12345", ade.getMessage());
}
- try {
- peManager.runCommand();
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ peManager.runCommand();
peManager.close();
}
@Test
- public void testPeroidicEventManagerStartUninitialized() {
- final String[] eventArgs =
- { "localhost", "12345", "start", "1000" };
+ public void testPeroidicEventManagerStartUninitialized() throws ApexDeploymentException {
+ final String[] eventArgs = { "localhost", "12345", "start", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
PeriodicEventManager peManager = null;
- try {
- peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
- peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ final DummyDeploymentClient dummyDeploymentClient = new DummyDeploymentClient("aHost", 54553);
+ peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
+ peManager.getEngineServiceFacade().setDeploymentClient(dummyDeploymentClient);
+ dummyDeploymentClient.setInitSuccessful(false);
try {
peManager.runCommand();
fail("test should throw an exception");
@@ -221,31 +206,26 @@ public class PeriodicEventManagerTest {
assertEquals("connection to apex is not initialized", ade.getMessage());
}
+ dummyDeploymentClient.setInitSuccessful(true);
try {
peManager.runCommand();
fail("test should throw an exception");
} catch (ApexDeploymentException ade) {
assertEquals("connection to apex is not initialized", ade.getMessage());
- ade.printStackTrace();
}
peManager.close();
}
@Test
- public void testPeroidicEventManagerStopUninitialized() {
- final String[] eventArgs =
- { "localhost", "12345", "stop", "1000" };
+ public void testPeroidicEventManagerStopUninitialized() throws ApexDeploymentException {
+ final String[] eventArgs = { "localhost", "12345", "stop", "1000" };
final ByteArrayOutputStream baosOut = new ByteArrayOutputStream();
PeriodicEventManager peManager = null;
- try {
- peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
- peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
- } catch (ApexDeploymentException ade) {
- fail("test should not throw an exception");
- }
+ peManager = new PeriodicEventManager(eventArgs, new PrintStream(baosOut, true));
+ peManager.getEngineServiceFacade().setDeploymentClient(new DummyDeploymentClient("aHost", 54553));
try {
peManager.runCommand();
@@ -282,6 +262,6 @@ public class PeriodicEventManagerTest {
String errString = baosErr.toString();
return "*** StdOut ***\n" + outString + "\n*** StdErr ***\n" + errString + "\n*** exception ***\n"
- + exceptionString;
+ + exceptionString;
}
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
index 182ce3597..edfbcf20f 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
@@ -130,12 +130,6 @@ public class TaskSelectExecutorTest {
try {
executor.executePre(0, new Properties(), incomingEvent);
- } catch (Exception ex) {
- assertEquals("task input fields \"[InField0]\" are missing for task \"Task0:0.0.1\"", ex.getMessage());
- }
-
- try {
- executor.executePre(0, new Properties(), incomingEvent);
} catch (Exception e) {
fail("test should not throw an exception");
}