[jboss-remoting-commits] JBoss Remoting SVN: r4357 - in remoting3/trunk: core/src/test/java/org/jboss/cx/remoting/core and 1 other directories.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jul 3 20:58:49 EDT 2008


Author: david.lloyd at jboss.com
Date: 2008-07-03 20:58:49 -0400 (Thu, 03 Jul 2008)
New Revision: 4357

Added:
   remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
Modified:
   remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
   remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
   remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
   remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
   remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
   remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
Log:
Add logging helper

Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -26,11 +26,16 @@
 import java.util.Arrays;
 import java.nio.ByteBuffer;
 import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 
 /**
  *
  */
 public final class ByteBufferInputStreamTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     public void testBasic() throws Throwable {
         final TestByteBufferAllocator allocator = new TestByteBufferAllocator(3);
         final ByteBufferInputStream stream = new ByteBufferInputStream(Streams.<ByteBuffer>getIteratorObjectSource(Arrays.<ByteBuffer>asList(

Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -32,6 +33,10 @@
  *
  */
 public final class ByteBufferOutputStreamTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     public void testBasic() throws Throwable {
         final TestByteBufferAllocator allocator = new TestByteBufferAllocator(4);
         final List<ByteBuffer> list = new ArrayList<ByteBuffer>();

Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 import java.util.Arrays;
 import java.nio.CharBuffer;
 
@@ -31,6 +32,10 @@
  *
  */
 public final class CharBufferReaderTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     public void testBasic() throws Throwable {
         final TestCharBufferAllocator allocator = new TestCharBufferAllocator(10);
         final ObjectSource<CharBuffer> source = Streams.getIteratorObjectSource(Arrays.asList(

Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -27,11 +27,16 @@
 import java.util.List;
 import java.nio.CharBuffer;
 import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 
 /**
  *
  */
 public final class CharBufferWriterTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     public void testBasic() throws Throwable {
         final TestCharBufferAllocator allocator = new TestCharBufferAllocator(7);
         final List<CharBuffer> list = new ArrayList<CharBuffer>();

Modified: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -28,11 +28,16 @@
 import java.util.Arrays;
 import java.util.Vector;
 import java.io.EOFException;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 
 /**
  *
  */
 public final class StreamsTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     public void testCollectionObjectSink() throws Throwable {
         final ArrayList<String> strings = new ArrayList<String>();
         final ObjectSink<String> sink = Streams.getCollectionObjectSink(strings);

Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java	2008-07-04 00:52:01 UTC (rev 4356)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -32,6 +32,7 @@
 import org.jboss.cx.remoting.CloseHandler;
 import org.jboss.cx.remoting.Client;
 import org.jboss.cx.remoting.RemotingException;
+import org.jboss.cx.remoting.test.support.LoggingHelper;
 import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
 import org.jboss.xnio.IoUtils;
 
@@ -39,6 +40,10 @@
  *
  */
 public final class EndpointTestCase extends TestCase {
+    static {
+        LoggingHelper.init();
+    }
+
     private static void safeStop(EndpointImpl endpoint) {
         try {
             endpoint.stop();

Added: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java	                        (rev 0)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java	2008-07-04 00:58:49 UTC (rev 4357)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.test.support;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.logging.Handler;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+/**
+ *
+ */
+public final class LoggingHelper {
+    private static final class Once {
+        static {
+            AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                public Void run() {
+                    final Logger rootLogger = Logger.getLogger("");
+                    rootLogger.setLevel(Level.ALL);
+                    final Handler[] handlers = rootLogger.getHandlers();
+                    for (Handler handler : handlers) {
+                        handler.setLevel(Level.ALL);
+                        handler.setFormatter(new Formatter() {
+                            public String format(final LogRecord record) {
+                                StringBuilder builder = new StringBuilder();
+                                builder.append(record.getLevel().toString());
+                                builder.append(" [").append(record.getLoggerName()).append("] ");
+                                builder.append(String.format(record.getMessage(), record.getParameters()));
+                                Throwable t = record.getThrown();
+                                while (t != null) {
+                                    builder.append("\n    Caused by: ");
+                                    builder.append(t.getClass().getName());
+                                    builder.append(": ");
+                                    builder.append(t.getMessage());
+                                    for (StackTraceElement e : t.getStackTrace()) {
+                                        builder.append("\n        at ");
+                                        builder.append(e.getClassName()).append('.').append(e.getMethodName());
+                                        builder.append("(").append(e.getFileName()).append(':').append(e.getLineNumber()).append(')');
+                                    }
+                                    t = t.getCause();
+                                }
+                                builder.append('\n');
+                                return builder.toString();
+                            }
+                        });
+                    }
+                    return null;
+                }
+            });
+        }
+    }
+
+    private LoggingHelper() {
+    }
+
+    public static void init() {
+        new Once();
+    }
+}




More information about the jboss-remoting-commits mailing list