You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2017/08/26 20:53:55 UTC
[37/50] logging-log4j2 git commit: Move test classes dependent on
log4j-server to that project
Move test classes dependent on log4j-server to that project
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bf3a76d8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bf3a76d8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bf3a76d8
Branch: refs/heads/LOG4J2-1431
Commit: bf3a76d8e208f75d4fa12ffb5da22c327cbfb8b8
Parents: 55fbb07
Author: Ralph Goers <rg...@nextiva.com>
Authored: Sat Aug 26 12:12:48 2017 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Sat Aug 26 12:12:48 2017 -0700
----------------------------------------------------------------------
log4j-core-its/pom.xml | 13 --
.../mom/activemq/AbstractJmsAppenderIT.java | 183 -------------------
.../AbstractJmsAppenderReconnectIT.java | 98 ----------
.../JmsAppenderConnectPostStartupIT.java | 75 --------
.../activemq/JmsAppenderConnectReConnectIT.java | 71 -------
.../activemq/JmsAppenderITcpConnectionIT.java | 77 --------
.../activemq/JmsAppenderIVmConnectionIT.java | 59 ------
.../mom/activemq/JmsClientTestConfig.java | 112 ------------
.../mom/activemq/JmsClientTestConfigRule.java | 105 -----------
.../net/AbstractSocketAppenderReconnectIT.java | 102 -----------
...ecureSocketAppenderConnectPostStartupIT.java | 93 ----------
.../SecureSocketAppenderConnectReConnectIT.java | 120 ------------
.../net/SocketAppenderConnectPostStartupIT.java | 81 --------
.../net/SocketAppenderConnectReConnectIT.java | 99 ----------
14 files changed, 1288 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core-its/pom.xml b/log4j-core-its/pom.xml
index 74b94e9..fe70cfa 100644
--- a/log4j-core-its/pom.xml
+++ b/log4j-core-its/pom.xml
@@ -49,19 +49,6 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-server</artifactId>
- <version>2.9-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-server</artifactId>
- <version>2.9-SNAPSHOT</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderIT.java
deleted file mode 100644
index 13d6830..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderIT.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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.activemq;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.ObjectMessage;
-import javax.jms.TextMessage;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.appender.mom.JmsAppender;
-import org.apache.logging.log4j.core.appender.mom.JmsManager;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.layout.JsonLayout;
-import org.apache.logging.log4j.core.layout.MessageLayout;
-import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.message.StringMapMessage;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Abstracts services for integration test for the JmsAppender using an embedded
- * ActiveMQ broker. The client (appender) is set up once for the whole class.
- * Subclasses decide whether the broker is reinitialized for each test method.
- * This allows to test the ability of the JmsAppender to reconnect.
- *
- * The subclasses cannot be run in parallel.
- */
-public abstract class AbstractJmsAppenderIT {
-
- static class JmsQueueConsumer implements MessageListener {
-
- private final CountDownLatch countDownLatch;
- private final Collection<Object> events;
- private final Class<? extends Message> messageClass;
- private final int messageCount;
-
- JmsQueueConsumer(final int messageCount, final Class<? extends Message> messageClass) {
- this.messageCount = messageCount;
- this.messageClass = messageClass;
- this.countDownLatch = new CountDownLatch(messageCount);
- this.events = new ArrayList<>(messageCount);
- }
-
- public void awaitAndAssertAllMessagesConsumed() throws InterruptedException {
- countDownLatch.await(5, TimeUnit.SECONDS);
- assertEquals(messageCount, events.size());
- }
-
- @Override
- public void onMessage(final Message message) {
- try {
- try {
- final Object event;
- Assert.assertTrue(String.format("Expected type '%s' to be an instance of %s", message.getClass(),
- messageClass), messageClass.isAssignableFrom(message.getClass()));
- if (message instanceof ObjectMessage) {
- event = ((ObjectMessage) message).getObject();
- } else if (message instanceof javax.jms.MapMessage) {
- event = message;
- } else if (message instanceof javax.jms.TextMessage) {
- event = message;
- } else {
- Assert.fail("Unexpected Message type: " + message);
- event = null;
- }
- events.add(event);
- } finally {
- countDownLatch.countDown();
- }
- } catch (final JMSException e) {
- e.printStackTrace();
- }
- }
- }
-
- static final String KEY_SERIALIZABLE_PACKAGES = "org.apache.activemq.SERIALIZABLE_PACKAGES";
-
- private final JmsClientTestConfigRule jmsTestConfigRule;
-
- public AbstractJmsAppenderIT(final JmsClientTestConfigRule jmsTestConfigRule) {
- this.jmsTestConfigRule = jmsTestConfigRule;
- }
-
- protected JmsAppender getJmsAppender() {
- return getJmsTestConfig().getJmsAppender();
- }
-
- protected JmsManager getJmsManager() {
- return getJmsTestConfig().getJmsManager();
- }
-
- private JmsClientTestConfig getJmsTestConfig() {
- return jmsTestConfigRule.getJmsClientTestConfig();
- }
-
- @Test
- public void testLogMapMessageToQueue() throws Exception {
- getJmsTestConfig().createAppender(MessageLayout.createLayout());
- final int messageCount = 100;
- final MessageConsumer messageConsumer = getJmsManager().createMessageConsumer();
- try {
- final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount, javax.jms.MapMessage.class);
- messageConsumer.setMessageListener(consumer);
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- for (int i = 0; i < messageCount; i++) {
- final Map<String, String> map = new HashMap<>();
- map.put("messageText", messageText);
- map.put("threadName", Thread.currentThread().getName());
- // @formatter:off
- final LogEvent event = Log4jLogEvent.newBuilder()
- .setLoggerName(loggerName)
- .setLoggerFqcn(loggerName)
- .setLevel(Level.INFO)
- .setMessage(new StringMapMessage(map))
- .setTimeMillis(System.currentTimeMillis())
- .build();
- // @formatter:on
- getJmsAppender().append(event);
- }
- consumer.awaitAndAssertAllMessagesConsumed();
- } finally {
- messageConsumer.close();
- }
- }
-
- @Test
- public void testLogObjectMessageToQueue() throws Exception {
- getJmsTestConfig().createAppender(JsonLayout.createDefaultLayout());
- final int messageCount = 100;
- final MessageConsumer messageConsumer = getJmsManager().createMessageConsumer();
- try {
- final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount, TextMessage.class);
- messageConsumer.setMessageListener(consumer);
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- for (int i = 0; i < messageCount; i++) {
- // @formatter:off
- final LogEvent event = Log4jLogEvent.newBuilder()
- .setLoggerName(loggerName)
- .setLoggerFqcn(loggerName)
- .setLevel(Level.INFO)
- .setMessage(new SimpleMessage(messageText))
- .setThreadName(Thread.currentThread().getName())
- .setTimeMillis(System.currentTimeMillis())
- .build();
- // @formatter:on
- getJmsAppender().append(event);
- }
- consumer.awaitAndAssertAllMessagesConsumed();
- } finally {
- messageConsumer.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderReconnectIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderReconnectIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderReconnectIT.java
deleted file mode 100644
index ce4745d..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/AbstractJmsAppenderReconnectIT.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.activemq;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.activemq.broker.BrokerService;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.mom.JmsAppender;
-import org.apache.logging.log4j.core.appender.mom.JmsManager;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.message.StringMapMessage;
-import org.apache.logging.log4j.server.mom.activemq.ActiveMqBrokerServiceHelper;
-import org.junit.After;
-import org.junit.Assert;
-
-/**
- * Subclass for tests that reconnect to Apache Active MQ. The class makes sure resources are properly shutdown after
- * each @Test method. A subclass normally only has one @Test method.
- * <p>
- * LOG4J2-1934 JMS Appender does not know how to recover from a broken connection. See
- * https://issues.apache.org/jira/browse/LOG4J2-1934
- * </p>
- */
-public class AbstractJmsAppenderReconnectIT {
-
- protected JmsClientTestConfig jmsClientTestConfig;
- protected JmsAppender appender;
- protected BrokerService brokerService;
-
- @After
- public void after() {
- try {
- ActiveMqBrokerServiceHelper.stopBrokerService(brokerService);
- } catch (final Exception e) {
- // Just log to the console for now.
- e.printStackTrace();
- }
- if (appender != null) {
- appender.stop();
- }
- if (jmsClientTestConfig != null) {
- jmsClientTestConfig.stop();
- }
- if (appender != null) {
- // Make sure the manager is gone as to not have bad side effect on other tests.
- @SuppressWarnings("resource")
- final JmsManager appenderManager = appender.getManager();
- if (appenderManager != null) {
- Assert.assertFalse(AbstractManager.hasManager(appenderManager.getName()));
- }
- }
- if (jmsClientTestConfig != null) {
- // Make sure the manager is gone as to not have bad side effect on other tests.
- @SuppressWarnings("resource")
- final JmsManager testManager = jmsClientTestConfig.getJmsManager();
- if (testManager != null) {
- Assert.assertFalse(AbstractManager.hasManager(testManager.getName()));
- }
- }
- }
-
- protected void appendEvent(final JmsAppender appender) {
- final Map<String, String> map = new HashMap<>();
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- map.put("messageText", messageText);
- map.put("threadName", Thread.currentThread().getName());
- // @formatter:off
- final LogEvent event = Log4jLogEvent.newBuilder()
- .setLoggerName(loggerName)
- .setLoggerFqcn(loggerName)
- .setLevel(Level.INFO)
- .setMessage(new StringMapMessage(map))
- .setTimeMillis(System.currentTimeMillis())
- .build();
- // @formatter:on
- appender.append(event);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectPostStartupIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectPostStartupIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectPostStartupIT.java
deleted file mode 100644
index 2c0af65..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectPostStartupIT.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.activemq;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.core.layout.MessageLayout;
-import org.apache.logging.log4j.server.mom.activemq.ActiveMqBrokerServiceHelper;
-import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-/**
- * Tests that a JMS Appender start when there is no broker and connect the broker when it is started later..
- * <p>
- * 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 a JMS Appender</li>
- * <li>Logs an event (fails and starts the reconnect thread)</li>
- * <li>Starts Apache ActiveMQ</li>
- * <li>Logs an event successfully</li>
- * </ol>
- */
-@Category(Appenders.Jms.class)
-public class JmsAppenderConnectPostStartupIT extends AbstractJmsAppenderReconnectIT {
-
- @Test
- public void testConnectPostStartup() throws Exception {
- //
- // Start appender
- final int port = AvailablePortFinder.getNextAvailable();
- final String brokerUrlString = "tcp://localhost:" + port;
- jmsClientTestConfig = new JmsClientTestConfig(ActiveMQInitialContextFactory.class.getName(), brokerUrlString,
- "admin", "admin".toCharArray());
- jmsClientTestConfig.start();
- appender = jmsClientTestConfig.createAppender(MessageLayout.createLayout());
- //
- // Logging will fail but the JMS manager is now running a reconnect thread.
- try {
- appendEvent(appender);
- Assert.fail("Expected to catch a " + AppenderLoggingException.class.getName());
- } catch (final AppenderLoggingException e) {
- // Expected.
- }
- //
- // Start broker
- brokerService = ActiveMqBrokerServiceHelper.startBrokerService(JmsAppenderConnectPostStartupIT.class.getName(),
- brokerUrlString, port);
- //
- // Logging now should just work
- Thread.sleep(appender.getManager().getJmsManagerConfiguration().getReconnectIntervalMillis());
- appendEvent(appender);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectReConnectIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectReConnectIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectReConnectIT.java
deleted file mode 100644
index ac3426f..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderConnectReConnectIT.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.activemq;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.core.layout.MessageLayout;
-import org.apache.logging.log4j.server.mom.activemq.ActiveMqBrokerServiceHelper;
-import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-/**
- * Tests that a JMS Appender can reconnect to a JMS broker after it has been recycled.
- * <p>
- * 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 ActiveMQ</li>
- * <li>Starts a JMS Appender</li>
- * <li>Logs an event</li>
- * <li>Stops Apache ActiveMQ</li>
- * <li>Starts Apache ActiveMQ</li>
- * <li>Logs an event</li>
- * </ol>
- */
-@Category(Appenders.Jms.class)
-public class JmsAppenderConnectReConnectIT extends AbstractJmsAppenderReconnectIT {
-
- @Test
- public void testConnectReConnect() throws Exception {
- // Start broker
- final int port = AvailablePortFinder.getNextAvailable();
- final String brokerUrlString = "tcp://localhost:" + port;
- brokerService = ActiveMqBrokerServiceHelper.startBrokerService(JmsAppenderConnectReConnectIT.class.getName(),
- brokerUrlString, port);
- // Start appender
- jmsClientTestConfig = new JmsClientTestConfig(ActiveMQInitialContextFactory.class.getName(), brokerUrlString,
- "admin", "admin".toCharArray());
- jmsClientTestConfig.start();
- appender = jmsClientTestConfig.createAppender(MessageLayout.createLayout());
- // Log message
- appendEvent(appender);
- // Stop broker
- ActiveMqBrokerServiceHelper.stopBrokerService(brokerService);
- // Restart broker
- brokerService = ActiveMqBrokerServiceHelper.startBrokerService(JmsAppenderConnectReConnectIT.class.getName(),
- brokerUrlString, port);
- // Logging again should cause the appender to reconnect
- appendEvent(appender);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderITcpConnectionIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderITcpConnectionIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderITcpConnectionIT.java
deleted file mode 100644
index cc913cf..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderITcpConnectionIT.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.activemq;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-import org.apache.logging.log4j.categories.Appenders;
-import org.apache.logging.log4j.server.mom.activemq.ActiveMqBrokerServiceRule;
-import org.apache.logging.log4j.test.AvailablePortSystemPropertyRule;
-import org.apache.logging.log4j.test.RuleChainFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.RuleChain;
-
-/**
- * Integration test for JmsAppender using an embedded ActiveMQ broker with in
- * socket communications between clients and broker. This test manages a client
- * connection to JMS like an Appender would. This test appender is managed at
- * the class level by a JmsTestConfigRule.
- * <p>
- * The test manages an Apache ActiveMQ broken embedded in this test. A new
- * broker is started and stopped for each test method on the same port, which
- * means that the JMS Appender needs to reconnect to JMS for the second test
- * run, which ever that test maybe.
- * </p>
- */
-@Category(Appenders.Jms.class)
-public class JmsAppenderITcpConnectionIT extends AbstractJmsAppenderIT {
-
- public static final AvailablePortSystemPropertyRule portRule = AvailablePortSystemPropertyRule
- .create(ActiveMqBrokerServiceRule.PORT_PROPERTY_NAME);
-
- public static final ActiveMqBrokerServiceRule activeMqBrokerServiceRule = new ActiveMqBrokerServiceRule(
- JmsAppenderITcpConnectionIT.class.getName(), portRule.getName());
-
- // "admin"/"admin" are the default Apache Active MQ creds.
- public static final JmsClientTestConfigRule jmsClientTestConfigRule = new JmsClientTestConfigRule(
- activeMqBrokerServiceRule, ActiveMQInitialContextFactory.class.getName(), "admin", "admin".toCharArray());
-
- /**
- * We assign a port only ONCE ands start the broker ONCE for the whole test
- * suite.
- */
- @ClassRule
- public static final RuleChain ruleChain = RuleChainFactory.create(portRule, activeMqBrokerServiceRule,
- jmsClientTestConfigRule);
-
- @AfterClass
- public static void afterClass() {
- jmsClientTestConfigRule.getJmsClientTestConfig().stop();
- }
-
- @BeforeClass
- public static void beforeClass() {
- jmsClientTestConfigRule.getJmsClientTestConfig().start();
- }
-
- public JmsAppenderITcpConnectionIT() {
- super(jmsClientTestConfigRule);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderIVmConnectionIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderIVmConnectionIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderIVmConnectionIT.java
deleted file mode 100644
index 0178ea3..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsAppenderIVmConnectionIT.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.activemq;
-
-import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
-import org.apache.logging.log4j.categories.Appenders;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
-
-/**
- * Integration test for JmsAppender using an embedded ActiveMQ broker with in
- * direct VM communication between clients and broker.
- * <p>
- * This test manages a client connection to JMS like an Appender would. This
- * test appender is managed at the class level by a JmsTestConfigRule.
- * </p>
- * <p>
- * This test does not manage an Apache ActiveMQ broker explicitly, rather it
- * lets ActiveMQ use its "vm" protocol.
- * </p>
- */
-@Category(Appenders.Jms.class)
-public class JmsAppenderIVmConnectionIT extends AbstractJmsAppenderIT {
-
- @ClassRule
- public static final JmsClientTestConfigRule jmsClientTestConfigRule = new JmsClientTestConfigRule(
- ActiveMQInitialContextFactory.class.getName(), "vm://localhost?broker.persistent=false", null, null);
-
- @AfterClass
- public static void afterClass() {
- jmsClientTestConfigRule.getJmsClientTestConfig().stop();
- }
-
- @BeforeClass
- public static void beforeClass() {
- jmsClientTestConfigRule.getJmsClientTestConfig().start();
- }
-
- public JmsAppenderIVmConnectionIT() {
- super(jmsClientTestConfigRule);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfig.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfig.java
deleted file mode 100644
index 26c57ed..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfig.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.activemq;
-
-import java.util.Properties;
-
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.appender.mom.JmsAppender;
-import org.apache.logging.log4j.core.appender.mom.JmsManager;
-import org.apache.logging.log4j.core.net.JndiManager;
-
-/**
- * All the JMS information and state needed to configure and get a test going.
- */
-class JmsClientTestConfig {
-
- private JmsAppender jmsAppender;
- private final String jmsInitialContextFactoryClassName;
- private JmsManager jmsManager;
- private final char[] jmsPassword;
- private final String jmsProviderUrlStr;
- private final String jmsUserName;
-
- JmsClientTestConfig(final String jmsInitialContextFactoryClassName, final String jmsProviderUrlStr,
- final String jmsUserName, final char[] jmsPassword) {
- this.jmsInitialContextFactoryClassName = jmsInitialContextFactoryClassName;
- this.jmsProviderUrlStr = jmsProviderUrlStr;
- this.jmsUserName = jmsUserName;
- this.jmsPassword = jmsPassword;
- }
-
- JmsAppender createAppender(final Layout<?> layout) {
- // @formatter:off
- jmsAppender = JmsAppender.newBuilder()
- .setName("JmsAppender")
- .setLayout(layout)
- .setIgnoreExceptions(true)
- .setJmsManager(jmsManager)
- .setReconnectIntervalMillis(2000)
- .build();
- // @formatter:on
- jmsAppender.start();
- return jmsAppender;
- }
-
- JmsAppender getJmsAppender() {
- return jmsAppender;
- }
-
- String getJmsInitialContextFactoryClassName() {
- return jmsInitialContextFactoryClassName;
- }
-
- JmsManager getJmsManager() {
- return jmsManager;
- }
-
- char[] getJmsPassword() {
- return jmsPassword;
- }
-
- String getJmsProviderUrlStr() {
- return jmsProviderUrlStr;
- }
-
- String getJmsUserName() {
- return jmsUserName;
- }
-
- void setJmsAppender(final JmsAppender jmsAppender) {
- this.jmsAppender = jmsAppender;
- }
-
- void setJmsManager(final JmsManager jmsManager) {
- this.jmsManager = jmsManager;
- }
-
- void start() {
- System.setProperty(AbstractJmsAppenderIT.KEY_SERIALIZABLE_PACKAGES,
- "org.apache.logging.log4j.core.impl,org.apache.logging.log4j.util,org.apache.logging.log4j,java.rmi");
- final Properties additional = new Properties();
- additional.setProperty("queue.TestQueue", "TestQueue");
- // jndiManager is closed in stop() through the jmsManager
- final Properties jndiProperties = JndiManager.createProperties(jmsInitialContextFactoryClassName,
- jmsProviderUrlStr, null, null, null, additional);
- final String name = JmsManager.class.getName() + "-" + getClass().getSimpleName() + "@" + hashCode();
- jmsManager = JmsManager.getJmsManager(name, jndiProperties, "ConnectionFactory", "TestQueue", jmsUserName,
- jmsPassword, false, JmsAppender.Builder.DEFAULT_RECONNECT_INTERVAL_MILLIS);
- }
-
- void stop() {
- if (jmsManager != null) {
- jmsManager.close();
- jmsManager = null;
- }
- System.getProperties().remove(AbstractJmsAppenderIT.KEY_SERIALIZABLE_PACKAGES);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfigRule.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfigRule.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfigRule.java
deleted file mode 100644
index b68403b..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/mom/activemq/JmsClientTestConfigRule.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.activemq;
-
-import org.apache.logging.log4j.server.mom.activemq.ActiveMqBrokerServiceRule;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * A JUnit {@link TestRule} that builds a JmsTestConfig by getting a JMS broker
- * URL string from either a ActiveMqBrokerServiceRule or the one it was given in
- * the constructor.
- */
-class JmsClientTestConfigRule implements TestRule {
-
- final ActiveMqBrokerServiceRule activeMqBrokerServiceRule;
- final String brokerUrlStr;
- private JmsClientTestConfig jmsClientTestConfig;
- final String jmsInitialContextFactoryClassName;
- final char[] password;
- final String userName;
-
- public JmsClientTestConfigRule(final ActiveMqBrokerServiceRule activeMqBrokerServiceRule,
- final String jmsInitialContextFactoryClassName, final String userName, final char[] password) {
- this.activeMqBrokerServiceRule = activeMqBrokerServiceRule;
- this.jmsInitialContextFactoryClassName = jmsInitialContextFactoryClassName;
- this.brokerUrlStr = null;
- this.userName = userName;
- this.password = password;
- }
-
- public JmsClientTestConfigRule(final String jmsInitialContextFactoryClassName, final String brokerUrlStr, final String userName,
- final char[] password) {
- this.activeMqBrokerServiceRule = null;
- this.jmsInitialContextFactoryClassName = jmsInitialContextFactoryClassName;
- this.brokerUrlStr = brokerUrlStr;
- this.userName = userName;
- this.password = password;
- }
-
- @Override
- public Statement apply(final Statement base, final Description description) {
- return new Statement() {
-
- @Override
- public void evaluate() throws Throwable {
- jmsClientTestConfig = new JmsClientTestConfig(jmsInitialContextFactoryClassName, getBrokerUrlString(),
- userName, password);
- try {
- base.evaluate();
- } finally {
- // no tear down.
- }
- }
-
- private String getBrokerUrlString() {
- return brokerUrlStr != null ? brokerUrlStr : activeMqBrokerServiceRule.getBrokerUrlString();
- }
- };
- }
-
- ActiveMqBrokerServiceRule getActiveMqBrokerServiceRule() {
- return activeMqBrokerServiceRule;
- }
-
- String getBrokerUrlStr() {
- return brokerUrlStr;
- }
-
- JmsClientTestConfig getJmsClientTestConfig() {
- return jmsClientTestConfig;
- }
-
- String getJmsInitialContextFactoryClassName() {
- return jmsInitialContextFactoryClassName;
- }
-
- char[] getPassword() {
- return password;
- }
-
- String getUserName() {
- return userName;
- }
-
- void setJmsClientTestConfig(final JmsClientTestConfig jmsClientTestConfig) {
- this.jmsClientTestConfig = jmsClientTestConfig;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/AbstractSocketAppenderReconnectIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/AbstractSocketAppenderReconnectIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/AbstractSocketAppenderReconnectIT.java
deleted file mode 100644
index 2a146a3..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/AbstractSocketAppenderReconnectIT.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.appender.AbstractManager;
-import org.apache.logging.log4j.core.appender.SocketAppender;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.net.AbstractSocketManager;
-import org.apache.logging.log4j.message.StringMapMessage;
-import org.apache.logging.log4j.server.TcpSocketServer;
-import org.junit.After;
-import org.junit.Assert;
-
-/**
- * Subclass for tests that reconnect to an Apache Socket Server. The class makes sure resources are properly shutdown
- * after each @Test method. A subclass normally only has one @Test method.
- * <p>
- * LOG4J2-1311 SocketAppender will lost first several logs after re-connection to log servers.
- * </p>
- */
-public class AbstractSocketAppenderReconnectIT {
-
- protected SocketAppender appender;
- protected int port;
- protected TcpSocketServer<InputStream> server;
- protected Thread thread;
-
- @After
- public void after() {
- shutdown();
- if (appender != null) {
- appender.stop();
- // Make sure the manager is gone as to not have bad side effect on other tests.
- @SuppressWarnings("resource")
- final AbstractSocketManager appenderManager = appender.getManager();
- if (appenderManager != null) {
- Assert.assertFalse(AbstractManager.hasManager(appenderManager.getName()));
- }
- }
- }
-
- protected void appendEvent(final SocketAppender appender) {
- final Map<String, String> map = new HashMap<>();
- final String messageText = "Hello, World!";
- final String loggerName = this.getClass().getName();
- map.put("messageText", messageText);
- map.put("threadName", Thread.currentThread().getName());
- // @formatter:off
- final LogEvent event = Log4jLogEvent.newBuilder()
- .setLoggerName(loggerName)
- .setLoggerFqcn(loggerName)
- .setLevel(Level.INFO)
- .setMessage(new StringMapMessage(map))
- .setTimeMillis(System.currentTimeMillis())
- .build();
- // @formatter:on
- appender.append(event);
- }
-
- protected void shutdown() {
- try {
- server.shutdown();
- } catch (final IOException e) {
- e.printStackTrace();
- }
- try {
- thread.join();
- } catch (final InterruptedException e) {
- // ignore
- }
- }
-
- protected Thread startServer(long sleepMillis) throws InterruptedException {
- thread = server.startNewThread();
- if (sleepMillis >= 0) {
- Thread.sleep(sleepMillis);
- }
- return thread;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectPostStartupIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectPostStartupIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectPostStartupIT.java
deleted file mode 100644
index d186dd5..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectPostStartupIT.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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 org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.core.appender.SocketAppender;
-import org.apache.logging.log4j.core.layout.JsonLayout;
-import org.apache.logging.log4j.core.net.SslSocketManager;
-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.test.AvailablePortFinder;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Tests that a Secure Socket Appender starts when there is no broker and connect the broker when it is started later.
- * <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 a SocketAppender (no reconnect thread is running)</li>
- * <li>Logs an event (fails and the manager starts its reconnect thread)</li>
- * <li>Starts Apache Socket Server</li>
- * <li>Logs an event successfully</li>
- * </ol>
- */
-public class SecureSocketAppenderConnectPostStartupIT extends AbstractSocketAppenderReconnectIT {
-
- private SslConfiguration sslConfiguration;
-
- @Before
- public void initServerSocketFactory() throws StoreConfigurationException {
- sslConfiguration = SslConfigurationTest.createTestSslConfigurationResources();
- }
-
- @Test
- public void testConnectPostStartup() throws Exception {
- //
- // Start appender
- final int port = AvailablePortFinder.getNextAvailable();
- // Start appender, fails to connect and starts reconnect thread.
- // @formatter:off
- appender = SocketAppender.newBuilder()
- .withPort(port)
- .withReconnectDelayMillis(1000)
- .withName("test")
- .withLayout(JsonLayout.newBuilder().build())
- .withSslConfiguration(sslConfiguration)
- .build();
- // @formatter:on
- appender.start();
- //
- // Logging will fail but the socket manager is still running its reconnect thread, waiting for the server.
- try {
- appendEvent(appender);
- Assert.fail("Expected to catch a " + AppenderLoggingException.class.getName());
- } catch (final AppenderLoggingException e) {
- // Expected.
- }
- //
- // Start server
- server = SecureTcpSocketServer.createJsonServer(port, sslConfiguration);
- // Wait to allow the reconnect thread to connect
- startServer(((SslSocketManager) appender.getManager()).getReconnectionDelayMillis() * 2);
- //
- // Logging now succeeds.
- appendEvent(appender);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/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
deleted file mode 100644
index 2a46cac..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SecureSocketAppenderConnectReConnectIT.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.SocketOptions;
-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 = SecureTcpSocketServer.createJsonServer(port, sslConfiguration);
- startServer(200);
- // Start appender
- // @formatter:off
- appender = SocketAppender.newBuilder()
- .withPort(port)
- .withConnectTimeoutMillis(1000)
- .withSocketOptions(SocketOptions.newBuilder().setSoTimeout(1000))
- .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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectPostStartupIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectPostStartupIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectPostStartupIT.java
deleted file mode 100644
index a9263cb..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectPostStartupIT.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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 org.apache.logging.log4j.core.appender.AppenderLoggingException;
-import org.apache.logging.log4j.core.appender.SocketAppender;
-import org.apache.logging.log4j.core.layout.JsonLayout;
-import org.apache.logging.log4j.core.net.TcpSocketManager;
-import org.apache.logging.log4j.server.TcpSocketServer;
-import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Tests that a Socket Appender starts when there is no broker and connect the broker when it is started later.
- * <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 a SocketAppender (no reconnect thread is running)</li>
- * <li>Logs an event (fails and the manager starts its reconnect thread)</li>
- * <li>Starts Apache Socket Server</li>
- * <li>Logs an event successfully</li>
- * </ol>
- */
-public class SocketAppenderConnectPostStartupIT extends AbstractSocketAppenderReconnectIT {
-
- @Test
- public void testConnectPostStartup() throws Exception {
- //
- // Start appender
- final int port = AvailablePortFinder.getNextAvailable();
- // Start appender, fails to connect and starts reconnect thread.
- // @formatter:off
- appender = SocketAppender.newBuilder()
- .withPort(port)
- .withReconnectDelayMillis(1000)
- .withName("test")
- .withLayout(JsonLayout.newBuilder().build())
- .build();
- // @formatter:on
- appender.start();
- //
- // Logging will fail but the socket manager is still running its reconnect thread, waiting for the server.
- try {
- appendEvent(appender);
- Assert.fail("Expected to catch a " + AppenderLoggingException.class.getName());
- } catch (final AppenderLoggingException e) {
- // Expected.
- }
- //
- // Start server
- server = TcpSocketServer.createJsonSocketServer(port);
- // Wait to allow the reconnect thread to connect
- startServer(((TcpSocketManager) appender.getManager()).getReconnectionDelayMillis() * 2);
- //
- // Logging now succeeds.
- appendEvent(appender);
- }
-}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bf3a76d8/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectReConnectIT.java
----------------------------------------------------------------------
diff --git a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectReConnectIT.java b/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectReConnectIT.java
deleted file mode 100644
index 359689d..0000000
--- a/log4j-core-its/src/test/java/org/apache/logging/log4j/core/appender/net/SocketAppenderConnectReConnectIT.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.server.TcpSocketServer;
-import org.apache.logging.log4j.test.AvailablePortFinder;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Tests that a Socket Appender can reconnect to a server after it has been recycled.
- * <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 SocketAppenderConnectReConnectIT extends AbstractSocketAppenderReconnectIT {
-
- @Test
- 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())
- .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 (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 = TcpSocketServer.createJsonSocketServer(port);
- 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);
- }
-
-}