From 33d831ef96a2150fb89ecfdaedd680b857185f87 Mon Sep 17 00:00:00 2001 From: dnwick Date: Sun, 6 Feb 2022 21:38:28 +0530 Subject: [PATCH 1/3] Upgrade log4j1 to 2.17.1 --- component/pom.xml | 7 ++- .../siddhi/extension/io/hl7/sink/Hl7Sink.java | 5 ++- .../io/hl7/source/Hl7ExceptionHandler.java | 5 ++- .../io/hl7/source/Hl7ReceivingApp.java | 5 ++- .../extension/io/hl7/source/Hl7Source.java | 5 ++- component/src/main/resources/log4j.properties | 34 -------------- .../src/main/resources/log4j2.properties | 40 +++++++++++++++++ .../io/hl7/source/TestCaseOfHl7Source.java | 42 +++++++++++------ .../hl7/source/TestCaseOfHl7SourceForTls.java | 5 ++- .../io/hl7/util/UnitTestAppender.java | 45 +++++++++++++------ component/src/test/resources/log4j.properties | 31 ------------- component/src/test/resources/log4j2.xml | 33 ++++++++++++++ pom.xml | 14 +++--- 13 files changed, 157 insertions(+), 114 deletions(-) delete mode 100644 component/src/main/resources/log4j.properties create mode 100755 component/src/main/resources/log4j2.properties delete mode 100644 component/src/test/resources/log4j.properties create mode 100644 component/src/test/resources/log4j2.xml diff --git a/component/pom.xml b/component/pom.xml index fe0bb7c..45433b2 100644 --- a/component/pom.xml +++ b/component/pom.xml @@ -42,8 +42,8 @@ siddhi-query-api - org.apache.log4j.wso2 - log4j + org.apache.logging.log4j + log4j-core org.testng @@ -177,8 +177,7 @@ io.siddhi.annotation.*;version="${siddhi.version.range}", io.siddhi.core.*;version="${siddhi.version.range}", - io.siddhi.query.*;version="${siddhi.version.range}", - org.apache.log4j + io.siddhi.query.*;version="${siddhi.version.range}" ca.uhn.hl7v2.*;version="${hapi.base.version}" diff --git a/component/src/main/java/io/siddhi/extension/io/hl7/sink/Hl7Sink.java b/component/src/main/java/io/siddhi/extension/io/hl7/sink/Hl7Sink.java index 4aa5d06..e67fb59 100644 --- a/component/src/main/java/io/siddhi/extension/io/hl7/sink/Hl7Sink.java +++ b/component/src/main/java/io/siddhi/extension/io/hl7/sink/Hl7Sink.java @@ -47,7 +47,8 @@ import io.siddhi.extension.io.hl7.util.Hl7Utils; import io.siddhi.query.api.definition.StreamDefinition; import io.siddhi.query.api.exception.SiddhiAppValidationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.net.URI; @@ -167,7 +168,7 @@ public class Hl7Sink extends Sink { - private static final Logger log = Logger.getLogger(Hl7Sink.class); + private static final Logger log = LogManager.getLogger(Hl7Sink.class); private boolean tlsEnabled; private String charset; private String hl7Encoding; diff --git a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ExceptionHandler.java b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ExceptionHandler.java index a3e5f46..ecb7adf 100644 --- a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ExceptionHandler.java +++ b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ExceptionHandler.java @@ -19,7 +19,8 @@ package io.siddhi.extension.io.hl7.source; import ca.uhn.hl7v2.protocol.ReceivingApplicationExceptionHandler; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Map; @@ -28,7 +29,7 @@ */ public class Hl7ExceptionHandler implements ReceivingApplicationExceptionHandler { - private static final Logger log = Logger.getLogger(Hl7ExceptionHandler.class); + private static final Logger log = LogManager.getLogger(Hl7ExceptionHandler.class); @Override public String processException(String s, Map map, String outGoingMsg, Exception e) { diff --git a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ReceivingApp.java b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ReceivingApp.java index 856064d..c5798d4 100644 --- a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ReceivingApp.java +++ b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7ReceivingApp.java @@ -30,7 +30,8 @@ import io.siddhi.core.stream.input.source.SourceEventListener; import io.siddhi.extension.io.hl7.source.exception.Hl7SourceRuntimeException; import io.siddhi.query.api.definition.Attribute; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.Arrays; @@ -45,7 +46,7 @@ */ public class Hl7ReceivingApp implements ReceivingApplication { - private static final Logger log = Logger.getLogger(Hl7ReceivingApp.class); + private static final Logger log = LogManager.getLogger(Hl7ReceivingApp.class); private SourceEventListener sourceEventListener; private String hl7EncodeType; private String hl7AckType; diff --git a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7Source.java b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7Source.java index baf143b..dd3c58f 100644 --- a/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7Source.java +++ b/component/src/main/java/io/siddhi/extension/io/hl7/source/Hl7Source.java @@ -44,7 +44,8 @@ import io.siddhi.extension.io.hl7.util.Hl7Constants; import io.siddhi.extension.io.hl7.util.Hl7Utils; import io.siddhi.query.api.definition.Attribute; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.FileInputStream; import java.io.IOException; @@ -158,7 +159,7 @@ ) public class Hl7Source extends Source { - private static final Logger log = Logger.getLogger(Hl7Source.class); + private static final Logger log = LogManager.getLogger(Hl7Source.class); private SourceEventListener sourceEventListener; private int port; private boolean tlsEnabled; diff --git a/component/src/main/resources/log4j.properties b/component/src/main/resources/log4j.properties deleted file mode 100644 index 22f4b32..0000000 --- a/component/src/main/resources/log4j.properties +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. licenses this file to you 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. -# -# For the general syntax of property based configuration files see the -# documenation of org.apache.log4j.PropertyConfigurator. -# The root category uses the appender called A1. Since no priority is -# specified, the root category assumes the default priority for root -# which is DEBUG in log4j. The root category is the only category that -# has a default priority. All other categories need not be assigned a -# priority in which case they inherit their priority from the -# hierarchy. - -#log4j.rootLogger=DEBUG, stdout -log4j.rootLogger=INFO, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%m%n -#log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %x - %m%n - diff --git a/component/src/main/resources/log4j2.properties b/component/src/main/resources/log4j2.properties new file mode 100755 index 0000000..2ce5010 --- /dev/null +++ b/component/src/main/resources/log4j2.properties @@ -0,0 +1,40 @@ +# +# /* +# * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# * +# * WSO2 Inc. licenses this file to you 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. +# */ +# + + +# For the general syntax of property based configuration files see the +# documenation of org.apache.log4j.PropertyConfigurator. + +# The root category uses the appender called A1. Since no priority is +# specified, the root category assumes the default priority for root +# which is DEBUG in log4j. The root category is the only category that +# has a default priority. All other categories need not be assigned a +# priority in which case they inherit their priority from the +# hierarchy. + +# Console appender configuration +appender.console.type = Console +appender.console.name = consoleLogger +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%t] %-5p %c %x - %m%n + +# Root logger referring to console appender +rootLogger.level = info +rootLogger.appenderRef.stdout.ref = consoleLogger diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7Source.java b/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7Source.java index 3264649..a4671b4 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7Source.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7Source.java @@ -32,7 +32,9 @@ import io.siddhi.extension.io.hl7.util.TestUtil; import io.siddhi.extension.io.hl7.util.UnitTestAppender; import io.siddhi.query.api.exception.SiddhiAppValidationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.Assert; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; @@ -49,7 +51,7 @@ */ public class TestCaseOfHl7Source { - private static Logger log = Logger.getLogger(TestCaseOfHl7Source.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfHl7Source.class); private AtomicInteger count = new AtomicInteger(); private volatile boolean eventArrived; private List receivedEvent; @@ -408,9 +410,11 @@ public void hl7ConsumerTestUnsupportedCharset() { log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 source test with given charset Type is invalid"); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Source.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@source ( type = 'hl7',\n" + @@ -422,8 +426,10 @@ public void hl7ConsumerTestUnsupportedCharset() { "define stream hl7stream (MSH10 string, MSH3HD1 string);\n"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(appender.getMessages().contains("UTF_8 Error while connecting at Source 'hl7'")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("UTF_8 Error while connecting at Source 'hl7'")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test @@ -432,9 +438,11 @@ public void hl7ConsumerTestMessageProcessException() throws InterruptedException log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 source test with unrecognized structure of received message - "); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Hl7ExceptionHandler.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@source ( type = 'hl7',\n" + @@ -476,10 +484,12 @@ public void receive(Event[] events) { stream.send(new Object[]{payLoadER71}); stream.send(new Object[]{payLoadER72}); SiddhiTestHelper.waitForEvents(waitTime, 2, count, timeout); - AssertJUnit.assertTrue(appender.getMessages().contains("Some error occurred while process the message." + + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("Some error occurred while process the message." + " Error message:")); executionPlanRuntime.shutdown(); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test(expectedExceptions = SiddhiAppValidationException.class) @@ -838,9 +848,11 @@ public void hl7ConsumerTestConformanceProfileWithProfileException() throws HL7Ex log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 source to test with conformance profile exception"); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Hl7ReceivingApp.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); receivedEvent = new ArrayList<>(1); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + @@ -894,10 +906,12 @@ public void receive(Event[] events) { AssertJUnit.assertEquals(1, count.get()); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertEquals(expected, receivedEvent); - AssertJUnit.assertTrue(appender.getMessages().contains("The given conformance Profile file is not" + + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("The given conformance Profile file is not" + " supported. Hence, dropping the validation.")); siddhiAppRuntime.shutdown(); executionPlanRuntime.shutdown(); + logger.removeAppender(appender); } @Test diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7SourceForTls.java b/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7SourceForTls.java index 4021a30..70d8f1c 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7SourceForTls.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/source/TestCaseOfHl7SourceForTls.java @@ -27,7 +27,8 @@ import io.siddhi.core.stream.input.InputHandler; import io.siddhi.core.stream.output.StreamCallback; import io.siddhi.extension.io.hl7.util.TestUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -42,7 +43,7 @@ */ public class TestCaseOfHl7SourceForTls { - private static Logger log = Logger.getLogger(TestCaseOfHl7SourceForTls.class); + private static final Logger log = LogManager.getLogger(TestCaseOfHl7SourceForTls.class); private AtomicInteger count = new AtomicInteger(); private volatile boolean eventArrived; private List receivedEvent; diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/util/UnitTestAppender.java b/component/src/test/java/io/siddhi/extension/io/hl7/util/UnitTestAppender.java index 09e9130..5ade3ba 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/util/UnitTestAppender.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/util/UnitTestAppender.java @@ -18,35 +18,52 @@ */ package io.siddhi.extension.io.hl7.util; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.mvel2.util.StringAppender; /** * Util class to read the logs of test cases. */ -public class UnitTestAppender extends AppenderSkeleton { +@Plugin(name = "UnitTestAppender", + category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) +public class UnitTestAppender extends AbstractAppender { - private String messages; + private StringAppender messages = new StringAppender(); - @Override - protected void append(LoggingEvent loggingEvent) { + public UnitTestAppender(String name, Filter filter) { - messages = loggingEvent.getRenderedMessage(); + super(name, filter, null); } - @Override - public void close() { + @PluginFactory + public static UnitTestAppender createAppender( + @PluginAttribute("name") String name, + @PluginElement("Filter") Filter filter) { + return new UnitTestAppender(name, filter); } - @Override - public boolean requiresLayout() { + public String getMessages() { - return false; + String results = messages.toString(); + if (results.isEmpty()) { + return null; + } + return results; } - public String getMessages() { + @Override + public void append(LogEvent event) { - return messages; + messages.append(event.getMessage().getFormattedMessage()); } + } diff --git a/component/src/test/resources/log4j.properties b/component/src/test/resources/log4j.properties deleted file mode 100644 index 6e417da..0000000 --- a/component/src/test/resources/log4j.properties +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. licenses this file to you 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. -# -# For the general syntax of property based configuration files see the -# documenation of org.apache.log4j.PropertyConfigurator. -# The root category uses the appender called A1. Since no priority is -# specified, the root category assumes the default priority for root -# which is DEBUG in log4j. The root category is the only category that -# has a default priority. All other categories need not be assigned a -# priority in which case they inherit their priority from the -# hierarchy. -#log4j.rootLogger=DEBUG, stdout -log4j.rootLogger=INFO, stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%m%n -#log4j.appender.stdout.layout.ConversionPattern1=[%t] %-5p %c %x - %m%n diff --git a/component/src/test/resources/log4j2.xml b/component/src/test/resources/log4j2.xml new file mode 100644 index 0000000..1d83f87 --- /dev/null +++ b/component/src/test/resources/log4j2.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 18b4875..7968485 100644 --- a/pom.xml +++ b/pom.xml @@ -96,8 +96,8 @@ ${hapi.hl7overhttp.version} - org.apache.log4j.wso2 - log4j + org.apache.logging.log4j + log4j-core ${log4j.version} @@ -145,13 +145,13 @@ - 5.1.2 + 5.1.21 [5.0.0,6.0.0) - 1.2.17.wso2v1 + 2.17.1 4.4.15 - 5.0.4 - 2.0.4 - 5.0.3 + 5.2.2-SNAPSHOT + 2.1.1-SNAPSHOT + 5.2.2-SNAPSHOT 0.7.9 6.11 2.2 From 9baddb29f416f653da7e35f5fc300c5609823ee7 Mon Sep 17 00:00:00 2001 From: dnwick Date: Sun, 6 Feb 2022 21:39:05 +0530 Subject: [PATCH 2/3] Fix tests --- .../io/hl7/sink/Hl7SinkTestUtil.java | 5 +- .../io/hl7/sink/TestCaseOfHl7Sink.java | 55 ++++++++++++------- .../io/hl7/sink/TestCaseOfHl7SinkForTls.java | 18 ++++-- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/sink/Hl7SinkTestUtil.java b/component/src/test/java/io/siddhi/extension/io/hl7/sink/Hl7SinkTestUtil.java index 5a40692..ebb13b2 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/sink/Hl7SinkTestUtil.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/sink/Hl7SinkTestUtil.java @@ -28,7 +28,8 @@ import ca.uhn.hl7v2.protocol.ApplicationRouter; import ca.uhn.hl7v2.protocol.ReceivingApplication; import io.siddhi.extension.io.hl7.util.TestUtil; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.ArrayList; @@ -40,7 +41,7 @@ */ public class Hl7SinkTestUtil { - private static final Logger log = Logger.getLogger(Hl7SinkTestUtil.class); + private static final Logger log = LogManager.getLogger(Hl7SinkTestUtil.class); private HapiContext context = new DefaultHapiContext(); private HL7Service hl7Service; private static int count; diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7Sink.java b/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7Sink.java index 258a369..cc3e124 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7Sink.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7Sink.java @@ -26,11 +26,12 @@ import io.siddhi.core.SiddhiAppRuntime; import io.siddhi.core.SiddhiManager; import io.siddhi.core.stream.input.InputHandler; -import io.siddhi.core.stream.output.sink.Sink; import io.siddhi.extension.io.hl7.util.TestUtil; import io.siddhi.extension.io.hl7.util.UnitTestAppender; import io.siddhi.query.api.exception.SiddhiAppValidationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -42,7 +43,7 @@ */ public class TestCaseOfHl7Sink { - private static Logger log = Logger.getLogger(TestCaseOfHl7Sink.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfHl7Sink.class); private volatile int count; private volatile boolean eventArrived; private Hl7SinkTestUtil hl7SinkTestUtil; @@ -466,9 +467,11 @@ public void hl7PublishTestConnectionUnavailable() throws InterruptedException { log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 sink test with a unavailable server."); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Sink.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@sink(type='hl7', " + @@ -480,8 +483,10 @@ public void hl7PublishTestConnectionUnavailable() throws InterruptedException { SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.start(); Thread.sleep(10000); - AssertJUnit.assertTrue(appender.getMessages().contains("Failed to connect with the HL7 server, check")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("Failed to connect with the HL7 server, check")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test(expectedExceptions = SiddhiAppValidationException.class) @@ -511,9 +516,11 @@ public void hl7PublishTestUnSupportCharsetForServer() throws InterruptedExceptio log.info("---------------------------------------------------------------------------------------------"); log.info("Sink test if the client uses multiple-byte-character encoding & server uses single-byte encoding "); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Hl7Sink.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@sink(type='hl7', " + @@ -535,9 +542,11 @@ public void hl7PublishTestUnSupportCharsetForServer() throws InterruptedExceptio } catch (InterruptedException e) { AssertJUnit.fail("interrupted"); } - AssertJUnit.assertTrue(appender.getMessages().contains("Error occurred while processing the message." + + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("Error occurred while processing the message." + " Please check the TestExecutionPlan:hl7stream")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test @@ -604,9 +613,11 @@ public void hl7PublishTestUnsupportedCharset() { log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 Sink test with given charset Type is invalid."); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Sink.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@sink(type='hl7', " + @@ -617,8 +628,10 @@ public void hl7PublishTestUnsupportedCharset() { "define stream hl7stream(payload string);"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(appender.getMessages().contains("UTF_8 Error while connecting at Sink 'hl7'")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("UTF_8, error while connecting at Sink 'hl7'")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test @@ -627,9 +640,11 @@ public void hl7PublishTestUnsupportedHl7Encoding() throws InterruptedException { log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 Sink test with UnSupported Hl7 Encoding - giving text format and preferred as xml"); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Hl7Sink.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@sink(type='hl7', " + @@ -651,9 +666,11 @@ public void hl7PublishTestUnsupportedHl7Encoding() throws InterruptedException { } catch (InterruptedException e) { AssertJUnit.fail("interrupted"); } - AssertJUnit.assertTrue(appender.getMessages().contains("Error occurred while processing the message. Please " + + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("Error occurred while processing the message. Please " + "check the TestExecutionPlan:hl7stream")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test(expectedExceptions = SiddhiAppValidationException.class) diff --git a/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7SinkForTls.java b/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7SinkForTls.java index fe3367e..1913fe1 100644 --- a/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7SinkForTls.java +++ b/component/src/test/java/io/siddhi/extension/io/hl7/sink/TestCaseOfHl7SinkForTls.java @@ -27,7 +27,9 @@ import io.siddhi.core.stream.input.InputHandler; import io.siddhi.extension.io.hl7.util.TestUtil; import io.siddhi.extension.io.hl7.util.UnitTestAppender; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -41,7 +43,7 @@ public class TestCaseOfHl7SinkForTls { private volatile int count; private volatile boolean eventArrived; - private static Logger log = Logger.getLogger(TestCaseOfHl7SinkForTls.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfHl7SinkForTls.class); private PipeParser pipeParser = new PipeParser(); private TestUtil testUtil = new TestUtil(); private Hl7SinkTestUtil hl7SinkTestUtil; @@ -106,9 +108,11 @@ public void hl7PublishTestForTlsSSLHandshakeException() throws InterruptedExcept log.info("---------------------------------------------------------------------------------------------"); log.info("hl7 Sink test with tls Enabled and tls of source not enabled"); log.info("---------------------------------------------------------------------------------------------"); - log = Logger.getLogger(Hl7Sink.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@App:name('TestExecutionPlan')\n" + "@sink(type='hl7', " + @@ -133,9 +137,11 @@ public void hl7PublishTestForTlsSSLHandshakeException() throws InterruptedExcept } catch (InterruptedException e) { AssertJUnit.fail("interrupted"); } - AssertJUnit.assertTrue(appender.getMessages().contains("Interruption occurred while sending the message " + + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages().contains("Interruption occurred while sending the message " + "from stream: TestExecutionPlan:hl7stream")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } @Test From 41b743aab8024a6cb5071a3d09efe0a6142d6a96 Mon Sep 17 00:00:00 2001 From: dnwick Date: Mon, 21 Feb 2022 16:08:06 +0530 Subject: [PATCH 3/3] Upgrade mapper versions and remove unnecessary packaging of jars --- component/pom.xml | 3 --- pom.xml | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/component/pom.xml b/component/pom.xml index 45433b2..933c655 100644 --- a/component/pom.xml +++ b/component/pom.xml @@ -179,9 +179,6 @@ io.siddhi.core.*;version="${siddhi.version.range}", io.siddhi.query.*;version="${siddhi.version.range}" - - ca.uhn.hl7v2.*;version="${hapi.base.version}" - * META-INF=target/classes/META-INF diff --git a/pom.xml b/pom.xml index 7968485..2d79f94 100644 --- a/pom.xml +++ b/pom.xml @@ -149,9 +149,9 @@ [5.0.0,6.0.0) 2.17.1 4.4.15 - 5.2.2-SNAPSHOT - 2.1.1-SNAPSHOT - 5.2.2-SNAPSHOT + 5.2.2 + 2.1.1 + 5.2.2 0.7.9 6.11 2.2