diff options
Diffstat (limited to 'testsuites/integration/integration-uservice-test/src/test')
10 files changed, 162 insertions, 137 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/EventGenerator.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/EventGenerator.java index 6a585d7c5..55b9fa953 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/EventGenerator.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/events/EventGenerator.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -22,12 +22,17 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.events; import java.util.Random; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * The Class EventGenerator. * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class EventGenerator { + private static final Logger LOGGER = LoggerFactory.getLogger(EventGenerator.class); + private static int nextEventNo = 0; /** @@ -576,7 +581,7 @@ public class EventGenerator { */ public static void main(final String[] args) { if (args.length != 2) { - System.err.println("usage EventGenerator #events XML|JSON"); + LOGGER.error("usage EventGenerator #events XML|JSON"); return; } @@ -584,17 +589,17 @@ public class EventGenerator { try { eventCount = Integer.parseInt(args[0]); } catch (final Exception e) { - System.err.println("usage EventGenerator #events XML|JSON"); + LOGGER.error("usage EventGenerator #events XML|JSON"); e.printStackTrace(); return; } if (args[1].equalsIgnoreCase("XML")) { - System.out.println(xmlEvents(eventCount)); + LOGGER.info(xmlEvents(eventCount)); } else if (args[1].equalsIgnoreCase("JSON")) { - System.out.println(jsonEvents(eventCount)); + LOGGER.info(jsonEvents(eventCount)); } else { - System.err.println("usage EventGenerator #events XML|JSON"); + LOGGER.error("usage EventGenerator #events XML|JSON"); return; } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java index dcec4a944..7367b0220 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventProducer.java @@ -68,8 +68,8 @@ public class JmsEventProducer implements Runnable { * @throws JMSException the JMS exception */ public JmsEventProducer(final String topic, final ConnectionFactory connectionFactory, final String username, - final String password, final int eventCount, final boolean sendObjects, final long eventInterval) - throws JMSException { + final String password, final int eventCount, final boolean sendObjects, final long eventInterval) + throws JMSException { this.topic = topic; this.eventCount = eventCount; this.sendObjects = sendObjects; @@ -88,7 +88,7 @@ public class JmsEventProducer implements Runnable { public void run() { final Topic jmsTopic = new ActiveMQTopic(topic); try (final Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic)) { + final MessageProducer jmsProducer = jmsSession.createProducer(jmsTopic)) { while (producerThread.isAlive() && !stopFlag) { ThreadUtilities.sleep(50); @@ -120,8 +120,8 @@ public class JmsEventProducer implements Runnable { */ private void sendEventsToTopic(final Session jmsSession, final MessageProducer jmsProducer) throws JMSException { - LOGGER.info("{} : sending events to JMS server, event count {}", this.getClass().getCanonicalName(), - eventCount); + LOGGER.debug("{} : sending events to JMS server, event count {}", this.getClass().getCanonicalName(), + eventCount); for (int i = 0; i < eventCount; i++) { ThreadUtilities.sleep(eventInterval); @@ -135,7 +135,7 @@ public class JmsEventProducer implements Runnable { jmsProducer.send(jmsMessage); eventsSentCount++; } - LOGGER.info("{} : completed, number of events sent", this.getClass().getCanonicalName(), eventsSentCount); + LOGGER.debug("{} : completed, number of events sent", this.getClass().getCanonicalName(), eventsSentCount); } /** @@ -151,13 +151,13 @@ public class JmsEventProducer implements Runnable { * Shutdown. */ public void shutdown() { - LOGGER.info("{} : stopping", this.getClass().getCanonicalName()); + LOGGER.debug("{} : stopping", this.getClass().getCanonicalName()); stopFlag = true; while (producerThread.isAlive()) { ThreadUtilities.sleep(10); } - LOGGER.info("{} : stopped", this.getClass().getCanonicalName()); + LOGGER.debug("{} : stopped", this.getClass().getCanonicalName()); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java index 94155c1a5..2fd174651 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/jms/JmsEventSubscriber.java @@ -106,7 +106,7 @@ public class JmsEventSubscriber implements Runnable { throw new ApexEventRuntimeException("JMS event consumption failed", e); } - LOGGER.info("{} : event reception completed", this.getClass().getCanonicalName()); + LOGGER.debug("{} : event reception completed", this.getClass().getCanonicalName()); } /** @@ -131,7 +131,7 @@ public class JmsEventSubscriber implements Runnable { } connection.close(); - LOGGER.info("{} : stopped", this.getClass().getCanonicalName()); + LOGGER.debug("{} : stopped", this.getClass().getCanonicalName()); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventProducer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventProducer.java index dd46f7f74..e0f5c23c4 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventProducer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventProducer.java @@ -29,6 +29,8 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.serialization.StringSerializer; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.testsuites.integration.uservice.adapt.events.EventGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class KafkaEventProducer. @@ -36,6 +38,9 @@ import org.onap.policy.apex.testsuites.integration.uservice.adapt.events.EventGe * @author Liam Fallon (liam.fallon@ericsson.com) */ public class KafkaEventProducer implements Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaEventProducer.class); + private final String topic; private final SharedKafkaTestResource sharedKafkaTestResource; private final int eventCount; @@ -101,12 +106,12 @@ public class KafkaEventProducer implements Runnable { * @param producer the producer */ private void sendEventsToTopic(final Producer<String, String> producer) { - System.out.println(KafkaEventProducer.class.getCanonicalName() - + ": sending events to Kafka server , event count " + eventCount + ", xmlEvents " + xmlEvents); + LOGGER.debug("{} : sending events to Kafka server, event count {}, xmlEvents {}", + KafkaEventProducer.class.getCanonicalName(), eventCount, xmlEvents); for (int i = 0; i < eventCount; i++) { - System.out.println(KafkaEventProducer.class.getCanonicalName() + ": waiting " + eventInterval - + " milliseconds before sending next event"); + LOGGER.debug("{} : waiting {} milliseconds before sending next event", + KafkaEventProducer.class.getCanonicalName(), eventInterval); ThreadUtilities.sleep(eventInterval); String eventString = null; @@ -118,9 +123,9 @@ public class KafkaEventProducer implements Runnable { producer.send(new ProducerRecord<String, String>(topic, "Event" + i + "Of" + eventCount, eventString)); producer.flush(); eventsSentCount++; - System.out.println("****** Sent event No. " + eventsSentCount + " ******"); + LOGGER.debug("****** Sent event No. {} ******", eventsSentCount); } - System.out.println(KafkaEventProducer.class.getCanonicalName() + ": completed"); + LOGGER.debug("{}: completed", KafkaEventProducer.class.getCanonicalName()); } /** @@ -136,7 +141,7 @@ public class KafkaEventProducer implements Runnable { * Shutdown. */ public void shutdown() { - System.out.println(KafkaEventProducer.class.getCanonicalName() + ": stopping"); + LOGGER.debug("{} : stopping", KafkaEventProducer.class.getCanonicalName()); stopFlag = true; @@ -144,6 +149,6 @@ public class KafkaEventProducer implements Runnable { ThreadUtilities.sleep(10); } - System.out.println(KafkaEventProducer.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{} : stopped", KafkaEventProducer.class.getCanonicalName()); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventSubscriber.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventSubscriber.java index dbe8d0294..da2cc3344 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventSubscriber.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/kafka/KafkaEventSubscriber.java @@ -32,6 +32,8 @@ import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.common.serialization.StringDeserializer; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class KafkaEventSubscriber. @@ -39,6 +41,9 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class KafkaEventSubscriber implements Runnable { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(KafkaEventSubscriber.class); + private static final Duration POLL_DURATION = Duration.ofMillis(100); private final String topic; @@ -59,11 +64,9 @@ public class KafkaEventSubscriber implements Runnable { throws MessagingException { this.topic = topic; - final Properties consumerProperties = new Properties(); consumerProperties.put("group.id", "test"); - consumer = sharedKafkaTestResource.getKafkaTestUtils().getKafkaConsumer(StringDeserializer.class, StringDeserializer.class, consumerProperties); consumer.subscribe(Arrays.asList(topic)); @@ -77,17 +80,16 @@ public class KafkaEventSubscriber implements Runnable { */ @Override public void run() { - System.out.println(KafkaEventSubscriber.class.getCanonicalName() - + ": receiving events from Kafka server on topic " + topic); + LOGGER.debug("{}: receiving events from Kafka server on topic {}", + KafkaEventSubscriber.class.getCanonicalName(), topic); while (subscriberThread.isAlive() && !subscriberThread.isInterrupted()) { try { final ConsumerRecords<String, String> records = consumer.poll(POLL_DURATION); for (final ConsumerRecord<String, String> record : records) { eventsReceivedCount++; - System.out.println("****** Received event No. " + eventsReceivedCount + " ******"); - System.out.println("offset=" + record.offset()); - System.out.println("key=" + record.key()); + LOGGER.debug("****** Received event No. {} ******\noffset={}\nkey={}", eventsReceivedCount, + record.offset(), record.key()); } } catch (final Exception e) { // Thread interrupted @@ -95,7 +97,7 @@ public class KafkaEventSubscriber implements Runnable { } } - System.out.println(KafkaEventSubscriber.class.getCanonicalName() + ": event reception completed"); + LOGGER.debug("{}: event reception completed", KafkaEventSubscriber.class.getCanonicalName()); } /** @@ -118,6 +120,6 @@ public class KafkaEventSubscriber implements Runnable { } consumer.close(); - System.out.println(KafkaEventSubscriber.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{} : stopped", KafkaEventSubscriber.class.getCanonicalName()); } } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerClient.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerClient.java index 46973290a..023ff9998 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerClient.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerClient.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -25,11 +25,15 @@ import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStri import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.testsuites.integration.uservice.adapt.events.EventGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class WebSocketEventProducerClient. */ public class WebSocketEventProducerClient implements WsStringMessageListener { + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventProducerClient.class); + private final String host; private final int port; private final int eventCount; @@ -50,7 +54,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { * @throws MessagingException the messaging exception */ public WebSocketEventProducerClient(final String host, final int port, final int eventCount, - final boolean xmlEvents, final long eventInterval) throws MessagingException { + final boolean xmlEvents, final long eventInterval) throws MessagingException { this.host = host; this.port = port; this.eventCount = eventCount; @@ -60,20 +64,20 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { client = new WsStringMessageClient(host, port); client.start(this); - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": host " + host + ", port " + port - + ", event count " + eventCount + ", xmlEvents " + xmlEvents); + LOGGER.debug("{}: host {}, port {}, event count {}, xmlEvents {}", + WebSocketEventProducerClient.class.getCanonicalName(), host, port, eventCount, xmlEvents); } /** * Send events. */ public void sendEvents() { - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": sending events on host " + host - + ", port " + port + ", event count " + eventCount + ", xmlEvents " + xmlEvents); + LOGGER.debug("{}: sending events on host {}, port {}, event count {}, xmlEvents {}", + WebSocketEventProducerClient.class.getCanonicalName(), host, port, eventCount, xmlEvents); for (int i = 0; i < eventCount; i++) { - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": waiting " + eventInterval - + " milliseconds before sending next event"); + LOGGER.debug("{}: waiting {} milliseconds before sending next event", + WebSocketEventProducerClient.class.getCanonicalName(), eventInterval); ThreadUtilities.sleep(eventInterval); String eventString = null; @@ -84,10 +88,10 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { } client.sendString(eventString); eventsSentCount++; - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": host " + host + ", port " - + port + ", sent event " + eventString); + LOGGER.debug("{}: host {}, port {}, sent event {}", WebSocketEventProducerClient.class.getCanonicalName(), + host, port, eventString); } - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": completed"); + LOGGER.debug("{}: completed", WebSocketEventProducerClient.class.getCanonicalName()); } /** @@ -104,7 +108,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { */ public void shutdown() { client.stop(); - System.out.println(WebSocketEventProducerClient.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{}: stopped", WebSocketEventProducerClient.class.getCanonicalName()); } /** @@ -112,8 +116,8 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { */ @Override public void receiveString(final String eventString) { - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": host " + host + ", port " + port - + ", received event " + eventString); + LOGGER.debug("{}: host {}, port {}, received event {}", WebSocketEventProducerServer.class.getCanonicalName(), + host, port, eventString); } /** @@ -124,7 +128,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { */ public static void main(final String[] args) throws MessagingException { if (args.length != 5) { - System.err.println("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); return; } @@ -132,7 +136,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { try { port = Integer.parseInt(args[1]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -141,7 +145,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { try { eventCount = Integer.parseInt(args[2]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -150,7 +154,7 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { try { eventInterval = Long.parseLong(args[4]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -159,12 +163,12 @@ public class WebSocketEventProducerClient implements WsStringMessageListener { if (args[3].equalsIgnoreCase("XML")) { xmlEvents = true; } else if (!args[3].equalsIgnoreCase("JSON")) { - System.err.println("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerClient host port #events XML|JSON eventInterval"); return; } - final WebSocketEventProducerClient client = - new WebSocketEventProducerClient(args[0], port, eventCount, xmlEvents, eventInterval); + final WebSocketEventProducerClient client = new WebSocketEventProducerClient(args[0], port, eventCount, + xmlEvents, eventInterval); client.sendEvents(); client.shutdown(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerServer.java index b75d99ff0..11438d952 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerServer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventProducerServer.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -25,11 +25,15 @@ import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStri import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.testsuites.integration.uservice.adapt.events.EventGenerator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class WebSocketEventProducerServer. */ public class WebSocketEventProducerServer implements WsStringMessageListener { + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventProducerServer.class); + private final int port; private final int eventCount; private final boolean xmlEvents; @@ -48,7 +52,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { * @throws MessagingException the messaging exception */ public WebSocketEventProducerServer(final int port, final int eventCount, final boolean xmlEvents, - final long eventInterval) throws MessagingException { + final long eventInterval) throws MessagingException { this.port = port; this.eventCount = eventCount; this.xmlEvents = xmlEvents; @@ -57,20 +61,20 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { server = new WsStringMessageServer(port); server.start(this); - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": port " + port + ", event count " - + eventCount + ", xmlEvents " + xmlEvents); + LOGGER.debug("{}: port {}, event count {}, xmlEvents {}", WebSocketEventProducerServer.class.getCanonicalName(), + port, eventCount, xmlEvents); } /** * Send events. */ public void sendEvents() { - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": sending events on port " + port - + ", event count " + eventCount + ", xmlEvents " + xmlEvents); + LOGGER.debug("{}: sending events on port {}, event count {}, xmlEvents {}", + WebSocketEventProducerServer.class.getCanonicalName(), port, eventCount, xmlEvents); for (int i = 0; i < eventCount; i++) { - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": waiting " + eventInterval - + " milliseconds before sending next event"); + LOGGER.debug("{}: waiting {} milliseconds before sending next event", + WebSocketEventProducerServer.class.getCanonicalName(), eventInterval); ThreadUtilities.sleep(eventInterval); String eventString = null; @@ -81,11 +85,11 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { } server.sendString(eventString); eventsSentCount++; - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": port " + port - + ", sent event " + eventString); + LOGGER.debug("{}: port {}, sent event {}", WebSocketEventProducerServer.class.getCanonicalName(), port, + eventString); } - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": event sending completed"); + LOGGER.debug("{}: event sending completed", WebSocketEventProducerServer.class.getCanonicalName()); } /** @@ -102,7 +106,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { */ public void shutdown() { server.stop(); - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{}: stopped", WebSocketEventProducerServer.class.getCanonicalName()); } /** @@ -110,8 +114,8 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { */ @Override public void receiveString(final String eventString) { - System.out.println(WebSocketEventProducerServer.class.getCanonicalName() + ": port " + port - + ", received event " + eventString); + LOGGER.debug("{}: port {}, received event {}", WebSocketEventProducerServer.class.getCanonicalName(), port, + eventString); } /** @@ -122,7 +126,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { */ public static void main(final String[] args) throws MessagingException { if (args.length != 4) { - System.err.println("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); return; } @@ -130,7 +134,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { try { port = Integer.parseInt(args[0]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -139,7 +143,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { try { eventCount = Integer.parseInt(args[1]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -148,7 +152,7 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { try { eventInterval = Long.parseLong(args[3]); } catch (final Exception e) { - System.err.println("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); + LOGGER.error("usage WebSocketEventProducerServer port #events XML|JSON eventInterval"); e.printStackTrace(); return; } @@ -157,12 +161,12 @@ public class WebSocketEventProducerServer implements WsStringMessageListener { if (args[2].equalsIgnoreCase("XML")) { xmlEvents = true; } else if (!args[2].equalsIgnoreCase("JSON")) { - System.err.println("usage WebSocketEventProducerServer port #events XML|JSON startDelay eventInterval"); + LOGGER.error("usage WebSocketEventProducerServer port #events XML|JSON startDelay eventInterval"); return; } - final WebSocketEventProducerServer server = - new WebSocketEventProducerServer(port, eventCount, xmlEvents, eventInterval); + final WebSocketEventProducerServer server = new WebSocketEventProducerServer(port, eventCount, xmlEvents, + eventInterval); server.sendEvents(); server.shutdown(); diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberClient.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberClient.java index fab51529a..5cd871225 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberClient.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberClient.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -23,11 +23,15 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient; import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class WebSocketEventSubscriberClient. */ public class WebSocketEventSubscriberClient implements WsStringMessageListener { + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberClient.class); + private final int port; private long eventsReceivedCount = 0; @@ -52,8 +56,8 @@ public class WebSocketEventSubscriberClient implements WsStringMessageListener { */ @Override public void receiveString(final String eventString) { - System.out.println(WebSocketEventSubscriberClient.class.getCanonicalName() + ": port " + port - + ", received event " + eventString); + LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberClient.class.getCanonicalName(), port, + eventString); eventsReceivedCount++; } @@ -71,7 +75,7 @@ public class WebSocketEventSubscriberClient implements WsStringMessageListener { */ public void shutdown() { client.stop(); - System.out.println(WebSocketEventSubscriberServer.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{}: stopped", WebSocketEventSubscriberServer.class.getCanonicalName()); } /** @@ -82,7 +86,7 @@ public class WebSocketEventSubscriberClient implements WsStringMessageListener { */ public static void main(final String[] args) throws MessagingException { if (args.length != 2) { - System.err.println("usage WebSocketEventSubscriberClient host port"); + LOGGER.error("usage WebSocketEventSubscriberClient host port"); return; } @@ -90,7 +94,7 @@ public class WebSocketEventSubscriberClient implements WsStringMessageListener { try { port = Integer.parseInt(args[0]); } catch (final Exception e) { - System.err.println("usage WebSocketEventSubscriberClient port"); + LOGGER.error("usage WebSocketEventSubscriberClient port"); e.printStackTrace(); return; } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberServer.java index edd6d7961..48d221791 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberServer.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/websocket/WebSocketEventSubscriberServer.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -23,11 +23,15 @@ package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener; import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class WebSocketEventSubscriberServer. */ public class WebSocketEventSubscriberServer implements WsStringMessageListener { + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberServer.class); + private final int port; private long eventsReceivedCount = 0; @@ -45,8 +49,7 @@ public class WebSocketEventSubscriberServer implements WsStringMessageListener { server = new WsStringMessageServer(port); server.start(this); - System.out.println( - WebSocketEventSubscriberServer.class.getCanonicalName() + ": port " + port + ", waiting for events"); + LOGGER.debug("{}: port {}, waiting for events", WebSocketEventSubscriberServer.class.getCanonicalName(), port); } /** @@ -54,8 +57,8 @@ public class WebSocketEventSubscriberServer implements WsStringMessageListener { */ @Override public void receiveString(final String eventString) { - System.out.println(WebSocketEventSubscriberServer.class.getCanonicalName() + ": port " + port - + ", received event " + eventString); + LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberServer.class.getCanonicalName(), port, + eventString); eventsReceivedCount++; } @@ -73,7 +76,7 @@ public class WebSocketEventSubscriberServer implements WsStringMessageListener { */ public void shutdown() { server.stop(); - System.out.println(WebSocketEventSubscriberServer.class.getCanonicalName() + ": stopped"); + LOGGER.debug("{} : stopped", WebSocketEventSubscriberServer.class.getCanonicalName()); } /** @@ -84,7 +87,7 @@ public class WebSocketEventSubscriberServer implements WsStringMessageListener { */ public static void main(final String[] args) throws MessagingException { if (args.length != 1) { - System.err.println("usage WebSocketEventSubscriberClient port"); + LOGGER.error("usage WebSocketEventSubscriberClient port"); return; } @@ -92,7 +95,7 @@ public class WebSocketEventSubscriberServer implements WsStringMessageListener { try { port = Integer.parseInt(args[0]); } catch (final Exception e) { - System.err.println("usage WebSocketEventSubscriberClient port"); + LOGGER.error("usage WebSocketEventSubscriberClient port"); e.printStackTrace(); return; } diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java index 34893ca5c..2377cfb91 100644 --- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java +++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/engine/ApexServiceTest.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -103,7 +103,6 @@ public class ApexServiceTest { parameters.getEngineParameters().getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); service = EngineServiceImpl.create(parameters); - LOGGER.debug("Running TestApexEngine. . ."); apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT"); @@ -127,12 +126,12 @@ public class ApexServiceTest { ParameterService.register(new LockManagerParameters()); ParameterService.register(new PersistorParameters()); ParameterService.register(new EngineServiceParameters()); - + EngineParameters engineParameters = new EngineParameters(); engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters()); ParameterService.register(engineParameters); } - + /** * Clear down parameters. */ @@ -146,7 +145,7 @@ public class ApexServiceTest { ParameterService.deregister(ContextParameterConstants.MAIN_GROUP_NAME); ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); } - + /** * Update the engine then test the engine with 2 sample events. * @@ -158,7 +157,7 @@ public class ApexServiceTest { final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); + LOGGER.debug("{}", service.getStatus(engineKey)); } while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { ThreadUtilities.sleep(200); @@ -177,14 +176,14 @@ public class ApexServiceTest { eventDataMap.put("TestTimestamp", testStartTime.getTime()); eventDataMap.put("TestTemperature", 34.5445667); - final ApexEvent event = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event.setExecutionId(System.nanoTime()); event.putAll(eventDataMap); engineServiceEventInterface.sendEvent(event); - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event2 = new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event2.setExecutionId(System.nanoTime()); event2.putAll(eventDataMap); engineServiceEventInterface.sendEvent(event2); @@ -198,7 +197,6 @@ public class ApexServiceTest { assertEquals(2, actionEventsReceived); actionEventsReceived = 0; - // Stop all engines on this engine service final long stoptime = System.currentTimeMillis(); service.stop(); @@ -221,7 +219,7 @@ public class ApexServiceTest { final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); + LOGGER.debug("{}", service.getStatus(engineKey)); } while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { ThreadUtilities.sleep(200); @@ -238,8 +236,8 @@ public class ApexServiceTest { eventDataMap.put("TestTimestamp", testStartTime.getTime()); eventDataMap.put("TestTemperature", 34.5445667); - final ApexEvent event1 = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event1 = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event1.putAll(eventDataMap); event1.setExecutionId(System.nanoTime()); @@ -260,8 +258,8 @@ public class ApexServiceTest { ThreadUtilities.sleep(100); } - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event2 = new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event2.setExecutionId(System.nanoTime()); event2.putAll(eventDataMap); @@ -309,7 +307,7 @@ public class ApexServiceTest { final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); + LOGGER.debug("{}", service.getStatus(engineKey)); } while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { ThreadUtilities.sleep(200); @@ -328,14 +326,14 @@ public class ApexServiceTest { eventDataMap.put("TestTimestamp", testStartTime.getTime()); eventDataMap.put("TestTemperature", 34.5445667); - final ApexEvent event = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event.setExecutionId(System.nanoTime()); event.putAll(eventDataMap); engineServiceEventInterface.sendEvent(event); - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event2 = new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event2.setExecutionId(System.nanoTime()); event2.putAll(eventDataMap); engineServiceEventInterface.sendEvent(event2); @@ -371,7 +369,7 @@ public class ApexServiceTest { final long starttime = System.currentTimeMillis(); for (final AxArtifactKey engineKey : service.getEngineKeys()) { - LOGGER.info("{}", service.getStatus(engineKey)); + LOGGER.debug("{}", service.getStatus(engineKey)); } while (!service.isStarted() && System.currentTimeMillis() - starttime < MAX_START_WAIT) { ThreadUtilities.sleep(200); @@ -388,8 +386,8 @@ public class ApexServiceTest { eventDataMap.put("TestTimestamp", testStartTime.getTime()); eventDataMap.put("TestTemperature", 34.5445667); - final ApexEvent event1 = - new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event1 = new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event1.putAll(eventDataMap); final ApexEventListener myEventListener1 = new ApexEventListener() { @@ -409,8 +407,8 @@ public class ApexServiceTest { ThreadUtilities.sleep(100); } - final ApexEvent event2 = - new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex"); + final ApexEvent event2 = new ApexEvent("Event0100", "0.0.1", "org.onap.policy.apex.domains.sample.events", + "test", "apex"); event2.putAll(eventDataMap); final ApexEventListener myEventListener2 = new ApexEventListener() { @@ -468,10 +466,10 @@ public class ApexServiceTest { } /** - * The listener interface for receiving test events. The class that is interested in processing - * a test event implements this interface, and the object created with that class is registered - * with a component using the component's <code>addTestListener</code> method. When the test - * event occurs, that object's appropriate method is invoked. + * The listener interface for receiving test events. The class that is interested in processing a test event + * implements this interface, and the object created with that class is registered with a component using the + * component's <code>addTestListener</code> method. When the test event occurs, that object's appropriate method is + * invoked. * * @see TestEvent */ @@ -489,7 +487,7 @@ public class ApexServiceTest { final Date testStartTime = new Date((Long) event.get("TestTimestamp")); final Date testEndTime = new Date(); - LOGGER.info("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); + LOGGER.debug("policy execution time: " + (testEndTime.getTime() - testStartTime.getTime()) + "ms"); } /** @@ -504,13 +502,13 @@ public class ApexServiceTest { assertTrue(result.get("TestMatchCase").equals(new Byte((byte) 123))); assertTrue(result.get("TestTemperature").equals(34.5445667)); assertTrue(((byte) result.get("TestMatchCaseSelected")) >= 0 - && ((byte) result.get("TestMatchCaseSelected") <= 3)); + && ((byte) result.get("TestMatchCaseSelected") <= 3)); assertTrue(((byte) result.get("TestEstablishCaseSelected")) >= 0 - && ((byte) result.get("TestEstablishCaseSelected") <= 3)); + && ((byte) result.get("TestEstablishCaseSelected") <= 3)); assertTrue(((byte) result.get("TestDecideCaseSelected")) >= 0 - && ((byte) result.get("TestDecideCaseSelected") <= 3)); - assertTrue( - ((byte) result.get("TestActCaseSelected")) >= 0 && ((byte) result.get("TestActCaseSelected") <= 3)); + && ((byte) result.get("TestDecideCaseSelected") <= 3)); + assertTrue(((byte) result.get("TestActCaseSelected")) >= 0 + && ((byte) result.get("TestActCaseSelected") <= 3)); } } |