You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by dj...@apache.org on 2012/10/25 20:00:01 UTC

svn commit: r1402235 - /felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Author: djencks
Date: Thu Oct 25 18:00:00 2012
New Revision: 1402235

URL: http://svn.apache.org/viewvc?rev=1402235&view=rev
Log:
provide a way to only log last 1000 lines for lengthy tests

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1402235&r1=1402234&r2=1402235&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java Thu Oct 25 18:00:00 2012
@@ -115,6 +115,10 @@ public abstract class ComponentTestBase
     protected static boolean NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR = false;
     protected volatile Log log;
 
+    //set to true to only get last 1000 lines of log.
+    protected static boolean restrictedLogging;
+
+
     static
     {
         theConfig = new Hashtable<String, String>();
@@ -164,7 +168,7 @@ public abstract class ComponentTestBase
     @Before
     public void setUp() throws BundleException
     {
-        log = new Log();
+        log = new Log(restrictedLogging);
         log.start();
         bundleContext.addFrameworkListener( log );
         bundleContext.registerService( LogService.class.getName(), log, null );
@@ -661,6 +665,7 @@ public abstract class ComponentTestBase
     
     public static class Log implements LogService, FrameworkListener, Runnable
     {
+        private static final int RESTRICTED_LOG_SIZE = 1000;
         private final SimpleDateFormat m_sdf = new SimpleDateFormat( "HH:mm:ss,S" );
         private final static PrintStream m_out = new PrintStream( new BufferedOutputStream( new FileOutputStream(
             FileDescriptor.err ), 128 ) );
@@ -670,6 +675,15 @@ public abstract class ComponentTestBase
         private volatile PrintStream m_realOut;
         private volatile PrintStream m_realErr;
 
+        private final boolean restrictedLogging;
+        private final String[] log = new String[1000];
+        private int i = 0;
+
+        public Log( boolean restrictedLogging )
+        {
+            this.restrictedLogging = restrictedLogging;
+        }
+
         public void start()
         {
             m_realOut = System.out;
@@ -685,7 +699,21 @@ public abstract class ComponentTestBase
         {
             System.setOut(m_realOut);
             System.setErr(m_realErr);
-            m_out.flush();
+            if ( restrictedLogging )
+            {
+                for (int j = 0; j < RESTRICTED_LOG_SIZE; j++)
+                {
+                    if ( log[i] != null )
+                    {
+                        m_realErr.println(log[i++]);
+                    }
+                    if (i == RESTRICTED_LOG_SIZE) i = 0;
+                }
+            }
+            else
+            {
+                m_out.flush();
+            }
             m_warnings.clear();
             m_logThread.interrupt();
             try
@@ -738,8 +766,16 @@ public abstract class ComponentTestBase
                         PrintWriter pw = new PrintWriter( sw );
                         entry.getError().printStackTrace( pw );
                     }
-                    m_out.println( sw.toString() );
-                    m_out.flush();
+                    if ( restrictedLogging )
+                    {
+                        log[i++] = sw.toString();
+                        if ( i == RESTRICTED_LOG_SIZE ) i = 0;
+                    }
+                    else
+                    {
+                        m_out.println( sw.toString() );
+                        m_out.flush();
+                    }
                 }
             }
             catch ( InterruptedException e )