incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r958509 - in /incubator/aries/trunk/util/src: main/java/org/apache/aries/util/tracker/ test/java/org/apache/aries/util/
Date Mon, 28 Jun 2010 09:03:22 GMT
Author: mahrwald
Date: Mon Jun 28 09:03:22 2010
New Revision: 958509

URL: http://svn.apache.org/viewvc?rev=958509&view=rev
Log:
ARIES-342: Stop memory leak with CompositeBundles

Added:
    incubator/aries/trunk/util/src/test/java/org/apache/aries/util/RecursiveBundleTrackerTest.java
Modified:
    incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
    incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java

Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java?rev=958509&r1=958508&r2=958509&view=diff
==============================================================================
--- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
(original)
+++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/InternalRecursiveBundleTracker.java
Mon Jun 28 09:03:22 2010
@@ -99,7 +99,7 @@ public class InternalRecursiveBundleTrac
   public void removedBundle(Bundle b, BundleEvent event, Object object)
   {
     if (b instanceof CompositeBundle) {
-      // We should have already picked up the stopping event on the CBA itself
+      customizedProcessBundle(this, b, event);
     } else {
       if (customizer != null) {
         customizer.removedBundle(b, event, object);
@@ -123,7 +123,7 @@ public class InternalRecursiveBundleTrac
           openTracker(btc, cb, bundleScope, mask);
         }
       } else {
-        if (event.getType() == BundleEvent.STOPPING) {
+        if (event.getType() == BundleEvent.STOPPED) {
           // if CompositeBundle is being stopped, let's remove the bundle
           // tracker(s) associated with the composite bundle
           BundleContext compositeBundleContext = ((CompositeBundle) b).getCompositeFramework()

Modified: incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java?rev=958509&r1=958508&r2=958509&view=diff
==============================================================================
--- incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
(original)
+++ incubator/aries/trunk/util/src/main/java/org/apache/aries/util/tracker/RecursiveBundleTracker.java
Mon Jun 28 09:03:22 2010
@@ -47,7 +47,7 @@ public final class RecursiveBundleTracke
      * 
      * @param context - The <code>BundleContext</code> against which the tracking
is done.
      * @param stateMask - The bit mask of the ORing of the bundle states to be tracked. The
-     * mask must contain the flags <code>Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING</code>
+     * mask must contain the flags <code>Bundle.INSTALLED | Bundle.STARTING | Bundle.ACTIVE
| Bundle.STOPPING</code>
      * as a minimum.
      * @throws IllegalArgumentException - If the provided bit mask does not contain required
      * flags

Added: incubator/aries/trunk/util/src/test/java/org/apache/aries/util/RecursiveBundleTrackerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/util/src/test/java/org/apache/aries/util/RecursiveBundleTrackerTest.java?rev=958509&view=auto
==============================================================================
--- incubator/aries/trunk/util/src/test/java/org/apache/aries/util/RecursiveBundleTrackerTest.java
(added)
+++ incubator/aries/trunk/util/src/test/java/org/apache/aries/util/RecursiveBundleTrackerTest.java
Mon Jun 28 09:03:22 2010
@@ -0,0 +1,94 @@
+/*
+ * 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.aries.util;
+
+import org.apache.aries.unittest.mocks.MethodCall;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.apache.aries.util.tracker.BundleTrackerFactory;
+import org.apache.aries.util.tracker.InternalRecursiveBundleTracker;
+import org.apache.aries.util.tracker.RecursiveBundleTracker;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
+import org.osgi.util.tracker.BundleTrackerCustomizer;
+
+import static org.junit.Assert.*;
+
+public class RecursiveBundleTrackerTest {
+    BundleContext context;
+    
+    @Before
+    public void setup() {
+        context = Skeleton.newMock(BundleContext.class);
+        Skeleton.getSkeleton(context).setReturnValue(
+                new MethodCall(BundleContext.class, "getServiceReference", "org.osgi.service.framework.CompositeBundleFactory"),

+                Skeleton.newMock(ServiceReference.class));
+    }
+    
+    @After
+    public void closeTrackes() {
+        BundleTrackerFactory.unregisterAndCloseBundleTracker("test");
+    }
+    
+    @Test
+    public void testCompositeLifeCycle() {
+        BundleTrackerCustomizer customizer = Skeleton.newMock(BundleTrackerCustomizer.class);
+
+        InternalRecursiveBundleTracker sut = new InternalRecursiveBundleTracker(context,

+                Bundle.INSTALLED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, customizer);
+        
+        sut.open();
+        
+        CompositeBundle cb = Skeleton.newMock(CompositeBundle.class);
+        Skeleton cbSkel = Skeleton.getSkeleton(cb);
+        cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getSymbolicName"), "test.composite");
+        cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getVersion"), new Version("1.0.0"));
+        
+        assertTrue(BundleTrackerFactory.getAllBundleTracker().isEmpty());
+        
+        sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
+        assertEquals(1, BundleTrackerFactory.getAllBundleTracker().size());
+        assertEquals(1, BundleTrackerFactory.getBundleTrackerList("test.composite_1.0.0").size());
+        
+        sut.removedBundle(cb, new BundleEvent(BundleEvent.STOPPED, cb), cb);
+        assertTrue(BundleTrackerFactory.getAllBundleTracker().isEmpty());        
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testMissingStopping() {
+        new RecursiveBundleTracker(null, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING
| Bundle.ACTIVE, null);
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testMissingStarting() {
+        new RecursiveBundleTracker(null, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE
| Bundle.STOPPING, null);        
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testMissingInstalled() {
+        new RecursiveBundleTracker(null, Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
| Bundle.STOPPING, null);        
+    }
+}



Mime
View raw message