felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1381404 - in /felix/trunk/scr/src/test/java/org/apache/felix/scr/integration: ComponentConcurrencyTest.java ComponentTestBase.java
Date Wed, 05 Sep 2012 21:49:24 GMT
Author: djencks
Date: Wed Sep  5 21:49:24 2012
New Revision: 1381404

URL: http://svn.apache.org/viewvc?rev=1381404&view=rev
Log:
FELIX-3645 fix concurrency test to allow expected logged errors.  Provide logging for all
itests

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
    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/ComponentConcurrencyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java?rev=1381404&r1=1381403&r2=1381404&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
Wed Sep  5 21:49:24 2012
@@ -26,6 +26,7 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Date;
 import java.util.Hashtable;
+import java.util.Iterator;
 
 import javax.inject.Inject;
 
@@ -50,7 +51,7 @@ public class ComponentConcurrencyTest ex
     static
     {
         // uncomment to enable debugging of this test class
-        //  paxRunnerVmOption = DEBUG_VM_OPTION;
+//        paxRunnerVmOption = DEBUG_VM_OPTION;
         descriptorFile = "/integration_test_component_concurrency.xml";
     }
 
@@ -68,91 +69,34 @@ public class ComponentConcurrencyTest ex
         }
     }
 
-    // Used to ignore logs displayed by the framework from stdout.
-    // (the log service will log it because it listen to fwk error 
-    // events ...).
-    static class NullStdout extends PrintStream
-    {
-        NullStdout()
-        {
-            super(new OutputStream()
-            {
-                @Override
-                public void write(int b) throws IOException
-                {
-                }
-            });
-        }
-    }
-
-    public static class Log implements LogListener
-    {
-        private volatile boolean _foundWarnings;
-        private final static PrintStream _out =
-                new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err),
128));
-
-        public void logged(LogEntry entry)
-        {
-            if (entry.getLevel() <= 2)
-            {
-                _foundWarnings = true;
-            }
-            StringWriter sw = new StringWriter();
-            sw.append("D=");
-            sw.append(new Date(entry.getTime()).toString());
-            sw.append(", T=" + Thread.currentThread().getName());
-            sw.append(": ");
-            sw.append(entry.getMessage());
-            if (entry.getException() != null)
-            {
-                sw.append(System.getProperty("line.separator"));
-                PrintWriter pw = new PrintWriter(sw);
-                entry.getException().printStackTrace(pw);
-            }
-            _out.println(sw.toString());
-        }
-
-        boolean foundWarnings()
-        {
-            return _foundWarnings;
-        }
-    }
-
     @Test
     public void test_concurrent_component_activation_using_componentFactories()
     {
-        final PrintStream out = System.out;
-        final PrintStream err = System.err;
-        System.setOut(new NullStdout());
-        System.setErr(new NullStdout());
-        
-        try
-        {
-            Log log = new Log();
-            ServiceReference sr = bundleContext.getServiceReference(LogReaderService.class.getName());
-            TestCase.assertNotNull(sr);
-            LogReaderService logReader = (LogReaderService) bundleContext.getService(sr);
-            TestCase.assertNotNull(logReader);
-            logReader.addLogListener(log);
-
-            final Component AFactory =
-                    findComponentByName("org.apache.felix.scr.integration.components.concurrency.AFactory");
-            TestCase.assertNotNull(AFactory);
-            AFactory.enable();
-
-            final Component CFactory =
-                    findComponentByName("org.apache.felix.scr.integration.components.concurrency.CFactory");
-            TestCase.assertNotNull(CFactory);
-            CFactory.enable();
 
-            delay(30);
-            TestCase.assertFalse(log.foundWarnings());
-        }
 
-        finally
-        {
-            System.setOut(out);
-            System.setErr(err);
+        final Component AFactory =
+                findComponentByName( "org.apache.felix.scr.integration.components.concurrency.AFactory"
);
+        TestCase.assertNotNull( AFactory );
+        AFactory.enable();
+
+        final Component CFactory =
+                findComponentByName( "org.apache.felix.scr.integration.components.concurrency.CFactory"
);
+        TestCase.assertNotNull( CFactory );
+        CFactory.enable();
+
+        delay( 30 );
+        for ( Iterator it = log.foundWarnings().iterator(); it.hasNext();)
+        {
+            LogEntry entry = ( LogEntry ) it.next();
+            String message = entry.getMessage();
+            if ( message.contains( "FrameworkEvent ERROR" ) ||
+                    message.contains( "Could not get service from ref" ) ||
+                    message.contains( "Failed creating the component instance; see log for
reason" ) ||
+                    message.contains( "Cannot create component instance due to failure to
bind reference" ))
+            {
+                continue;
+            }
+            TestCase.fail( "unexpected warning or error logged: " + message );
         }
     }
 }

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=1381404&r1=1381403&r2=1381404&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
Wed Sep  5 21:49:24 2012
@@ -27,16 +27,25 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
 import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.lang.reflect.Field;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Date;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.List;
 import java.util.TreeSet;
 
 import javax.inject.Inject;
@@ -58,7 +67,11 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
 import org.osgi.util.tracker.ServiceTracker;
 
 
@@ -95,6 +108,9 @@ public abstract class ComponentTestBase
     protected static String descriptorFile = "/integration_test_simple_components.xml";
 
     protected static boolean NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR = false;
+    private PrintStream out;
+    private PrintStream err;
+    protected Log log;
 
     static
     {
@@ -124,12 +140,13 @@ public abstract class ComponentTestBase
         final Option[] base = options(
             provision(
                 CoreOptions.bundle( bundleFile.toURI().toString() ),
+                    mavenBundle( "org.apache.felix", "org.apache.felix.log", "1.0.1" ),
                 mavenBundle( "org.ops4j.pax.tinybundles", "tinybundles", "1.0.0" ),
-                mavenBundle( "org.apache.felix", "org.apache.felix.configadmin", "1.0.10"
),
-                mavenBundle( "org.apache.felix", "org.apache.felix.log", "1.0.1" )
+                mavenBundle( "org.apache.felix", "org.apache.felix.configadmin", "1.0.10"
)
              ),
              junitBundles(),
-             systemProperty( "ds.factory.enabled" ).value( Boolean.toString( NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR
) )
+             systemProperty( "ds.factory.enabled" ).value( Boolean.toString( NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR
) ),
+             systemProperty( "ds.loglevel" ).value( "debug" )
 
         );
         final Option vmOption = ( paxRunnerVmOption != null ) ? CoreOptions.vmOption( paxRunnerVmOption
) : null;
@@ -140,6 +157,18 @@ public abstract class ComponentTestBase
     @Before
     public void setUp() throws BundleException
     {
+        out = System.out;
+        err = System.err;
+        System.setOut(new NullStdout());
+        System.setErr( new NullStdout() );
+
+        log = new Log();
+            ServiceReference sr = bundleContext.getServiceReference(LogReaderService.class.getName());
+            TestCase.assertNotNull(sr);
+            LogReaderService logReader = (LogReaderService) bundleContext.getService(sr);
+            TestCase.assertNotNull(logReader);
+            logReader.addLogListener( log );
+
         scrTracker = new ServiceTracker( bundleContext, "org.apache.felix.scr.ScrService",
null );
         scrTracker.open();
         configAdminTracker = new ServiceTracker( bundleContext, "org.osgi.service.cm.ConfigurationAdmin",
null );
@@ -163,6 +192,8 @@ public abstract class ComponentTestBase
         configAdminTracker = null;
         scrTracker.close();
         scrTracker = null;
+        System.setOut(out);
+        System.setErr(err);
     }
 
 
@@ -546,4 +577,56 @@ public abstract class ComponentTestBase
         }
     }
 
+    // Used to ignore logs displayed by the framework from stdout.
+    // (the log service will log it because it listen to fwk error
+    // events ...).
+    static class NullStdout extends PrintStream
+    {
+        NullStdout()
+        {
+            super(new OutputStream()
+            {
+                @Override
+                public void write(int b) throws IOException
+                {
+                }
+            });
+        }
+    }
+
+    public static class Log implements LogListener
+    {
+        private final List m_warnings = Collections.synchronizedList( new ArrayList() );//<LogEntry>
+        private final static PrintStream _out =
+                new PrintStream(new BufferedOutputStream(new FileOutputStream( FileDescriptor.err),
128));
+
+        public void logged(LogEntry entry)
+        {
+            if (entry.getLevel() <= 2)
+            {
+                m_warnings.add( entry );
+            }
+            StringWriter sw = new StringWriter();
+            sw.append( "log level: " + entry.getLevel() );
+            sw.append(" D=");
+            sw.append(new Date(entry.getTime()).toString());
+            sw.append(", T=" + Thread.currentThread().getName());
+            sw.append(": ");
+            sw.append(entry.getMessage());
+            if (entry.getException() != null)
+            {
+                sw.append(System.getProperty("line.separator"));
+                PrintWriter pw = new PrintWriter(sw);
+                entry.getException().printStackTrace(pw);
+            }
+            _out.println(sw.toString());
+        }
+
+        List foundWarnings()
+        {
+            return m_warnings;
+        }
+    }
+
+
 }



Mime
View raw message