"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

KafkaAppenderTest.java  (apache-log4j-2.11.1-src):KafkaAppenderTest.java  (apache-log4j-2.11.2-src)
skipping to change at line 140 skipping to change at line 140
@Test @Test
public void testAppendWithKey() throws Exception { public void testAppendWithKey() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKey" ); final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKey" );
final LogEvent logEvent = createLogEvent(); final LogEvent logEvent = createLogEvent();
appender.append(logEvent); appender.append(logEvent);
final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size()); assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0); final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item); assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic()); assertEquals(TOPIC_NAME, item.topic());
String msgKey = item.key().toString(); final String msgKey = item.key().toString();
byte[] keyValue = "key".getBytes(StandardCharsets.UTF_8); final byte[] keyValue = "key".getBytes(StandardCharsets.UTF_8);
assertArrayEquals(item.key(), keyValue); assertArrayEquals(item.key(), keyValue);
assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_ 8)); assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_ 8));
} }
@Test @Test
public void testAppendWithKeyLookup() throws Exception { public void testAppendWithKeyLookup() throws Exception {
final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKeyL ookup"); final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithKeyL ookup");
final LogEvent logEvent = createLogEvent(); final LogEvent logEvent = createLogEvent();
Date date = new Date(); final Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy"); final SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
appender.append(logEvent); appender.append(logEvent);
final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); final List<ProducerRecord<byte[], byte[]>> history = kafka.history();
assertEquals(1, history.size()); assertEquals(1, history.size());
final ProducerRecord<byte[], byte[]> item = history.get(0); final ProducerRecord<byte[], byte[]> item = history.get(0);
assertNotNull(item); assertNotNull(item);
assertEquals(TOPIC_NAME, item.topic()); assertEquals(TOPIC_NAME, item.topic());
byte[] keyValue = format.format(date).getBytes(StandardCharsets.UTF_8); final byte[] keyValue = format.format(date).getBytes(StandardCharsets.UT F_8);
assertArrayEquals(item.key(), keyValue); assertArrayEquals(item.key(), keyValue);
assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_ 8)); assertEquals(LOG_MESSAGE, new String(item.value(), StandardCharsets.UTF_ 8));
} }
private LogEvent deserializeLogEvent(final byte[] data) throws IOException, ClassNotFoundException { private LogEvent deserializeLogEvent(final byte[] data) throws IOException, ClassNotFoundException {
final ByteArrayInputStream bis = new ByteArrayInputStream(data); final ByteArrayInputStream bis = new ByteArrayInputStream(data);
try (ObjectInput ois = new FilteredObjectInputStream(bis)) { try (ObjectInput ois = new FilteredObjectInputStream(bis)) {
return (LogEvent) ois.readObject(); return (LogEvent) ois.readObject();
} }
} }
 End of changes. 3 change blocks. 
5 lines changed or deleted 5 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)