Skip to content

Commit

Permalink
Upgrade Siddhi version to 5.1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
senthuran16 committed Mar 10, 2022
1 parent 723d749 commit 37eb983
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import io.siddhi.extension.io.websocket.sink.util.ResultContainer;
import io.siddhi.extension.io.websocket.sink.util.WebSocketReceiver;
import io.siddhi.extension.io.websocket.util.LoggerAppender;
import io.siddhi.extension.io.websocket.util.LoggerCallback;
import io.siddhi.extension.io.websocket.util.WebSocketServer;
import io.siddhi.query.api.exception.SiddhiAppValidationException;
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.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -100,17 +102,16 @@ public void testWebSocketSinkInvalidUri() throws InterruptedException {
"Define stream BarStream1 (symbol string, price float, volume long);" +
"from FooStream1 select symbol, price, volume insert into BarStream1;");

LoggerCallback loggerCallback = new LoggerCallback(regexPattern) {
@Override
public void receive(String logEventMessage) {
isLogEventArrived = true;
}
};
LoggerAppender.setLoggerCallback(loggerCallback);
LoggerAppender appender = new LoggerAppender("LoggerAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
executionPlanRuntime.start();
Thread.sleep(1000);
Assert.assertEquals(isLogEventArrived, true,
"Matching log event not found for pattern: '" + regexPattern + "'");
Assert.assertTrue(
((LoggerAppender) logger.getAppenders().get("LoggerAppender")).getMessages().contains(regexPattern),
"Matching log event not found for pattern: '" + regexPattern + "'");
executionPlanRuntime.shutdown();
}

Expand All @@ -127,17 +128,16 @@ public void testWebSocketSinkInvalidHeaderFormat() throws InterruptedException {
"Define stream BarStream1 (symbol string, price float, volume long);" +
"from FooStream1 select symbol, price, volume insert into BarStream1;");

LoggerCallback loggerCallback = new LoggerCallback(regexPattern) {
@Override
public void receive(String logEventMessage) {
isLogEventArrived = true;
}
};
LoggerAppender.setLoggerCallback(loggerCallback);
LoggerAppender appender = new LoggerAppender("LoggerAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
executionPlanRuntime.start();
Thread.sleep(1000);
Assert.assertEquals(isLogEventArrived, true,
"Matching log event not found for pattern: '" + regexPattern + "'");
Assert.assertTrue(
((LoggerAppender) logger.getAppenders().get("LoggerAppender")).getMessages().contains(regexPattern),
"Matching log event not found for pattern: '" + regexPattern + "'");
executionPlanRuntime.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import io.siddhi.core.stream.output.StreamCallback;
import io.siddhi.core.util.SiddhiTestHelper;
import io.siddhi.extension.io.websocket.util.LoggerAppender;
import io.siddhi.extension.io.websocket.util.LoggerCallback;
import io.siddhi.extension.io.websocket.util.WebSocketServer;
import io.siddhi.query.api.exception.SiddhiAppValidationException;
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.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
Expand Down Expand Up @@ -182,17 +184,17 @@ public void testWebSocketSourceInvalidUri() throws InterruptedException {
"@map(type='xml'))" +
"Define stream BarStream1 (symbol string, price float, volume long);" +
"from FooStream1 select symbol, price, volume insert into BarStream1;");
LoggerCallback loggerCallback = new LoggerCallback(regexPattern) {
@Override
public void receive(String logEventMessage) {
isLogEventArrived = true;
}
};
LoggerAppender.setLoggerCallback(loggerCallback);

LoggerAppender appender = new LoggerAppender("LoggerAppender", null);
final Logger logger = (Logger) LogManager.getRootLogger();
logger.setLevel(Level.ALL);
logger.addAppender(appender);
appender.start();
executionPlanRuntime.start();
Thread.sleep(1000);
Assert.assertEquals(isLogEventArrived, true,
"Matching log event not found for pattern: '" + regexPattern + "'");
Assert.assertTrue(
((LoggerAppender) logger.getAppenders().get("LoggerAppender")).getMessages().contains(regexPattern),
"Matching log event not found for pattern: '" + regexPattern + "'");
executionPlanRuntime.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@

package io.siddhi.extension.io.websocket.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;

/**
* The custom log4j appender for appending the log event generated while running the tests in TestNG.
Expand All @@ -32,27 +40,33 @@
* To enable the appender, set in the root logger,
* log4j.rootLogger=INFO, stdout, testNG
*/
public class LoggerAppender extends AppenderSkeleton {
private static LoggerCallback loggerCallback;
@Plugin(name = "LoggerAppender",
category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE)
public class LoggerAppender extends AbstractAppender {
private StringAppender messages = new StringAppender();

public static void setLoggerCallback(LoggerCallback loggerCallback) {
LoggerAppender.loggerCallback = loggerCallback;
public LoggerAppender(String name, Filter filter) {
super(name, filter, null);
}

@Override
protected void append(final LoggingEvent event) {
if (loggerCallback != null) {
loggerCallback.receiveLoggerEvent((String) event.getMessage());
}
@PluginFactory
public static LoggerAppender createAppender(
@PluginAttribute("name") String name,
@PluginElement("Filter") Filter filter) {

return new LoggerAppender(name, filter);
}

@Override
public void close() {
loggerCallback = null;
public String getMessages() {
String results = messages.toString();
if (results.isEmpty()) {
return null;
}
return results;
}

@Override
public boolean requiresLayout() {
return true;
public void append(LogEvent event) {
messages.append(event.getMessage().getFormattedMessage());
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</scm>

<properties>
<siddhi.version>5.1.13</siddhi.version>
<siddhi.version>5.1.21</siddhi.version>
<siddhi.version.range>[5.0.0,6.0.0)</siddhi.version.range>
<carbon.feature.plugin.version>3.1.1</carbon.feature.plugin.version>
<maven.surefire.plugin.version>2.12.4</maven.surefire.plugin.version>
Expand Down

0 comments on commit 37eb983

Please sign in to comment.