diff options
Diffstat (limited to 'feature-pooling-dmaap/src')
55 files changed, 430 insertions, 259 deletions
diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java index 278e7fdc..27b81504 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/DmaapManager.java @@ -259,6 +259,8 @@ public class DmaapManager { public static class Factory { /** + * Get topic source. + * * @return the topic sources */ public List<TopicSource> getTopicSources() { @@ -266,6 +268,8 @@ public class DmaapManager { } /** + * Get topic sinks. + * * @return the topic sinks */ public List<TopicSink> getTopicSinks() { diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java index ad6a1c56..d45bded7 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingFeature.java @@ -46,7 +46,9 @@ import org.slf4j.LoggerFactory; /** * Controller/session pooling. Multiple hosts may be launched, all servicing the same * controllers/sessions. When this feature is enabled, the requests are divided across the different - * hosts, instead of all running on a single, active host. <p> With each controller, there is an + * hosts, instead of all running on a single, active host. + * + * <p>With each controller, there is an * associated DMaaP topic that is used for internal communication between the different hosts * serving the controller. */ @@ -87,7 +89,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF private ThreadLocal<OfferArgs> offerArgs = new ThreadLocal<>(); /** - * + * Constructor. */ public PoolingFeature() { super(); @@ -113,6 +115,8 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF } /** + * Get active latch. + * * @return a latch that will be decremented when a manager enters the active state */ protected CountDownLatch getActiveLatch() { @@ -126,7 +130,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF @Override public boolean beforeStart(PolicyEngine engine) { - logger.info("initializing " + PoolingProperties.FEATURE_NAME); + logger.info("initializing {}", PoolingProperties.FEATURE_NAME); featProps = factory.getProperties(PoolingProperties.FEATURE_NAME); // remove any generic pooling topic - always use controller-specific property @@ -138,6 +142,14 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF return false; } + @Override + public boolean beforeStart(PolicyController controller) { + return doManager(controller, mgr -> { + mgr.beforeStart(); + return false; + }); + } + /** * Adds the controller and a new pooling manager to {@link #ctlr2pool}. * @@ -177,14 +189,6 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF } @Override - public boolean beforeStart(PolicyController controller) { - return doManager(controller, mgr -> { - mgr.beforeStart(); - return false; - }); - } - - @Override public boolean afterStart(PolicyController controller) { return doManager(controller, mgr -> { mgr.afterStart(); @@ -307,7 +311,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF * Executes a function using the manager associated with the controller. Catches any exceptions * from the function and re-throws it as a runtime exception. * - * @param controller + * @param controller controller * @param func function to be executed * @return {@code true} if the function handled the request, {@code false} otherwise * @throws PoolingFeatureRtException if an error occurs @@ -329,7 +333,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF /** * Deletes the manager associated with a controller. * - * @param controller + * @param controller controller * @throws PoolingFeatureRtException if an error occurs */ private void deleteManager(PolicyController controller) { @@ -347,10 +351,11 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF private static interface MgrFunc { /** + * Apply. * - * @param mgr + * @param mgr manager * @return {@code true} if the request was handled by the manager, {@code false} otherwise - * @throws PoolingFeatureException + * @throws PoolingFeatureException feature exception */ public boolean apply(PoolingManagerImpl mgr) throws PoolingFeatureException; } @@ -376,9 +381,10 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF private String event; /** + * Constructor. * - * @param protocol - * @param topic + * @param protocol protocol + * @param topic topic * @param event the actual event data received on the topic */ public OfferArgs(CommInfrastructure protocol, String topic, String event) { @@ -394,6 +400,8 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF public static class Factory { /** + * Get properties. + * * @param featName feature name * @return the properties for the specified feature */ @@ -405,7 +413,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF * Makes a pooling manager for a controller. * * @param host name/uuid of this host - * @param controller + * @param controller controller * @param props properties to use to configure the manager * @param activeLatch decremented when the manager goes Active * @return a new pooling manager @@ -418,7 +426,7 @@ public class PoolingFeature implements PolicyEngineFeatureAPI, PolicyControllerF /** * Gets the policy controller associated with a drools controller. * - * @param droolsController + * @param droolsController drools controller * @return the policy controller associated with a drools controller */ public PolicyController getController(DroolsController droolsController) { diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManager.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManager.java index c25dc12d..94956d6b 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManager.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManager.java @@ -86,7 +86,7 @@ public interface PoolingManager { /** * Handles a {@link Forward} event that was received from the internal topic. * - * @param event + * @param event event */ public void handle(Forward event); @@ -94,7 +94,7 @@ public interface PoolingManager { * Schedules a timer to fire after a delay. * * @param delayMs delay, in milliseconds - * @param task + * @param task task * @return a new scheduled task */ public CancellableScheduledTask schedule(long delayMs, StateTimerTask task); @@ -104,7 +104,7 @@ public interface PoolingManager { * * @param initialDelayMs initial delay, in milliseconds * @param delayMs delay, in milliseconds - * @param task + * @param task task * @return a new scheduled task */ public CancellableScheduledTask scheduleWithFixedDelay(long initialDelayMs, long delayMs, StateTimerTask task); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java index 02ba4ec9..17d520ad 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java @@ -20,6 +20,7 @@ package org.onap.policy.drools.pooling; +import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -29,10 +30,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.onap.policy.common.utils.properties.SpecProperties; -import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.common.utils.properties.SpecProperties; +import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.pooling.extractor.ClassExtractors; import org.onap.policy.drools.pooling.message.BucketAssignments; import org.onap.policy.drools.pooling.message.Forward; @@ -50,7 +51,6 @@ import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.system.PolicyController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.JsonProcessingException; /** * Implementation of a {@link PoolingManager}. Until bucket assignments have been made, @@ -126,8 +126,8 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Current state. - * <p> - * This uses a finite state machine, wherein the state object contains all of the data + * + * <p>This uses a finite state machine, wherein the state object contains all of the data * relevant to that state. Each state object has a process() method, specific to each * type of {@link Message} subclass. The method returns the next state object, or * {@code null} if the state is to remain the same. @@ -417,10 +417,9 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Handles an event from the internal topic. * - * @param topic2 - * @param event - * @return {@code true} if the event was handled, {@code false} if the controller - * should handle it + * @param commType comm infrastructure + * @param topic2 topic + * @param event event */ @Override public void onTopicEvent(CommInfrastructure commType, String topic2, String event) { @@ -440,14 +439,14 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { * Called by the PolicyController before it offers the event to the DroolsController. * If the controller is locked, then it isn't processing events. However, they still * need to be forwarded, thus in that case, they are decoded and forwarded. - * <p> - * On the other hand, if the controller is not locked, then we just return immediately + * + * <p>On the other hand, if the controller is not locked, then we just return immediately * and let {@link #beforeInsert(Object, String, String, Object) beforeInsert()} handle * it instead, as it already has the decoded message. * - * @param protocol - * @param topic2 - * @param event + * @param protocol protocol + * @param topic2 topic + * @param event event * @return {@code true} if the event was handled by the manager, {@code false} if it * must still be handled by the invoker */ @@ -464,8 +463,8 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Called by the DroolsController before it inserts the event into the rule engine. * - * @param protocol - * @param topic2 + * @param protocol protocol + * @param topic2 topic * @param event original event text, as received from the Bus * @param event2 event, as an object * @return {@code true} if the event was handled by the manager, {@code false} if it @@ -484,9 +483,9 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Handles an event from an external topic. * - * @param protocol - * @param topic2 - * @param event + * @param protocol protocol + * @param topic2 topic + * @param event event * @param reqid request id extracted from the event, or {@code null} if it couldn't be * extracted * @return {@code true} if the event was handled by the manager, {@code false} if it @@ -519,7 +518,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Handles an event from an external topic. * - * @param event + * @param event event * @return {@code true} if the event was handled, {@code false} if the invoker should * handle it */ @@ -539,7 +538,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Handles a {@link Forward} event, possibly forwarding it again. * - * @param event + * @param event event * @return {@code true} if the event was handled, {@code false} if the invoker should * handle it */ @@ -595,8 +594,8 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Decodes an event from a String into an event Object. * - * @param topic2 - * @param event + * @param topic2 topic + * @param event event * @return the decoded event object, or {@code null} if it can't be decoded */ private Object decodeEvent(String topic2, String event) { @@ -625,10 +624,10 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Makes a {@link Forward}, and validates its contents. * - * @param protocol - * @param topic2 - * @param event - * @param reqid + * @param protocol protocol + * @param topic2 topic + * @param event event + * @param reqid request id * @return a new message, or {@code null} if the message was invalid */ private Forward makeForward(CommInfrastructure protocol, String topic2, String event, String reqid) { @@ -661,7 +660,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { /** * Injects an event into the controller. * - * @param event + * @param event event */ private void inject(Forward event) { logger.info("inject event for request {} from topic {}", event.getRequestId(), event.getTopic()); @@ -760,6 +759,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { private StateTimerTask task; /** + * Constructor. * * @param task task to execute when this timer runs */ @@ -832,9 +832,9 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener { * @param topic topic on which the event was received * @param event event text to be decoded * @return the decoded event - * @throws IllegalArgumentException - * @throw UnsupportedOperationException - * @throws IllegalStateException + * @throws IllegalArgumentException illegal argument + * @throw UnsupportedOperationException unsupported operation + * @throws IllegalStateException illegal state */ public Object decodeEvent(DroolsController drools, String topic, String event) { return EventProtocolCoder.manager.decode(drools.getGroupId(), drools.getArtifactId(), topic, event); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingProperties.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingProperties.java index 1482366f..795bd29d 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingProperties.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingProperties.java @@ -129,6 +129,8 @@ public class PoolingProperties extends PropertyConfiguration { private long interHeartbeatMs; /** + * Constructor. + * * @param controllerName the name of the controller * @param props set of properties used to configure this * @throws PropertyException if an error occurs diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/Serializer.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/Serializer.java index 63aefb7a..b37c33b0 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/Serializer.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/Serializer.java @@ -20,11 +20,11 @@ package org.onap.policy.drools.pooling; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Map; import org.onap.policy.drools.pooling.message.Message; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; /** * Serialization helper functions. @@ -38,7 +38,7 @@ public class Serializer { private final ObjectMapper mapper = new ObjectMapper(); /** - * + * Constructor. */ public Serializer() { super(); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/ClassExtractors.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/ClassExtractors.java index 97e96337..a4d1fb1b 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/ClassExtractors.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/ClassExtractors.java @@ -70,6 +70,7 @@ public class ClassExtractors { private final ConcurrentHashMap<String, Extractor> class2extractor = new ConcurrentHashMap<>(); /** + * Constructor. * * @param props properties that specify how the data is to be extracted from * a given class @@ -267,8 +268,8 @@ public class ClassExtractors { * hierarchically, where each name identifies a particular component within * the hierarchy. Supports retrieval from {@link Map} objects, as well as * via getXxx() methods, or by direct field retrieval. - * <p> - * Note: this will <i>not</i> work if POJOs are contained within a Map. + * + * <p>Note: this will <i>not</i> work if POJOs are contained within a Map. */ private class ComponetizedExtractor implements Extractor { @@ -278,11 +279,12 @@ public class ClassExtractors { private final Extractor[] extractors; /** + * Constructor. * * @param clazz the class associated with the object at the root of the * hierarchy * @param names name associated with each component - * @throws ExtractorException + * @throws ExtractorException extractor exception */ public ComponetizedExtractor(Class<?> clazz, String[] names) throws ExtractorException { this.extractors = new Extractor[names.length]; @@ -307,15 +309,12 @@ public class ClassExtractors { * @param comp name of the component to extract * @return a pair containing the extractor and the extracted object's * type - * @throws ExtractorException + * @throws ExtractorException extrator exception */ private Pair<Extractor, Class<?>> buildExtractor(Class<?> clazz, String comp) throws ExtractorException { - Pair<Extractor, Class<?>> pair = null; - - if (pair == null) { - pair = getMethodExtractor(clazz, comp); - } - + + Pair<Extractor, Class<?>> pair = getMethodExtractor(clazz, comp); + if (pair == null) { pair = getFieldExtractor(clazz, comp); } diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/FieldExtractor.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/FieldExtractor.java index d394795d..9389ab22 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/FieldExtractor.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/FieldExtractor.java @@ -37,6 +37,7 @@ public class FieldExtractor implements Extractor { private final Field field; /** + * Constructor. * * @param field field containing the object */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MapExtractor.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MapExtractor.java index 032ea47e..9c5be5ff 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MapExtractor.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MapExtractor.java @@ -37,6 +37,7 @@ public class MapExtractor implements Extractor { private final String key; /** + * Constructor. * * @param key key to the item to extract from the map */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MethodExtractor.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MethodExtractor.java index 20c4a1a7..3efef5ec 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MethodExtractor.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/extractor/MethodExtractor.java @@ -38,6 +38,7 @@ public class MethodExtractor implements Extractor { private final Method method; /** + * Constructor. * * @param method method to invoke to extract the contained object */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/BucketAssignments.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/BucketAssignments.java index ee871cbd..b5b64693 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/BucketAssignments.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/BucketAssignments.java @@ -20,13 +20,13 @@ package org.onap.policy.drools.pooling.message; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import org.onap.policy.drools.pooling.PoolingFeatureException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.annotation.JsonIgnore; /** * Bucket assignments, which is simply an array of host names. @@ -57,13 +57,14 @@ public class BucketAssignments { private String[] hostArray = null; /** - * + * Constructor. */ public BucketAssignments() { super(); } /** + * Constructor. * * @param hostArray maps a bucket number (i.e., array index) to a host. All values * must be non-null @@ -204,12 +205,15 @@ public class BucketAssignments { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } BucketAssignments other = (BucketAssignments) obj; return Arrays.equals(hostArray, other.hostArray); } diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Forward.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Forward.java index fb3d4eb2..d4037e90 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Forward.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Forward.java @@ -20,9 +20,9 @@ package org.onap.policy.drools.pooling.message; +import com.fasterxml.jackson.annotation.JsonIgnore; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.drools.pooling.PoolingFeatureException; -import com.fasterxml.jackson.annotation.JsonIgnore; /** * Message to forward an event to another host. @@ -67,12 +67,13 @@ public class Forward extends Message { } /** + * Constructor. * * @param source host on which the message originated - * @param protocol - * @param topic + * @param protocol protocol + * @param topic topic * @param payload the actual event data received on the topic - * @param requestId + * @param requestId request id */ public Forward(String source, CommInfrastructure protocol, String topic, String payload, String requestId) { super(source); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Heartbeat.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Heartbeat.java index 2a63a5be..50a34138 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Heartbeat.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Heartbeat.java @@ -31,7 +31,7 @@ public class Heartbeat extends Message { private long timestampMs; /** - * + * Constructor. */ public Heartbeat() { super(); @@ -39,6 +39,7 @@ public class Heartbeat extends Message { } /** + * Constructor. * * @param source host on which the message originated * @param timestampMs time, in milliseconds, associated with the message diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Identification.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Identification.java index 5de6b8f9..6bb88363 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Identification.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Identification.java @@ -26,7 +26,7 @@ package org.onap.policy.drools.pooling.message; public class Identification extends MessageWithAssignments { /** - * + * Constructor. */ public Identification() { super(); @@ -34,9 +34,10 @@ public class Identification extends MessageWithAssignments { } /** + * Constructor. * * @param source host on which the message originated - * @param assignments + * @param assignments assignments */ public Identification(String source, BucketAssignments assignments) { super(source, assignments); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Leader.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Leader.java index 0fc48c3c..7464a531 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Leader.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Leader.java @@ -20,8 +20,8 @@ package org.onap.policy.drools.pooling.message; -import org.onap.policy.drools.pooling.PoolingFeatureException; import com.fasterxml.jackson.annotation.JsonIgnore; +import org.onap.policy.drools.pooling.PoolingFeatureException; /** * Indicates that the "source" of this message is now the "lead" host. @@ -29,16 +29,17 @@ import com.fasterxml.jackson.annotation.JsonIgnore; public class Leader extends MessageWithAssignments { /** - * + * Constructor. */ public Leader() { super(); } /** + * Constructor. * * @param source host on which the message originated - * @param assignments + * @param assignments assignments */ public Leader(String source, BucketAssignments assignments) { super(source, assignments); @@ -61,7 +62,7 @@ public class Leader extends MessageWithAssignments { String leader = getSource(); - if(!assignments.hasAssignment(leader)) { + if (!assignments.hasAssignment(leader)) { throw new PoolingFeatureException("leader " + leader + " has no bucket assignments"); } diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Message.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Message.java index e8a4671d..215cdaec 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Message.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Message.java @@ -20,11 +20,11 @@ package org.onap.policy.drools.pooling.message; -import org.onap.policy.drools.pooling.PoolingFeatureException; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.onap.policy.drools.pooling.PoolingFeatureException; /** * Messages sent on the internal topic. @@ -53,13 +53,14 @@ public class Message { private String channel; /** - * + * Constructor. */ public Message() { super(); } /** + * Constructor. * * @param source host on which the message originated */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/MessageWithAssignments.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/MessageWithAssignments.java index 9fded815..4a0b8658 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/MessageWithAssignments.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/MessageWithAssignments.java @@ -20,8 +20,8 @@ package org.onap.policy.drools.pooling.message; -import org.onap.policy.drools.pooling.PoolingFeatureException; import com.fasterxml.jackson.annotation.JsonIgnore; +import org.onap.policy.drools.pooling.PoolingFeatureException; /** * A Message that includes bucket assignments. @@ -34,16 +34,17 @@ public class MessageWithAssignments extends Message { private BucketAssignments assignments; /** - * + * Constructor. */ public MessageWithAssignments() { super(); } /** + * Constructor. * * @param source host on which the message originated - * @param assignments + * @param assignments assignements */ public MessageWithAssignments(String source, BucketAssignments assignments) { super(source); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Offline.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Offline.java index 297671ac..487c4f3e 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Offline.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Offline.java @@ -27,7 +27,7 @@ package org.onap.policy.drools.pooling.message; public class Offline extends Message { /** - * + * Constructor. */ public Offline() { super(); @@ -35,6 +35,7 @@ public class Offline extends Message { } /** + * Constructor. * * @param source host on which the message originated */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Query.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Query.java index c995a288..8c9898ee 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Query.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Query.java @@ -26,7 +26,7 @@ package org.onap.policy.drools.pooling.message; public class Query extends Message { /** - * + * Constructor. */ public Query() { super(); @@ -34,6 +34,7 @@ public class Query extends Message { } /** + * Constructor. * * @param source host on which the message originated */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ActiveState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ActiveState.java index 8f0a902a..58205ddd 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ActiveState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ActiveState.java @@ -66,8 +66,9 @@ public class ActiveState extends ProcessingState { private boolean predHeartbeatSeen = false; /** + * Constructor. * - * @param mgr + * @param mgr pooling manager */ public ActiveState(PoolingManager mgr) { super(mgr, mgr.getAssignments().getLeader()); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/FilterUtils.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/FilterUtils.java index a2da0ea2..069ca656 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/FilterUtils.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/FilterUtils.java @@ -44,7 +44,7 @@ public class FilterUtils { protected static final String CLASS_EQUALS = "Equals"; /** - * + * Constructor. */ private FilterUtils() { super(); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/InactiveState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/InactiveState.java index f717aa52..579dc16d 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/InactiveState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/InactiveState.java @@ -35,8 +35,9 @@ public class InactiveState extends State { private static final Logger logger = LoggerFactory.getLogger(InactiveState.class); /** + * Constructor. * - * @param mgr + * @param mgr pooling manager */ public InactiveState(PoolingManager mgr) { super(mgr); diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ProcessingState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ProcessingState.java index e9dc0324..7fed6a15 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ProcessingState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/ProcessingState.java @@ -48,8 +48,9 @@ public class ProcessingState extends State { private String leader; /** + * Constructor. * - * @param mgr + * @param mgr pooling manager * @param leader current known leader, which need not be the same as the assignment * leader. Never {@code null} * @throws IllegalArgumentException if an argument is invalid @@ -308,10 +309,10 @@ public class ProcessingState extends State { } // move the bucket from the larger to the smaller - Integer b = larger.remove(); - smaller.add(b); + Integer bucket = larger.remove(); + smaller.add(bucket); - bucket2host[b] = smaller.host; + bucket2host[bucket] = smaller.host; // put the items back, with their new counts assignments.add(larger); @@ -349,8 +350,9 @@ public class ProcessingState extends State { private Queue<Integer> buckets = new LinkedList<>(); /** + * Constructor. * - * @param host + * @param host host */ public HostBucket(String host) { this.host = host; @@ -375,6 +377,7 @@ public class ProcessingState extends State { } /** + * Size. * * @return the number of buckets assigned to this host */ @@ -388,11 +391,11 @@ public class ProcessingState extends State { */ @Override public final int compareTo(HostBucket other) { - int d = buckets.size() - other.buckets.size(); - if (d == 0) { - d = host.compareTo(other.host); + int diff = buckets.size() - other.buckets.size(); + if (diff == 0) { + diff = host.compareTo(other.host); } - return d; + return diff; } @Override diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java index 1a4da150..ea74f03a 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/QueryState.java @@ -51,8 +51,9 @@ public class QueryState extends ProcessingState { private boolean sawSelfIdent = false; /** + * Constructor. * - * @param mgr + * @param mgr manager */ public QueryState(PoolingManager mgr) { // this host is the leader, until a better candidate identifies itself diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/StartState.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/StartState.java index 3068cfc9..59d264ec 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/StartState.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/StartState.java @@ -25,6 +25,7 @@ import static org.onap.policy.drools.pooling.state.FilterUtils.MSG_TIMESTAMP; import static org.onap.policy.drools.pooling.state.FilterUtils.makeAnd; import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals; import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr; + import java.util.Map; import org.onap.policy.drools.pooling.PoolingManager; import org.onap.policy.drools.pooling.message.Heartbeat; @@ -47,14 +48,16 @@ public class StartState extends State { private long hbTimestampMs = System.currentTimeMillis(); /** + * Constructor. * - * @param mgr + * @param mgr pooling manager */ public StartState(PoolingManager mgr) { super(mgr); } /** + * Get Heart beat time stamp in milliseconds. * * @return the time stamp inserted into the heart beat message */ diff --git a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/State.java b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/State.java index a1be2a7c..edffb3fe 100644 --- a/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/State.java +++ b/feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/state/State.java @@ -23,6 +23,7 @@ package org.onap.policy.drools.pooling.state; import static org.onap.policy.drools.pooling.state.FilterUtils.MSG_CHANNEL; import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals; import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr; + import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -42,8 +43,8 @@ import org.slf4j.LoggerFactory; /** * A state in the finite state machine. - * <p> - * A state may have several timers associated with it, which must be cancelled whenever + * + * <p>A state may have several timers associated with it, which must be cancelled whenever * the state is changed. Assumes that timers are not continuously added to the same state. */ public abstract class State { @@ -61,8 +62,9 @@ public abstract class State { private final List<CancellableScheduledTask> timers = new LinkedList<>(); /** + * Constructor. * - * @param mgr + * @param mgr pooling manager */ public State(PoolingManager mgr) { this.mgr = mgr; @@ -197,6 +199,28 @@ public abstract class State { } /** + * Processes a message. The default method just returns {@code null}. + * + * @param msg message to be processed + * @return the new state, or {@code null} if the state is unchanged + */ + public State process(Offline msg) { + logger.info("ignored offline message from {} on topic {}", msg.getSource(), getTopic()); + return null; + } + + /** + * Processes a message. The default method just returns {@code null}. + * + * @param msg message to be processed + * @return the new state, or {@code null} if the state is unchanged + */ + public State process(Query msg) { + logger.info("ignored Query message from {} on topic {}", msg.getSource(), getTopic()); + return null; + } + + /** * Determines if a message is valid and did not originate from this host. * * @param msg message to be validated @@ -227,28 +251,6 @@ public abstract class State { } /** - * Processes a message. The default method just returns {@code null}. - * - * @param msg message to be processed - * @return the new state, or {@code null} if the state is unchanged - */ - public State process(Offline msg) { - logger.info("ignored offline message from {} on topic {}", msg.getSource(), getTopic()); - return null; - } - - /** - * Processes a message. The default method just returns {@code null}. - * - * @param msg message to be processed - * @return the new state, or {@code null} if the state is unchanged - */ - public State process(Query msg) { - logger.info("ignored Query message from {} on topic {}", msg.getSource(), getTopic()); - return null; - } - - /** * Publishes a message. * * @param msg message to be published @@ -287,7 +289,7 @@ public abstract class State { /** * Publishes a message on the specified channel. * - * @param channel + * @param channel channel * @param msg message to be published */ protected final void publish(String channel, Forward msg) { @@ -297,7 +299,7 @@ public abstract class State { /** * Publishes a message on the specified channel. * - * @param channel + * @param channel channel * @param msg message to be published */ protected final void publish(String channel, Heartbeat msg) { @@ -307,7 +309,7 @@ public abstract class State { /** * Starts distributing messages using the specified bucket assignments. * - * @param assignments + * @param assignments assignments */ protected final void startDistributing(BucketAssignments assignments) { if (assignments != null) { @@ -318,8 +320,8 @@ public abstract class State { /** * Schedules a timer to fire after a delay. * - * @param delayMs - * @param task + * @param delayMs delay in ms + * @param task task */ protected final void schedule(long delayMs, StateTimerTask task) { timers.add(mgr.schedule(delayMs, task)); @@ -328,9 +330,9 @@ public abstract class State { /** * Schedules a timer to fire repeatedly. * - * @param initialDelayMs - * @param delayMs - * @param task + * @param initialDelayMs initial delay ms + * @param delayMs delay ms + * @param task task */ protected final void scheduleWithFixedDelay(long initialDelayMs, long delayMs, StateTimerTask task) { timers.add(mgr.scheduleWithFixedDelay(initialDelayMs, delayMs, task)); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java index d48dea5b..e554a34a 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Arrays; import java.util.LinkedList; import java.util.concurrent.CountDownLatch; @@ -70,6 +71,11 @@ public class DmaapManagerTest { DmaapManager.setFactory(saveFactory); } + /** + * Setup. + * + * @throws Exception throws an exception + */ @Before public void setUp() throws Exception { listener = mock(TopicListener.class); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java index 3c3466be..709f1b06 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java @@ -27,6 +27,9 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.Arrays; import java.util.Deque; @@ -51,21 +54,19 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.common.endpoints.event.comm.FilterableTopicSource; import org.onap.policy.common.endpoints.event.comm.Topic; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicListener; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; +import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.pooling.message.Message; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.drools.system.PolicyEngine; import org.onap.policy.drools.utils.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; /** * End-to-end tests of the pooling feature. Launches one or more "hosts", each one having @@ -118,6 +119,10 @@ public class FeatureTest { */ private Context ctx; + /** + * Setup before class. + * + */ @BeforeClass public static void setUpBeforeClass() { saveFeatureFactory = PoolingFeature.getFactory(); @@ -127,6 +132,9 @@ public class FeatureTest { // note: invoke runSlow() to slow things down } + /** + * Tear down after class. + */ @AfterClass public static void tearDownAfterClass() { PoolingFeature.setFactory(saveFeatureFactory); @@ -134,11 +142,17 @@ public class FeatureTest { DmaapManager.setFactory(saveDmaapFactory); } + /** + * Setup. + */ @Before public void setUp() { ctx = null; } + /** + * Tear down. + */ @After public void tearDown() { if (ctx != null) { @@ -189,15 +203,15 @@ public class FeatureTest { * Invoke this to slow the timers down. */ protected static void runSlow() { - stdReactivateWaitMs = 10000; - stdIdentificationMs = 10000; - stdStartHeartbeatMs = 15000; - stdActiveHeartbeatMs = 12000; - stdInterHeartbeatMs = 5000; - stdOfflinePubWaitMs = 2; - stdPollMs = 2; - stdInterPollMs = 2000; - stdEventWaitSec = 1000; + stdReactivateWaitMs = 10000; + stdIdentificationMs = 10000; + stdStartHeartbeatMs = 15000; + stdActiveHeartbeatMs = 12000; + stdInterHeartbeatMs = 5000; + stdOfflinePubWaitMs = 2; + stdPollMs = 2; + stdInterPollMs = 2000; + stdEventWaitSec = 1000; } /** @@ -232,7 +246,7 @@ public class FeatureTest { /** * Counts the number of decode errors. */ - private final AtomicInteger nDecodeErrors = new AtomicInteger(0); + private final AtomicInteger numDecodeErrors = new AtomicInteger(0); /** * Number of events we're still waiting to receive. @@ -246,14 +260,15 @@ public class FeatureTest { private Host currentHost = null; /** + * Constructor. * * @param nEvents number of events to be processed */ - public Context(int nEvents) { + public Context(int events) { featureFactory = new FeatureFactory(this); managerFactory = new ManagerFactory(this); dmaapFactory = new DmaapFactory(this); - eventCounter = new CountDownLatch(nEvents); + eventCounter = new CountDownLatch(events); PoolingFeature.setFactory(featureFactory); PoolingManagerImpl.setFactory(managerFactory); @@ -298,10 +313,10 @@ public class FeatureTest { * Verifies that all hosts processed at least one message. */ public void checkAllSawAMsg() { - int x = 0; + int msgs = 0; for (Host host : hosts) { - assertTrue("x=" + x, host.messageSeen()); - ++x; + assertTrue("msgs=" + msgs, host.messageSeen()); + ++msgs; } } @@ -309,7 +324,7 @@ public class FeatureTest { * Sets {@link #currentHost} to the specified host, and then invokes the given * function. Resets {@link #currentHost} to {@code null} before returning. * - * @param host + * @param host host * @param func function to invoke */ public void withHost(Host host, VoidFunction func) { @@ -321,7 +336,7 @@ public class FeatureTest { /** * Offers an event to the external topic. * - * @param event + * @param event event */ public void offerExternal(String event) { externalTopic.offer(event); @@ -330,7 +345,7 @@ public class FeatureTest { /** * Adds an internal channel to the set of channels. * - * @param channel + * @param channel channel * @param queue the channel's queue */ public void addInternal(String channel, BlockingQueue<String> queue) { @@ -340,7 +355,7 @@ public class FeatureTest { /** * Offers a message to all internal channels. * - * @param message + * @param message message */ public void offerInternal(String message) { channel2queue.values().forEach(queue -> queue.offer(message)); @@ -349,8 +364,8 @@ public class FeatureTest { /** * Offers amessage to an internal channel. * - * @param channel - * @param message + * @param channel channel + * @param message message */ public void offerInternal(String channel, String message) { BlockingQueue<String> queue = channel2queue.get(channel); @@ -362,7 +377,7 @@ public class FeatureTest { /** * Decodes an event. * - * @param event + * @param event event * @return the decoded event, or {@code null} if it cannot be decoded */ public Object decodeEvent(String event) { @@ -372,15 +387,17 @@ public class FeatureTest { /** * Associates a controller with its drools controller. * - * @param controller - * @param droolsController + * @param controller controller + * @param droolsController drools controller */ public void addController(PolicyController controller, DroolsController droolsController) { drools2policy.put(droolsController, controller); } /** - * @param droolsController + * Get controller. + * + * @param droolsController drools controller * @return the controller associated with a drools controller, or {@code null} if * it has no associated controller */ @@ -389,6 +406,8 @@ public class FeatureTest { } /** + * Constructor. + * * @return queue for the external topic */ public BlockingQueue<String> getExternalTopic() { @@ -396,21 +415,23 @@ public class FeatureTest { } /** + * Get decode errors. * * @return the number of decode errors so far */ public int getDecodeErrors() { - return nDecodeErrors.get(); + return numDecodeErrors.get(); } /** * Increments the count of decode errors. */ public void bumpDecodeErrors() { - nDecodeErrors.incrementAndGet(); + numDecodeErrors.incrementAndGet(); } /** + * Get remaining events. * * @return the number of events that haven't been processed */ @@ -428,10 +449,10 @@ public class FeatureTest { /** * Waits, for a period of time, for all events to be processed. * - * @param time - * @param units + * @param time time + * @param units units * @return {@code true} if all events have been processed, {@code false} otherwise - * @throws InterruptedException + * @throws InterruptedException throws interrupted */ public boolean awaitEvents(long time, TimeUnit units) throws InterruptedException { return eventCounter.await(time, units); @@ -478,8 +499,9 @@ public class FeatureTest { private final DroolsController drools = mock(DroolsController.class); /** + * Constructor. * - * @param context + * @param context context */ public Host(Context context) { this.context = context; @@ -502,6 +524,8 @@ public class FeatureTest { } /** + * Get name. + * * @return the host name */ public String getName() { @@ -543,9 +567,9 @@ public class FeatureTest { /** * Offers an event to the feature, before the policy controller handles it. * - * @param protocol - * @param topic2 - * @param event + * @param protocol protocol + * @param topic2 topic + * @param event event * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean beforeOffer(CommInfrastructure protocol, String topic2, String event) { @@ -555,10 +579,10 @@ public class FeatureTest { /** * Offers an event to the feature, after the policy controller handles it. * - * @param protocol - * @param topic - * @param event - * @param success + * @param protocol protocol + * @param topic topic + * @param event event + * @param success success * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean afterOffer(CommInfrastructure protocol, String topic, String event, boolean success) { @@ -569,7 +593,7 @@ public class FeatureTest { /** * Offers an event to the feature, before the drools controller handles it. * - * @param fact + * @param fact fact * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean beforeInsert(Object fact) { @@ -579,7 +603,7 @@ public class FeatureTest { /** * Offers an event to the feature, after the drools controller handles it. * - * @param fact + * @param fact fact * @param successInsert {@code true} if it was successfully inserted by the drools * controller, {@code false} otherwise * @return {@code true} if the event was handled, {@code false} otherwise @@ -596,6 +620,7 @@ public class FeatureTest { } /** + * Message seen. * * @return {@code true} if a message was seen for this host, {@code false} * otherwise @@ -605,6 +630,8 @@ public class FeatureTest { } /** + * Get internal queue. + * * @return the queue associated with this host's internal topic */ public BlockingQueue<String> getInternalQueue() { @@ -628,10 +655,10 @@ public class FeatureTest { @Override public Void answer(InvocationOnMock args) throws Throwable { - int i = 0; - CommInfrastructure commType = args.getArgument(i++); - String topic = args.getArgument(i++); - String event = args.getArgument(i++); + int index = 0; + CommInfrastructure commType = args.getArgument(index++); + String topic = args.getArgument(index++); + String event = args.getArgument(index++); if (host.beforeOffer(commType, topic, event)) { return null; @@ -676,8 +703,9 @@ public class FeatureTest { private final Serializer serializer = new Serializer(); /** + * Constructor. * - * @param context + * @param context context */ public TopicSinkImpl(Context context) { this.context = context; @@ -732,8 +760,9 @@ public class FeatureTest { private AtomicReference<Pair<CountDownLatch, CountDownLatch>> pair = new AtomicReference<>(null); /** + * Constructor. * - * @param context + * @param context context * @param internal {@code true} if to read from the internal topic, {@code false} * to read from the external topic */ @@ -778,7 +807,8 @@ public class FeatureTest { try { do { processMessages(newPair.first(), listener); - } while (!newPair.first().await(stdInterPollMs, TimeUnit.MILLISECONDS)); + } + while (!newPair.first().await(stdInterPollMs, TimeUnit.MILLISECONDS)); logger.info("topic source thread completed"); @@ -850,8 +880,8 @@ public class FeatureTest { * Polls for messages from the topic and offers them to the listener. * * @param stopped triggered if processing should stop - * @param listener - * @throws InterruptedException + * @param listener listener + * @throws InterruptedException throws interrupted exception */ private void processMessages(CountDownLatch stopped, TopicListener listener) throws InterruptedException { @@ -874,7 +904,7 @@ public class FeatureTest { private static class TopicImpl implements Topic { /** - * + * Constructor. */ public TopicImpl() { super(); @@ -954,8 +984,9 @@ public class FeatureTest { private final Context context; /** + * Constructor. * - * @param context + * @param context context */ public FeatureFactory(Context context) { this.context = context; @@ -1029,8 +1060,9 @@ public class FeatureTest { private final TypeReference<TreeMap<String, String>> typeRef = new TypeReference<TreeMap<String, String>>() {}; /** + * Constructor. * - * @param context + * @param context context */ public ManagerFactory(Context context) { @@ -1065,8 +1097,9 @@ public class FeatureTest { private final Context context; /** + * Constructor. * - * @param context + * @param context context */ public DmaapFactory(Context context) { this.context = context; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java index 70bacb1b..050ca612 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest2.java @@ -70,7 +70,7 @@ import org.slf4j.LoggerFactory; * following are not: <dl> <dt>PolicyEngine, PolicyController, DroolsController</dt> <dd>mocked</dd> * </dl> * - * <p> The following fields must be set before executing this: <ul> <li>UEB_SERVERS</li> + * <p>The following fields must be set before executing this: <ul> <li>UEB_SERVERS</li> * <li>INTERNAL_TOPIC</li> <li>EXTERNAL_TOPIC</li> </ul> */ public class FeatureTest2 { @@ -135,7 +135,10 @@ public class FeatureTest2 { */ private Context ctx; - + /** + * Setup before class. + * + */ @BeforeClass public static void setUpBeforeClass() { saveFeatureFactory = PoolingFeature.getFactory(); @@ -149,6 +152,10 @@ public class FeatureTest2 { internalSink.start(); } + /** + * Tear down after class. + * + */ @AfterClass public static void tearDownAfterClass() { PoolingFeature.setFactory(saveFeatureFactory); @@ -159,11 +166,17 @@ public class FeatureTest2 { internalSink.stop(); } + /** + * Setup. + */ @Before public void setUp() { ctx = null; } + /** + * Tear down. + */ @After public void tearDown() { if (ctx != null) { @@ -275,7 +288,7 @@ public class FeatureTest2 { /** * Counts the number of decode errors. */ - private final AtomicInteger nDecodeErrors = new AtomicInteger(0); + private final AtomicInteger decodeErrors = new AtomicInteger(0); /** * Number of events we're still waiting to receive. @@ -283,13 +296,14 @@ public class FeatureTest2 { private final CountDownLatch eventCounter; /** + * Constructor. * * @param nEvents number of events to be processed */ - public Context(int nEvents) { + public Context(int events) { featureFactory = new FeatureFactory(this); managerFactory = new ManagerFactory(this); - eventCounter = new CountDownLatch(nEvents); + eventCounter = new CountDownLatch(events); PoolingFeature.setFactory(featureFactory); PoolingManagerImpl.setFactory(managerFactory); @@ -333,17 +347,17 @@ public class FeatureTest2 { * Verifies that all hosts processed at least one message. */ public void checkAllSawAMsg() { - int x = 0; + int msgs = 0; for (Host host : hosts) { - assertTrue("x=" + x, host.messageSeen()); - ++x; + assertTrue("msgs=" + msgs, host.messageSeen()); + ++msgs; } } /** * Offers an event to the external topic. * - * @param event + * @param event event */ public void offerExternal(String event) { externalSink.send(event); @@ -352,7 +366,7 @@ public class FeatureTest2 { /** * Decodes an event. * - * @param event + * @param event event * @return the decoded event, or {@code null} if it cannot be decoded */ public Object decodeEvent(String event) { @@ -362,15 +376,17 @@ public class FeatureTest2 { /** * Associates a controller with its drools controller. * - * @param controller - * @param droolsController + * @param controller controller + * @param droolsController drools controller */ public void addController(PolicyController controller, DroolsController droolsController) { drools2policy.put(droolsController, controller); } /** - * @param droolsController + * Get controller. + * + * @param droolsController drools controller * @return the controller associated with a drools controller, or {@code null} if it has no * associated controller */ @@ -379,21 +395,23 @@ public class FeatureTest2 { } /** + * Get decode errors. * * @return the number of decode errors so far */ public int getDecodeErrors() { - return nDecodeErrors.get(); + return decodeErrors.get(); } /** * Increments the count of decode errors. */ public void bumpDecodeErrors() { - nDecodeErrors.incrementAndGet(); + decodeErrors.incrementAndGet(); } /** + * Get remaining events. * * @return the number of events that haven't been processed */ @@ -411,10 +429,10 @@ public class FeatureTest2 { /** * Waits, for a period of time, for all events to be processed. * - * @param time - * @param units + * @param time time + * @param units units * @return {@code true} if all events have been processed, {@code false} otherwise - * @throws InterruptedException + * @throws InterruptedException throws interrupted exception */ public boolean awaitEvents(long time, TimeUnit units) throws InterruptedException { return eventCounter.await(time, units); @@ -424,7 +442,7 @@ public class FeatureTest2 { * Waits, for a period of time, for all hosts to enter the Active state. * * @param timeMs maximum time to wait, in milliseconds - * @throws InterruptedException + * @throws InterruptedException throws interrupted exception */ public void awaitAllActive(long timeMs) throws InterruptedException { long tend = timeMs + System.currentTimeMillis(); @@ -457,8 +475,9 @@ public class FeatureTest2 { private final DroolsController drools = mock(DroolsController.class); /** + * Constructor. * - * @param context + * @param context context */ public Host(Context context) { @@ -485,7 +504,7 @@ public class FeatureTest2 { * @param timeMs time to wait, in milliseconds * @return {@code true} if the host entered the Active state within the given amount of * time, {@code false} otherwise - * @throws InterruptedException + * @throws InterruptedException throws interrupted exception */ public boolean awaitActive(long timeMs) throws InterruptedException { return feature.getActiveLatch().await(timeMs, TimeUnit.MILLISECONDS); @@ -531,9 +550,9 @@ public class FeatureTest2 { /** * Offers an event to the feature, before the policy controller handles it. * - * @param protocol - * @param topic2 - * @param event + * @param protocol protocol + * @param topic2 topic + * @param event event * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean beforeOffer(CommInfrastructure protocol, String topic2, String event) { @@ -543,10 +562,10 @@ public class FeatureTest2 { /** * Offers an event to the feature, after the policy controller handles it. * - * @param protocol - * @param topic - * @param event - * @param success + * @param protocol protocol + * @param topic topic + * @param event event + * @param success success * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean afterOffer(CommInfrastructure protocol, String topic, String event, boolean success) { @@ -557,7 +576,7 @@ public class FeatureTest2 { /** * Offers an event to the feature, before the drools controller handles it. * - * @param fact + * @param fact fact * @return {@code true} if the event was handled, {@code false} otherwise */ public boolean beforeInsert(Object fact) { @@ -567,7 +586,7 @@ public class FeatureTest2 { /** * Offers an event to the feature, after the drools controller handles it. * - * @param fact + * @param fact fact * @param successInsert {@code true} if it was successfully inserted by the drools * controller, {@code false} otherwise * @return {@code true} if the event was handled, {@code false} otherwise @@ -584,6 +603,7 @@ public class FeatureTest2 { } /** + * Message seen. * * @return {@code true} if a message was seen for this host, {@code false} otherwise */ @@ -608,10 +628,10 @@ public class FeatureTest2 { @Override public Void answer(InvocationOnMock args) throws Throwable { - int i = 0; - CommInfrastructure commType = args.getArgument(i++); - String topic = args.getArgument(i++); - String event = args.getArgument(i++); + int index = 0; + CommInfrastructure commType = args.getArgument(index++); + String topic = args.getArgument(index++); + String event = args.getArgument(index++); if (host.beforeOffer(commType, topic, event)) { return null; @@ -649,8 +669,9 @@ public class FeatureTest2 { private final Context context; /** + * Constructor. * - * @param context + * @param context context */ public FeatureFactory(Context context) { this.context = context; @@ -727,8 +748,9 @@ public class FeatureTest2 { private final TypeReference<TreeMap<String, String>> typeRef = new TypeReference<TreeMap<String, String>>() {}; /** + * Constructor. * - * @param context + * @param context context */ public ManagerFactory(Context context) { diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureExceptionTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureExceptionTest.java index 34b604c9..731736a1 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureExceptionTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureExceptionTest.java @@ -20,7 +20,8 @@ package org.onap.policy.drools.pooling; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.onap.policy.common.utils.test.ExceptionsTester; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureRtExceptionTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureRtExceptionTest.java index cbb24421..fcd23322 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureRtExceptionTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureRtExceptionTest.java @@ -20,7 +20,8 @@ package org.onap.policy.drools.pooling; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.onap.policy.common.utils.test.ExceptionsTester; import org.onap.policy.drools.pooling.PoolingFeatureRtException; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java index c57a9f6f..07fc757b 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingFeatureTest.java @@ -31,6 +31,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -38,8 +39,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.pooling.PoolingFeature.Factory; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.drools.system.PolicyEngine; @@ -95,6 +96,11 @@ public class PoolingFeatureTest { PoolingFeature.setFactory(saveFactory); } + /** + * Setup. + * + * @throws Exception exception + */ @Before public void setUp() throws Exception { props = initProperties(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java index d90bac4b..e6b6e4cd 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java @@ -34,6 +34,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.LinkedList; import java.util.Properties; import java.util.Queue; @@ -46,9 +47,9 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicListener; +import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.pooling.PoolingManagerImpl.Factory; import org.onap.policy.drools.pooling.extractor.ClassExtractors; import org.onap.policy.drools.pooling.message.BucketAssignments; @@ -125,6 +126,11 @@ public class PoolingManagerImplTest { PoolingManagerImpl.setFactory(saveFactory); } + /** + * Setup. + * + * @throws Exception throws exception + */ @Before public void setUp() throws Exception { plainProps = new Properties(); @@ -202,7 +208,7 @@ public class PoolingManagerImplTest { PolicyController ctlr = mock(PolicyController.class); PoolingFeatureRtException ex = expectException(PoolingFeatureRtException.class, - () -> new PoolingManagerImpl(MY_HOST, ctlr, poolProps, active)); + () -> new PoolingManagerImpl(MY_HOST, ctlr, poolProps, active)); assertNotNull(ex.getCause()); assertTrue(ex.getCause() instanceof ClassCastException); } @@ -214,7 +220,7 @@ public class PoolingManagerImplTest { when(factory.makeDmaapManager(any())).thenThrow(ex); PoolingFeatureRtException ex2 = expectException(PoolingFeatureRtException.class, - () -> new PoolingManagerImpl(MY_HOST, controller, poolProps, active)); + () -> new PoolingManagerImpl(MY_HOST, controller, poolProps, active)); assertEquals(ex, ex2.getCause()); } @@ -304,26 +310,26 @@ public class PoolingManagerImplTest { Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID); mgr.handle(msg); - verify(dmaap, times(START_PUB+1)).publish(any()); + verify(dmaap, times(START_PUB + 1)).publish(any()); mgr.beforeStop(); verify(dmaap).stopConsumer(mgr); verify(sched).shutdownNow(); - verify(dmaap, times(START_PUB+2)).publish(any()); + verify(dmaap, times(START_PUB + 2)).publish(any()); verify(dmaap).publish(contains("offline")); assertTrue(mgr.getCurrent() instanceof IdleState); // verify that next message is handled locally mgr.handle(msg); - verify(dmaap, times(START_PUB+2)).publish(any()); + verify(dmaap, times(START_PUB + 2)).publish(any()); verify(controller).onTopicEvent(CommInfrastructure.UEB, TOPIC2, THE_EVENT); } @Test public void testBeforeStop_NotRunning() throws Exception { - State st = mgr.getCurrent(); + final State st = mgr.getCurrent(); mgr.beforeStop(); @@ -339,7 +345,7 @@ public class PoolingManagerImplTest { // call beforeStart but not afterStart mgr.beforeStart(); - State st = mgr.getCurrent(); + final State st = mgr.getCurrent(); mgr.beforeStop(); @@ -624,7 +630,7 @@ public class PoolingManagerImplTest { // route the message to this host mgr.startDistributing(makeAssignments(true)); - CountDownLatch latch = catchRecursion(false); + final CountDownLatch latch = catchRecursion(false); Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID); mgr.handle(msg); @@ -644,7 +650,7 @@ public class PoolingManagerImplTest { // route the message to this host mgr.startDistributing(makeAssignments(true)); - CountDownLatch latch = catchRecursion(true); + final CountDownLatch latch = catchRecursion(true); Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID); mgr.handle(msg); @@ -870,7 +876,7 @@ public class PoolingManagerImplTest { assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT)); - verify(dmaap, times(START_PUB+1)).publish(any()); + verify(dmaap, times(START_PUB + 1)).publish(any()); } @Test @@ -921,7 +927,7 @@ public class PoolingManagerImplTest { // route the message to this host mgr.startDistributing(makeAssignments(true)); - CountDownLatch latch = catchRecursion(true); + final CountDownLatch latch = catchRecursion(true); Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID); mgr.handle(msg); @@ -943,7 +949,7 @@ public class PoolingManagerImplTest { // generate RuntimeException when onTopicEvent() is invoked doThrow(new IllegalArgumentException("expected")).when(controller).onTopicEvent(any(), any(), any()); - CountDownLatch latch = catchRecursion(true); + final CountDownLatch latch = catchRecursion(true); Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID); mgr.handle(msg); @@ -975,7 +981,7 @@ public class PoolingManagerImplTest { } @Test - public void testHandleInternal_IOEx() throws Exception { + public void testHandleInternal_IoEx() throws Exception { startMgr(); mgr.onTopicEvent(CommInfrastructure.UEB, MY_TOPIC, "invalid message"); @@ -1028,7 +1034,7 @@ public class PoolingManagerImplTest { // route the message to the other host mgr.startDistributing(makeAssignments(false)); assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT)); - verify(dmaap, times(START_PUB+1)).publish(any()); + verify(dmaap, times(START_PUB + 1)).publish(any()); } @Test diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java index eac8bfb1..cc716a2a 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java @@ -32,6 +32,7 @@ import static org.onap.policy.drools.pooling.PoolingProperties.POOLING_TOPIC; import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX; import static org.onap.policy.drools.pooling.PoolingProperties.REACTIVATE_MS; import static org.onap.policy.drools.pooling.PoolingProperties.START_HEARTBEAT_MS; + import java.util.Properties; import java.util.function.Function; import org.junit.Before; @@ -57,6 +58,11 @@ public class PoolingPropertiesTest { private Properties plain; private PoolingProperties pooling; + /** + * Setup. + * + * @throws Exception throws an exception + */ @Before public void setUp() throws Exception { plain = makeProperties(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java index 4206a836..0b098c13 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertNotNull; import static org.onap.policy.drools.pooling.state.FilterUtils.makeAnd; import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals; import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr; + import java.util.Map; import java.util.TreeMap; import org.junit.Test; @@ -42,7 +43,7 @@ public class SerializerTest { @Test @SuppressWarnings("unchecked") public void testEncodeFilter() throws Exception { - Serializer ser = new Serializer(); + final Serializer ser = new Serializer(); /* * Ensure raw maps serialize as expected. Use a TreeMap so the field diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTest.java index e6269a9a..c277a00f 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTest.java @@ -23,6 +23,7 @@ package org.onap.policy.drools.pooling.extractor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; + import java.util.Map; import java.util.Properties; import java.util.TreeMap; @@ -44,6 +45,10 @@ public class ClassExtractorsTest { private Properties props; private ClassExtractors map; + /** + * Setup. + * + */ @Before public void setUp() { props = new Properties(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTestSupport.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTestSupport.java index 98b679d4..df42fe0f 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTestSupport.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ClassExtractorsTestSupport.java @@ -28,7 +28,7 @@ public class ClassExtractorsTestSupport { private ClassExtractorsTestSupport2 nested = new ClassExtractorsTestSupport2(); /** - * + * Constructor. */ public ClassExtractorsTestSupport() { super(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ExtractorExceptionTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ExtractorExceptionTest.java index d1458de7..aef0a925 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ExtractorExceptionTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/ExtractorExceptionTest.java @@ -21,6 +21,7 @@ package org.onap.policy.drools.pooling.extractor; import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.onap.policy.common.utils.test.ExceptionsTester; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/FieldExtractorTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/FieldExtractorTest.java index 9794bffa..7536d007 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/FieldExtractorTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/FieldExtractorTest.java @@ -22,6 +22,7 @@ package org.onap.policy.drools.pooling.extractor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; + import java.lang.reflect.Field; import org.junit.Before; import org.junit.Test; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MapExtractorTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MapExtractorTest.java index 48985bf3..afaa2b65 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MapExtractorTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MapExtractorTest.java @@ -20,7 +20,9 @@ package org.onap.policy.drools.pooling.extractor; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.HashMap; import java.util.Map; import org.junit.Before; @@ -48,7 +50,7 @@ public class MapExtractorTest { public void testExtract_MissingValue() { Map<String,Object> map = new HashMap<>(); - map.put(KEY+"x", VALUE+"x"); + map.put(KEY + "x", VALUE + "x"); // object is a map, but doesn't have the key assertNull(ext.extract(map)); @@ -58,7 +60,7 @@ public class MapExtractorTest { public void testExtract() { Map<String,Object> map = new HashMap<>(); - map.put(KEY+"x", VALUE+"x"); + map.put(KEY + "x", VALUE + "x"); map.put(KEY, VALUE); // object is a map and contains the key diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MethodExtractorTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MethodExtractorTest.java index ae5858e7..41f731fb 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MethodExtractorTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/extractor/MethodExtractorTest.java @@ -22,6 +22,7 @@ package org.onap.policy.drools.pooling.extractor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; + import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BasicMessageTester.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BasicMessageTester.java index 69d7e67c..2dab38d1 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BasicMessageTester.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BasicMessageTester.java @@ -23,9 +23,10 @@ package org.onap.policy.drools.pooling.message; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; + +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.onap.policy.drools.pooling.PoolingFeatureException; -import com.fasterxml.jackson.databind.ObjectMapper; /** * Superclass used to test subclasses of {@link Message}. @@ -49,6 +50,7 @@ public abstract class BasicMessageTester<T extends Message> { private final Class<T> subclazz; /** + * Constructor. * * @param subclazz subclass of {@link Message} being tested */ @@ -60,7 +62,6 @@ public abstract class BasicMessageTester<T extends Message> { * Creates a default Message and verifies that the source and channel are * {@code null}. * - * @return the default Message */ @Test public final void testDefaultConstructor() { @@ -71,8 +72,6 @@ public abstract class BasicMessageTester<T extends Message> { * Tests that the Message has the correct source, and that the channel is * {@code null}. * - * @param msg message to be checked - * @param expectedSource what the source is expected to be */ @Test public final void testConstructorWithArgs() { diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java index c14e8dba..5788141b 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + import java.util.Arrays; import java.util.SortedSet; import java.util.TreeSet; @@ -41,7 +42,7 @@ public class BucketAssignmentsTest { @Test public void testBucketAssignmentsStringArray() { - String arr[] = {"abc", "def"}; + String[] arr = {"abc", "def"}; BucketAssignments asgn = new BucketAssignments(arr); assertNotNull(asgn.getHostArray()); @@ -51,13 +52,13 @@ public class BucketAssignmentsTest { @Test public void testGetHostArray_testSetHostArray() { - String arr[] = {"abc", "def"}; + String[] arr = {"abc", "def"}; BucketAssignments asgn = new BucketAssignments(arr); assertNotNull(asgn.getHostArray()); assertEquals(arr.toString(), asgn.getHostArray().toString()); - String arr2[] = {"xyz"}; + String[] arr2 = {"xyz"}; asgn.setHostArray(arr2); assertNotNull(asgn.getHostArray()); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/ForwardTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/ForwardTest.java index 2549fa94..c51cafed 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/ForwardTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/ForwardTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; + import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageTest.java index 432dcc3c..4e683ff9 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageTest.java @@ -22,6 +22,7 @@ package org.onap.policy.drools.pooling.message; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; + import org.junit.Test; public class MessageTest extends BasicMessageTester<Message> { diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageWithAssignmentsTester.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageWithAssignmentsTester.java index 2b670dcc..e5dfae9b 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageWithAssignmentsTester.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/MessageWithAssignmentsTester.java @@ -22,6 +22,7 @@ package org.onap.policy.drools.pooling.message; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; + import org.junit.Test; /** @@ -31,7 +32,7 @@ import org.junit.Test; */ public abstract class MessageWithAssignmentsTester<T extends MessageWithAssignments> extends BasicMessageTester<T> { // values set by makeValidMessage() - public static final String[] VALID_ARRAY = {VALID_HOST, VALID_HOST+"_xxx"}; + public static final String[] VALID_ARRAY = {VALID_HOST, VALID_HOST + "_xxx"}; public static final BucketAssignments VALID_ASGN = new BucketAssignments(VALID_ARRAY); /** @@ -41,6 +42,7 @@ public abstract class MessageWithAssignmentsTester<T extends MessageWithAssignme private boolean nullAssignments; /** + * Constructor. * * @param subclazz subclass of {@link MessageWithAssignments} being tested */ diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ActiveStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ActiveStateTest.java index f2701038..9cb835c9 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ActiveStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ActiveStateTest.java @@ -33,6 +33,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Arrays; import java.util.Map; import org.junit.Before; @@ -50,6 +51,9 @@ public class ActiveStateTest extends BasicStateTester { private ActiveState state; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/BasicStateTester.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/BasicStateTester.java index 75ca7564..20f49a0e 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/BasicStateTester.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/BasicStateTester.java @@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; + import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -113,6 +114,11 @@ public class BasicStateTester { super(); } + /** + * Setup. + * + * @throws Exception throws exception + */ public void setUp() throws Exception { onceSchedules = new LinkedList<>(); onceTasks = new LinkedList<>(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/FilterUtilsTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/FilterUtilsTest.java index ba517194..f4eb870e 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/FilterUtilsTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/FilterUtilsTest.java @@ -31,6 +31,7 @@ import static org.onap.policy.drools.pooling.state.FilterUtils.JSON_VALUE; import static org.onap.policy.drools.pooling.state.FilterUtils.makeAnd; import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals; import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr; + import java.util.Map; import org.junit.Test; diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/IdleStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/IdleStateTest.java index 497dbbb7..cf2c9c7c 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/IdleStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/IdleStateTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -42,6 +43,9 @@ public class IdleStateTest extends BasicStateTester { private IdleState state; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/InactiveStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/InactiveStateTest.java index ae53ce05..ee7fd5e5 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/InactiveStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/InactiveStateTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -41,6 +42,10 @@ public class InactiveStateTest extends BasicStateTester { private InactiveState state; + /** + * Setup. + * + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ProcessingStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ProcessingStateTest.java index 7ac58439..4f634516 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ProcessingStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/ProcessingStateTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Arrays; import java.util.Map; import org.junit.Before; @@ -45,6 +46,9 @@ public class ProcessingStateTest extends BasicStateTester { private ProcessingState state; private HostBucket hostBucket; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/QueryStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/QueryStateTest.java index 7cd37581..5601932e 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/QueryStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/QueryStateTest.java @@ -30,6 +30,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -44,6 +45,9 @@ public class QueryStateTest extends BasicStateTester { private QueryState state; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StartStateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StartStateTest.java index 18f12ff8..faafb8cb 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StartStateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StartStateTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -46,6 +47,9 @@ public class StartStateTest extends BasicStateTester { private StartState state; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java index e3d383d9..42bb35f2 100644 --- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java +++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -47,6 +48,9 @@ public class StateTest extends BasicStateTester { private State state; + /** + * Setup. + */ @Before public void setUp() throws Exception { super.setUp(); |