provide a way to only log last 1000 lines for lengthy tests

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1402235 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
index dfaff77..5ad110b 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
@@ -115,6 +115,10 @@
     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 @@
     @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 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 @@
         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 @@
         {
             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 @@
                         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 )