You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/10/02 09:15:27 UTC

svn commit: r1528324 - in /felix/trunk/ipojo/runtime: core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/ core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/run...

Author: clement
Date: Wed Oct  2 07:15:26 2013
New Revision: 1528324

URL: http://svn.apache.org/r1528324
Log:
Add a test about FELIX-4247 Memory leak with ServiceUsage and inner class (Listener style) to confirm the fix.

Added:
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultHelloService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultLeakingService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/HelloService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/LeakingService.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Listener.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/ListenerStyleLeakTest.java
Modified:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultHelloService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultHelloService.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultHelloService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultHelloService.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.ipojo.runtime.core.test.components.leak;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.test.services.HelloService;
+
+/**
+ * A implementation of the Hello Service
+ * (FELIX-4247 Memory leak with ServiceUsage and inner class (Listener style))
+ */
+@Component
+@Provides
+public class DefaultHelloService implements HelloService {
+    @Override
+    public String hello(final String name) {
+        System.out.println("Hello "+ name);
+        return "Hello " + name;
+    }
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultLeakingService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultLeakingService.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultLeakingService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/leak/DefaultLeakingService.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.ipojo.runtime.core.test.components.leak;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Instantiate;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.annotations.Requires;
+import org.apache.felix.ipojo.runtime.core.test.services.HelloService;
+import org.apache.felix.ipojo.runtime.core.test.services.LeakingService;
+import org.apache.felix.ipojo.runtime.core.test.services.Listener;
+
+/**
+ * A component reproducing the leak (FELIX-4247 Memory leak with ServiceUsage and inner class (Listener style)).
+ */
+@Component
+@Provides
+@Instantiate
+public class DefaultLeakingService implements LeakingService {
+
+    @Requires(optional = true)
+    HelloService service;
+
+    private Listener listener;
+
+    public DefaultLeakingService() {
+        listener = new Listener() {
+            // When the Hello Service will become unavailable, calling doSomething should use a nullable object.
+            // Therefore, it should return 'null'.
+            @Override
+            public String doSomething() {
+                return service.hello("iPOJO");
+            }
+        };
+    }
+
+    @Override
+    public Listener getListener() {
+        return listener;
+    }
+
+    @Override
+    public String executeListener() {
+        return listener.doSomething();
+    }
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/HelloService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/HelloService.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/HelloService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/HelloService.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.ipojo.runtime.core.test.services;
+
+/**
+ * A service used to reproduce the leak bug (FELIX-4247 Memory leak with ServiceUsage and inner class (Listener
+ * style)).
+ */
+public interface HelloService {
+    String hello(String name);
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/LeakingService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/LeakingService.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/LeakingService.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/LeakingService.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.ipojo.runtime.core.test.services;
+
+/**
+ * A service providing a listener.
+ * USed to reproduce the leak bug (FELIX-4247 Memory leak with ServiceUsage and inner class (Listener style))
+ */
+public interface LeakingService {
+    Listener getListener();
+    String executeListener();
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Listener.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Listener.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Listener.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/services/Listener.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.ipojo.runtime.core.test.services;
+
+/**
+ * A listener to reproduce the listener leak (FELIX-4247 Memory leak with ServiceUsage and inner class (Listener
+ * style))
+ */
+public interface Listener {
+    String doSomething();
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/ListenerStyleLeakTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/ListenerStyleLeakTest.java?rev=1528324&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/ListenerStyleLeakTest.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-service-dependency-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/dependencies/leak/ListenerStyleLeakTest.java Wed Oct  2 07:15:26 2013
@@ -0,0 +1,106 @@
+/*
+ * 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.ipojo.runtime.core.test.dependencies.leak;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.runtime.core.test.dependencies.Common;
+import org.apache.felix.ipojo.runtime.core.test.services.HelloService;
+import org.apache.felix.ipojo.runtime.core.test.services.LeakingService;
+import org.apache.felix.ipojo.runtime.core.test.services.Listener;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+/**
+ * Check the fix of the leak FELIX-4247 Memory leak with ServiceUsage and inner class (Listener style).
+ */
+public class ListenerStyleLeakTest extends Common {
+
+    public static final String DEFAULT_HELLO_SERVICE = "org.apache.felix.ipojo.runtime.core.test.components.leak" +
+            ".DefaultHelloService";
+    public static final String DEFAULT_LEAKING_SERVICE = "org.apache.felix.ipojo.runtime.core.test.components.leak" +
+            ".DefaultLeakingService";
+
+    /**
+     * This test does not use the listener-style.
+     * <ol>
+     *     <li>Gets the hello message from the leaking instance using the hello instance</li>
+     *     <li>Stops the hello instance</li>
+     *     <li>Get the hello message again, must be {@code null}</li>
+     * </ol>
+     *
+     */
+    @Test
+    public void testNormalStyle() {
+
+        ComponentInstance hello = ipojoHelper.createComponentInstance(DEFAULT_HELLO_SERVICE);
+        ComponentInstance leaking = ipojoHelper.createComponentInstance(DEFAULT_LEAKING_SERVICE);
+
+        assertThat(hello.getState()).isEqualTo(ComponentInstance.VALID);
+        assertThat(leaking.getState()).isEqualTo(ComponentInstance.VALID);
+
+        LeakingService service = osgiHelper.waitForService(LeakingService.class,
+                "(instance.name=" + leaking.getInstanceName() + ")", 1000);
+        osgiHelper.waitForService(HelloService.class, "(instance.name=" + hello.getInstanceName() + ")", 1000);
+
+        String result = service.executeListener();
+        assertThat(result).isEqualToIgnoringCase("hello iPOJO");
+
+        hello.stop();
+
+        result = service.executeListener();
+        assertThat(result).isNull();
+    }
+
+    /**
+     * This test do use the listener-style.
+     * <ol>
+     *     <li>Gets the listener object provided by the leaking instance</li>
+     *     <li>Gets the hello message from this listener. As the hello service is bound,
+     *     it relies on the hello instance</li>
+     *     <li>Stops the hello instance</li>
+     *     <li>Get the hello message again, must be {@code null}</li>
+     * </ol>
+     *
+     */
+    @Test
+    public void testListenerStyle() {
+
+        ComponentInstance hello = ipojoHelper.createComponentInstance(DEFAULT_HELLO_SERVICE);
+        ComponentInstance leaking = ipojoHelper.createComponentInstance(DEFAULT_LEAKING_SERVICE);
+
+        assertThat(hello.getState()).isEqualTo(ComponentInstance.VALID);
+        assertThat(leaking.getState()).isEqualTo(ComponentInstance.VALID);
+
+        LeakingService service = osgiHelper.waitForService(LeakingService.class,
+                "(instance.name=" + leaking.getInstanceName() + ")", 1000);
+        osgiHelper.waitForService(HelloService.class, "(instance.name=" + hello.getInstanceName() + ")", 1000);
+
+        Listener listener = service.getListener();
+        String result = listener.doSomething();
+        assertThat(result).isEqualToIgnoringCase("hello iPOJO");
+
+        hello.stop();
+
+        result = listener.doSomething();
+        assertThat(result).isNull();
+    }
+}

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=1528324&r1=1528323&r2=1528324&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java Wed Oct  2 07:15:26 2013
@@ -278,7 +278,6 @@ public class DependencyHandler extends P
                 if (meths != null) {
                     for (MethodMetadata method : meths) {
                         for (Dependency dep : m_dependencies) {
-                            System.out.println("Registering " + method.getMethodName());
                             getInstanceManager().register(method, inner, dep);
                         }
                     }