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 2014/01/07 01:12:32 UTC

svn commit: r1556078 - in /felix/trunk/scr/src/test: java/org/apache/felix/scr/integration/ java/org/apache/felix/scr/integration/components/deadlock/ resources/

Author: djencks
Date: Tue Jan  7 00:12:31 2014
New Revision: 1556078

URL: http://svn.apache.org/r1556078
Log:
FELIX-4348 async locate service deadlock test

Added:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java   (with props)
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java   (with props)
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java   (with props)
    felix/trunk/scr/src/test/resources/integration_test_locate.xml   (with props)
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=1556078&r1=1556077&r2=1556078&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 Tue Jan  7 00:12:31 2014
@@ -140,6 +140,7 @@ public abstract class ComponentTestBase
                                             "org.apache.felix.scr.integration.components.circular," +
                                             "org.apache.felix.scr.integration.components.circularFactory," +
                                             "org.apache.felix.scr.integration.components.concurrency," +
+                                            "org.apache.felix.scr.integration.components.deadlock," +
                                             "org.apache.felix.scr.integration.components.felix3680," +
                                             "org.apache.felix.scr.integration.components.felix3680_2");
         builder.setHeader("Import-Package", "org.apache.felix.scr,org.apache.felix.scr.component;mandatory:=\"status\"; status=\"provisional\"");

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java?rev=1556078&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java Tue Jan  7 00:12:31 2014
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration;
+
+import static org.junit.Assert.*;
+
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import org.apache.felix.scr.Component;
+import org.apache.felix.scr.integration.components.SimpleServiceImpl;
+import org.apache.felix.scr.integration.components.deadlock.Consumer;
+import org.apache.felix.scr.integration.components.deadlock.TestComponent;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.cm.Configuration;
+
+@RunWith(JUnit4TestRunner.class)
+public class LocateTest extends ComponentTestBase
+{
+    
+    static
+    {
+        descriptorFile = "/integration_test_locate.xml";
+        // uncomment to enable debugging of this test class
+//         paxRunnerVmOption = DEBUG_VM_OPTION;
+        COMPONENT_PACKAGE = COMPONENT_PACKAGE + ".deadlock";
+    }
+    
+    @Test
+    public void testAsyncLocate() throws Exception
+    {
+        bundleContext.registerService( Object.class, new Object(), null );
+        
+        final Component consumerComponent = findComponentByName( "AsyncLocate" );
+        TestCase.assertNotNull( consumerComponent );
+        TestCase.assertEquals( Component.STATE_ACTIVE, consumerComponent.getState() );
+        
+        final String pid = "SimpleComponent";
+        Configuration config = getConfigurationAdmin().getConfiguration( pid, null );
+        final Hashtable props = new Hashtable();
+        props.put( "target", "bar" );
+        config.update(props);
+        delay();
+        
+        final Component component = findComponentByName( pid );
+        TestCase.assertNotNull( component );
+        //when deadlock is present the state is actually unsatisfied.
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        delay();
+        props.put( "target", "foo" );
+        config.update(props);
+        delay();
+       
+        TestComponent tc = (TestComponent) component.getComponentInstance().getInstance();
+        assertTrue(tc.isSuccess1());
+        assertTrue(tc.isSuccess2());
+    }
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java?rev=1556078&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java Tue Jan  7 00:12:31 2014
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration.components.deadlock;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+public class Consumer
+{
+    
+    private ComponentContext cc;
+    
+    protected void activate(ComponentContext cc) 
+    {
+        this.cc = cc;
+    }
+    
+    protected void setSimpleComponent(TestComponent sc)
+    {
+        sc.doIt( );       
+    }
+    
+    protected void unsetSimpleComponent(ServiceReference<TestComponent> sr)
+    {
+        
+    }    
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/Consumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java?rev=1556078&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java Tue Jan  7 00:12:31 2014
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration.components.deadlock;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+public class TestComponent
+{
+    
+    private ComponentContext cc;
+    
+    private ServiceReference sr;
+    private boolean success1;
+    private boolean success2;
+    
+    protected void activate(ComponentContext cc)
+    {
+        this.cc =cc;
+    }
+    
+    protected void setRef(ServiceReference sr)
+    {
+        this.sr = sr;
+    }
+    
+    protected void unsetRef(ServiceReference sr)
+    {
+        if (sr == this.sr)
+        {
+            this.sr = null;
+        }
+    }
+
+    public void doIt()
+    {
+        Thread t = new Thread() 
+        {
+
+            @Override
+            public void run()
+            {
+                Object sc = cc.locateService("Ref", sr);
+                if (sc != null)
+                {
+                    success1 = true;
+                }
+            }
+            
+        };
+        t.start();
+        try
+        {
+            t.join();
+            success2 = true;
+        }
+        catch ( InterruptedException e )
+        {
+            e.printStackTrace();
+        }
+       
+    }
+    
+    public boolean isSuccess1()
+    {
+        return success1;
+    }
+
+    public boolean isSuccess2()
+    {
+        return success2;
+    }
+
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/deadlock/TestComponent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/scr/src/test/resources/integration_test_locate.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_locate.xml?rev=1556078&view=auto
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_locate.xml (added)
+++ felix/trunk/scr/src/test/resources/integration_test_locate.xml Tue Jan  7 00:12:31 2014
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	you under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"> 
+
+    <scr:component name="SimpleComponent"
+        configuration-policy="require">
+        <implementation class="org.apache.felix.scr.integration.components.deadlock.TestComponent" />
+        <service>
+            <provide interface='org.apache.felix.scr.integration.components.deadlock.TestComponent' />
+        </service>
+        <reference
+            name="Ref"
+            interface="java.lang.Object"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setRef"
+            unbind="unsetRef"
+        />
+    </scr:component>
+
+
+    <scr:component name="AsyncLocate"
+        immediate="true">
+        <implementation class="org.apache.felix.scr.integration.components.deadlock.Consumer" />
+        <reference
+            name="SimpleComponent"
+            interface="org.apache.felix.scr.integration.components.deadlock.TestComponent"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleComponent"
+            unbind="unsetSimpleComponent"
+            target='target="foo"'
+        />
+    </scr:component>
+
+</components>

Propchange: felix/trunk/scr/src/test/resources/integration_test_locate.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/resources/integration_test_locate.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/resources/integration_test_locate.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml