Repository: logging-log4j2 Updated Branches: refs/heads/master 2bf4ed22a -> f2ddaf93a
[LOG4J2-2013] SslSocketManager does not apply SSLContext on TCP reconnect. Add disabled test that shows the issue. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f2ddaf93 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f2ddaf93 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f2ddaf93 Branch: refs/heads/master Commit: f2ddaf93aeee3101cd95ba61d13c79bcec112b48 Parents: 2bf4ed2 Author: Gary Gregory <[email protected]> Authored: Tue Aug 15 17:11:14 2017 -0600 Committer: Gary Gregory <[email protected]> Committed: Tue Aug 15 17:11:14 2017 -0600 ---------------------------------------------------------------------- .../SecureSocketAppenderConnectReConnectIT.java | 117 +++++++++++++++++++ 1 file changed, 117 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f2ddaf93/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectReConnectIT.java ---------------------------------------------------------------------- diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectReConnectIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectReConnectIT.java new file mode 100644 index 0000000..97499b7 --- /dev/null +++ b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectReConnectIT.java @@ -0,0 +1,117 @@ +/* + * 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.net; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.logging.log4j.core.appender.SocketAppender; +import org.apache.logging.log4j.core.layout.JsonLayout; +import org.apache.logging.log4j.core.net.ssl.SslConfiguration; +import org.apache.logging.log4j.core.net.ssl.SslConfigurationTest; +import org.apache.logging.log4j.core.net.ssl.StoreConfigurationException; +import org.apache.logging.log4j.server.SecureTcpSocketServer; +import org.apache.logging.log4j.server.TcpSocketServer; +import org.apache.logging.log4j.test.AvailablePortFinder; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests that a Secure Socket Appender can reconnect to a server after it has been recycled. + * <p> + * LOG4J2-2013 SslSocketManager does not apply SSLContext on TCP reconnect. + * </p> + * <p> + * LOG4J2-1311 SocketAppender will lost first several logs after re-connection to log servers. + * </p> + * <p> + * See also LOG4J2-1934 JMS Appender does not know how to recover from a broken connection. See + * https://issues.apache.org/jira/browse/LOG4J2-1934 + * </p> + * <p> + * This test class' single test method performs the following: + * </p> + * <ol> + * <li>Starts Apache Socket Server</li> + * <li>Starts a Socket Appender</li> + * <li>Logs an event OK</li> + * <li>Stops Apache Socket Server</li> + * <li>Starts Apache Socket Server</li> + * <li>Logs an event</li> + * </ol> + */ +public class SecureSocketAppenderConnectReConnectIT extends AbstractSocketAppenderReconnectIT { + + private SslConfiguration sslConfiguration; + + @Before + public void initServerSocketFactory() throws StoreConfigurationException { + sslConfiguration = SslConfigurationTest.createTestSslConfigurationResources(); + } + + @Test + @Ignore + public void testConnectReConnect() throws Exception { + port = AvailablePortFinder.getNextAvailable(); + // Start server + server = TcpSocketServer.createJsonSocketServer(port); + startServer(200); + // Start appender + // @formatter:off + appender = SocketAppender.newBuilder() + .withPort(port) + .withReconnectDelayMillis(1000) + .withName("test") + .withLayout(JsonLayout.newBuilder().build()) + .withSslConfiguration(sslConfiguration) + .build(); + // @formatter:on + appender.start(); + // Log message + appendEvent(appender); + // Stop server + shutdown(); + // I should not be able to connect to the server now + try { + try (Socket socket = new Socket("localhost", port)) { + Assert.fail("The server socket should not be opened: " + socket); + } + } catch (final IOException e) { + // expected + } + // HACK START - Gary + // SANS HACK, the test passes, as somehow the socket in the appender is still valid + // On Windows 10, I did not try other OSs: + // HERE, I BREAKPOINT AND GO TO THE OS AND FORCE THE TCP CONNECTION TO CLOSE (TcpView.exe)), SUCH THAT + // INTERNALLY THE MANAGER GETS: + // java.net.SocketException: Connection reset by peer: socket write error + // HACK END + // + // Restart server on the SAME port + server = SecureTcpSocketServer.createJsonServer(port, sslConfiguration); + thread = startServer(0); + try (Socket socket = new Socket("localhost", port)) { + Assert.assertTrue(socket.isBound()); + Assert.assertFalse(socket.isClosed()); + } + // Logging again should cause the appender to reconnect + appendEvent(appender); + } + +}
