logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1426901 - in /logging/log4j/log4j2/trunk/core/src: main/java/org/apache/logging/log4j/core/net/ test/java/org/apache/logging/log4j/core/appender/ test/java/org/apache/logging/log4j/core/net/
Date Sun, 30 Dec 2012 07:09:34 GMT
Author: rgoers
Date: Sun Dec 30 07:09:34 2012
New Revision: 1426901

URL: http://svn.apache.org/viewvc?rev=1426901&view=rev
Log:
Fix unit test issues when building with Java 7

Added:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
      - copied, changed from r1426000, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java?rev=1426901&r1=1426900&r2=1426901&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/MimeMessageBuilder.java
Sun Dec 30 07:09:34 2012
@@ -39,7 +39,11 @@ public class MimeMessageBuilder {
         if (null != address) {
             message.setFrom(address);
         } else {
-            message.setFrom();
+            try {
+                message.setFrom();
+            } catch (Exception ex) {
+                message.setFrom(null);
+            }
         }
         return this;
     }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java?rev=1426901&r1=1426900&r2=1426901&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
Sun Dec 30 07:09:34 2012
@@ -43,6 +43,7 @@ import org.apache.logging.log4j.core.app
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.helpers.CyclicBuffer;
 import org.apache.logging.log4j.core.helpers.NameUtil;
+import org.apache.logging.log4j.core.helpers.NetUtils;
 import org.apache.logging.log4j.core.helpers.PropertiesUtil;
 
 public class SMTPManager extends AbstractManager {
@@ -280,6 +281,10 @@ public class SMTPManager extends Abstrac
 
             Properties properties = PropertiesUtil.getSystemProperties();
             properties.put("mail.transport.protocol", data.protocol);
+            if (properties.getProperty("mail.host") == null) {
+                // Prevent an UnknownHostException in Java 7
+                properties.put("mail.host", NetUtils.getLocalHostname());
+            }
 
             if (null != data.host) {
                 properties.put(prefix + ".host", data.host);

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java?rev=1426901&r1=1426900&r2=1426901&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/SMTPAppenderTest.java
Sun Dec 30 07:09:34 2012
@@ -52,7 +52,12 @@ public class SMTPAppenderTest {
         assertNull(builder.getMimeMessage().getFrom());
 
         builder.setFrom(null);
-        assertArrayEquals(new Address[] { InternetAddress.getLocalAddress(null) }, builder.getMimeMessage().getFrom());
+        Address[] array = null;
+        Address addr = InternetAddress.getLocalAddress(null);
+        if (addr != null) {
+            array = new Address[] {addr};
+        }
+        assertArrayEquals(array, builder.getMimeMessage().getFrom());
 
         builder.setFrom(address);
         assertArrayEquals(new Address[] { new InternetAddress(address) }, builder.getMimeMessage().getFrom());

Copied: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
(from r1426000, logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java?p2=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java&p1=logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java&r1=1426000&r2=1426901&rev=1426901&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java
Sun Dec 30 07:09:34 2012
@@ -16,6 +16,13 @@
  */
 package org.apache.logging.log4j.core.net;
 
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.AppenderRuntimeException;
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,17 +34,10 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.appender.AppenderRuntimeException;
-import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-public class SocketTest {
+public class SocketReconnectTest {
     private static final int SOCKET_PORT = 5514;
 
     private static final String CONFIG = "log4j-socket.xml";
@@ -48,25 +48,6 @@ public class SocketTest {
     }
 
     @Test
-    public void testConnect() throws Exception {
-        System.err.println("Initializing logger");
-        Logger logger = null;
-        try {
-            logger = LogManager.getLogger(SocketTest.class);
-        } catch (final NullPointerException e) {
-            fail("Unexpected exception; should not occur until first logging statement "
+ e.getMessage());
-        }
-
-        final String message = "Log #1";
-        try {
-            logger.error(message);
-            fail("Expected exception not thrown");
-        } catch (final AppenderRuntimeException e) {
-            //System.err.println("Expected exception here, but already errored out when initializing
logger");
-        }
-    }
-
-    @Test
     public void testReconnect() throws Exception {
         TestSocketServer testServer = null;
         ExecutorService executor = null;
@@ -81,7 +62,7 @@ public class SocketTest {
             Thread.sleep(300);
 
             //System.err.println("Initializing logger");
-            final Logger logger = LogManager.getLogger(SocketTest.class);
+            final Logger logger = LogManager.getLogger(SocketReconnectTest.class);
 
             String message = "Log #1";
             logger.error(message);

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java?rev=1426901&r1=1426900&r2=1426901&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java
Sun Dec 30 07:09:34 2012
@@ -66,63 +66,6 @@ public class SocketTest {
         }
     }
 
-    @Test
-    public void testReconnect() throws Exception {
-        TestSocketServer testServer = null;
-        ExecutorService executor = null;
-        Future<InputStream> futureIn;
-        final InputStream in;
-
-        try {
-            executor = Executors.newSingleThreadExecutor();
-            System.err.println("Initializing server");
-            testServer = new TestSocketServer();
-            futureIn = executor.submit(testServer);
-            Thread.sleep(300);
-
-            //System.err.println("Initializing logger");
-            final Logger logger = LogManager.getLogger(SocketTest.class);
-
-            String message = "Log #1";
-            logger.error(message);
-
-            BufferedReader reader = new BufferedReader(new InputStreamReader(futureIn.get()));
-            assertEquals(message, reader.readLine());
-
-            closeQuietly(testServer);
-
-            message = "Log #2";
-            logger.error(message);
-
-            message = "Log #3";
-            try {
-                logger.error(message);
-            } catch (final AppenderRuntimeException e) {
-                // System.err.println("Caught expected exception");
-            }
-
-            //System.err.println("Re-initializing server");
-            testServer = new TestSocketServer();
-            futureIn = executor.submit(testServer);
-            Thread.sleep(500);
-
-            try {
-                logger.error(message);
-                reader = new BufferedReader(new InputStreamReader(futureIn.get()));
-                assertEquals(message, reader.readLine());
-            } catch (final AppenderRuntimeException e) {
-                e.printStackTrace();
-                fail("Unexpected Exception");
-            }
-            //System.err.println("Sleeping to demonstrate repeated re-connections");
-            //Thread.sleep(5000);
-        } finally {
-            closeQuietly(testServer);
-            closeQuietly(executor);
-        }
-    }
-
-
     private static class TestSocketServer implements Callable<InputStream> {
         private ServerSocket server;
         private Socket client;



Mime
View raw message