You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2018/01/25 21:04:20 UTC
logging-log4j2 git commit: Fix KafkaAppender tests
Repository: logging-log4j2
Updated Branches:
refs/heads/master 8f53bd9cf -> e7f3c8c4f
Fix KafkaAppender tests
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e7f3c8c4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e7f3c8c4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e7f3c8c4
Branch: refs/heads/master
Commit: e7f3c8c4f48538efbf3729334fa6253275d1cc64
Parents: 8f53bd9
Author: Mikael Ståldal <mi...@staldal.nu>
Authored: Thu Jan 25 22:04:12 2018 +0100
Committer: Mikael Ståldal <mi...@staldal.nu>
Committed: Thu Jan 25 22:04:12 2018 +0100
----------------------------------------------------------------------
.../kafka/KafkaAppenderCloseTimeoutTest.java | 78 ++++++++++++++++++++
.../appender/mom/kafka/KafkaAppenderTest.java | 10 ---
.../resources/KafkaAppenderCloseTimeoutTest.xml | 31 ++++++++
3 files changed, 109 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e7f3c8c4/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderCloseTimeoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderCloseTimeoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderCloseTimeoutTest.java
new file mode 100644
index 0000000..a8d3566
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderCloseTimeoutTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+package org.apache.logging.log4j.core.appender.mom.kafka;
+
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.kafka.clients.producer.MockProducer;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.logging.log4j.categories.Appenders;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(Appenders.Kafka.class)
+public class KafkaAppenderCloseTimeoutTest {
+
+ private static final MockProducer<byte[], byte[]> kafka = new MockProducer<byte[], byte[]>(true, null, null) {
+ @Override
+ public void close() {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException ignore) {
+ }
+ }
+
+ @Override
+ public void close(long timeout, TimeUnit timeUnit) {
+ try {
+ Thread.sleep(timeUnit.toMillis(timeout));
+ } catch (InterruptedException ignore) {
+ }
+ }
+ };
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ KafkaManager.producerFactory = new KafkaProducerFactory() {
+ @Override
+ public Producer<byte[], byte[]> newKafkaProducer(final Properties config) {
+ return kafka;
+ }
+ };
+ }
+
+ @Rule
+ public LoggerContextRule ctx = new LoggerContextRule("KafkaAppenderCloseTimeoutTest.xml");
+
+ @Before
+ public void setUp() throws Exception {
+ kafka.clear();
+ }
+
+ @Test(timeout = 2000)
+ public void testClose() throws Exception {
+ final Appender appender = ctx.getRequiredAppender("KafkaAppender");
+ appender.stop();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e7f3c8c4/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java
index 0c718b3..613bd74 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java
@@ -53,11 +53,6 @@ public class KafkaAppenderTest {
@Override
public void close(final long timeout, final TimeUnit timeUnit) {
- try {
- Thread.sleep(50);
- } catch (final InterruptedException ignore) {
- // ignore
- }
}
};
@@ -173,9 +168,4 @@ public class KafkaAppenderTest {
}
}
- @Test(timeout = 2000)
- public void testClose() throws Exception {
- final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithLayout");
- appender.stop();
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e7f3c8c4/log4j-core/src/test/resources/KafkaAppenderCloseTimeoutTest.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/KafkaAppenderCloseTimeoutTest.xml b/log4j-core/src/test/resources/KafkaAppenderCloseTimeoutTest.xml
new file mode 100644
index 0000000..e58cb17
--- /dev/null
+++ b/log4j-core/src/test/resources/KafkaAppenderCloseTimeoutTest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF 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.
+ -->
+<Configuration name="KafkaAppenderCloseTimeoutTest" status="OFF">
+ <Appenders>
+ <Kafka name="KafkaAppender" topic="kafka-topic">
+ <PatternLayout pattern="[%m]"/>
+ <Property name="bootstrap.servers">localhost:9092</Property>
+ <Property name="timeout.ms">1000</Property>
+ </Kafka>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="KafkaAppender"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file