Test [LOG4J2-1558] SocketAppender should support IO buffering. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/eeff0c59 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/eeff0c59 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/eeff0c59
Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext Commit: eeff0c59e50e287e5aec32c31ae726cf8993d4bd Parents: 6323258 Author: ggregory <ggreg...@apache.org> Authored: Fri Sep 2 15:11:09 2016 -0700 Committer: ggregory <ggreg...@apache.org> Committed: Fri Sep 2 15:11:09 2016 -0700 ---------------------------------------------------------------------- .../appender/SocketAppenderBufferSizeTest.java | 77 ++++++++++++++++++++ log4j-core/src/test/resources/log4j-empty.xml | 20 +++++ 2 files changed, 97 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eeff0c59/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderBufferSizeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderBufferSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderBufferSizeTest.java new file mode 100644 index 0000000..9d0c9bf --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderBufferSizeTest.java @@ -0,0 +1,77 @@ +/* + * 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; + +import org.apache.logging.log4j.ThreadContext; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.SocketAppenderTest.TcpSocketTestServer; +import org.apache.logging.log4j.core.util.Constants; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.AvailablePortFinder; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * + */ +public class SocketAppenderBufferSizeTest { + + private TcpSocketTestServer tcpServer; + + private LoggerContext loggerContext; + private Logger logger; + + @Rule + public LoggerContextRule loggerContextRule = new LoggerContextRule("log4j-empty.xml"); + + @Before + public void setup() throws Exception { + tcpServer = new TcpSocketTestServer(AvailablePortFinder.getNextAvailable()); + tcpServer.start(); + ThreadContext.clearAll(); + loggerContext = loggerContextRule.getLoggerContext(); + logger = loggerContext.getLogger(SocketAppenderBufferSizeTest.class.getName()); + } + + @After + public void teardown() { + tcpServer.shutdown(); + loggerContext = null; + logger = null; + tcpServer.reset(); + ThreadContext.clearAll(); + } + + @Test + public void testTcpAppenderDefaultBufferSize() throws Exception { + SocketAppenderTest.testTcpAppender(tcpServer, logger, Constants.ENCODER_BYTE_BUFFER_SIZE); + } + + @Test + public void testTcpAppenderLargeBufferSize() throws Exception { + SocketAppenderTest.testTcpAppender(tcpServer, logger, Constants.ENCODER_BYTE_BUFFER_SIZE * 100); + } + + @Test + public void testTcpAppenderSmallestBufferSize() throws Exception { + SocketAppenderTest.testTcpAppender(tcpServer, logger, 1); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/eeff0c59/log4j-core/src/test/resources/log4j-empty.xml ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/resources/log4j-empty.xml b/log4j-core/src/test/resources/log4j-empty.xml new file mode 100644 index 0000000..f528061 --- /dev/null +++ b/log4j-core/src/test/resources/log4j-empty.xml @@ -0,0 +1,20 @@ +<?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 status="INFO" name="TestEmpty"> +</Configuration>