Repository: karaf
Updated Branches:
  refs/heads/master bcca6b3cc -> 143017008


[KARAF-5123] Add test for issue


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/14301700
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/14301700
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/14301700

Branch: refs/heads/master
Commit: 14301700887d23766659072af3726b68ec7f09b7
Parents: bcca6b3
Author: Christian Schneider <[email protected]>
Authored: Fri May 26 17:52:06 2017 +0200
Committer: Christian Schneider <[email protected]>
Committed: Fri May 26 17:52:06 2017 +0200

----------------------------------------------------------------------
 .../features/internal/region/DigraphHelper.java | 10 ++-
 .../internal/service/FeaturesServiceImpl.java   |  6 +-
 .../service/FeaturesServiceImplTest.java        | 79 +++++++++++++++-----
 .../features/internal/service/remove/a.xml      | 23 ++++++
 .../features/internal/service/remove/b.xml      | 22 ++++++
 5 files changed, 115 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/14301700/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
----------------------------------------------------------------------
diff --git 
a/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
 
b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
index 5706fc8..805e21e 100644
--- 
a/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
+++ 
b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
@@ -160,15 +160,19 @@ public final class DigraphHelper {
 
     public static Map<String, Set<Long>> getBundlesPerRegion(RegionDigraph 
digraph) {
         Map<String, Set<Long>> bundlesPerRegion = new HashMap<>();
-        for (Region region : digraph.getRegions()) {
-            bundlesPerRegion.put(region.getName(), new 
HashSet<>(region.getBundleIds()));
+        if (digraph != null) {
+            for (Region region : digraph.getRegions()) {
+                bundlesPerRegion.put(region.getName(), new 
HashSet<>(region.getBundleIds()));
+            }
         }
         return bundlesPerRegion;
     }
     
     public static Map<String, Map<String, Map<String, Set<String>>>> 
getPolicies(RegionDigraph digraph) {
         Map<String, Map<String, Map<String, Set<String>>>> filtersPerRegion = 
new HashMap<>();
-        
+        if (digraph == null) {
+            return filtersPerRegion;
+        }
         for (Region region : digraph.getRegions()) {
             Map<String, Map<String, Set<String>>> edges = new HashMap<>();
             for (RegionDigraph.FilteredRegion fr : digraph.getEdges(region)) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/14301700/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
 
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 65e19ec..2cf14ce 100644
--- 
a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ 
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -946,10 +946,8 @@ public class FeaturesServiceImpl implements 
FeaturesService, Deployer.DeployCall
             }
         }
         RegionDigraph regionDigraph = installSupport.getDiGraphCopy();
-        if (regionDigraph != null) {
-            dstate.bundlesPerRegion = 
DigraphHelper.getBundlesPerRegion(regionDigraph);
-            dstate.filtersPerRegion = DigraphHelper.getPolicies(regionDigraph);
-        }
+        dstate.bundlesPerRegion = 
DigraphHelper.getBundlesPerRegion(regionDigraph);
+        dstate.filtersPerRegion = DigraphHelper.getPolicies(regionDigraph);
         return dstate;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/14301700/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
----------------------------------------------------------------------
diff --git 
a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
 
b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
index 8ff215a..999016c 100644
--- 
a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
+++ 
b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
@@ -22,22 +22,30 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.net.*;
+import java.util.EnumSet;
 import java.util.Map;
 
 import org.apache.felix.resolver.ResolverImpl;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.TestBase;
+import org.apache.karaf.features.FeaturesService.Option;
 import org.apache.karaf.features.internal.resolver.Slf4jResolverLog;
+import 
org.apache.karaf.features.internal.service.BundleInstallSupport.FrameworkInfo;
 import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.service.resolver.Resolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.easymock.EasyMock.expect;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Test cases for {@link 
org.apache.karaf.features.internal.service.FeaturesServiceImpl}
@@ -51,6 +59,19 @@ public class FeaturesServiceImplTest extends TestBase {
     @Before
     public void setUp() throws IOException {
         dataFile = File.createTempFile("features", null, null);
+        URL.setURLStreamHandlerFactory(protocol -> protocol.equals("custom") ? 
new URLStreamHandler() {
+            @Override
+            protected URLConnection openConnection(URL u) throws IOException {
+                return getClass().getResource(u.getPath()).openConnection();
+            }
+        } : null);
+    }
+    
+    @After
+    public void after() throws Exception {
+        Field field = URL.class.getDeclaredField("factory");
+        field.setAccessible(true);
+        field.set(null, null);
     }
 
     @Test
@@ -116,26 +137,48 @@ public class FeaturesServiceImplTest extends TestBase {
 
     @Test
     public void testCyclicFeatures() throws Exception {
-        URL.setURLStreamHandlerFactory(protocol -> protocol.equals("custom") ? 
new URLStreamHandler() {
-            @Override
-            protected URLConnection openConnection(URL u) throws IOException {
-                return getClass().getResource(u.getPath()).openConnection();
-            }
-        } : null);
-        try {
-            FeaturesServiceConfig cfg = new FeaturesServiceConfig();
-            BundleInstallSupport installSupport = 
EasyMock.niceMock(BundleInstallSupport.class);
-            EasyMock.replay(installSupport);
-            final FeaturesServiceImpl impl = new FeaturesServiceImpl(new 
Storage(), null, null, this.resolver, installSupport, null, cfg);
-            impl.addRepository(URI.create("custom:cycle/a-references-b.xml"));
-            impl.getFeatures();
-        } finally {
-            Field field = URL.class.getDeclaredField("factory");
-            field.setAccessible(true);
-            field.set(null, null);
-        }
+        FeaturesServiceConfig cfg = new FeaturesServiceConfig();
+        BundleInstallSupport installSupport = 
EasyMock.niceMock(BundleInstallSupport.class);
+        EasyMock.replay(installSupport);
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(new 
Storage(), null, null, this.resolver, installSupport, null, cfg);
+        impl.addRepository(URI.create("custom:cycle/a-references-b.xml"));
+        impl.getFeatures();
     }
 
+    @Test
+    public void testRemoveRepo() throws Exception {
+        FeaturesServiceConfig cfg = new FeaturesServiceConfig();
+        BundleInstallSupport installSupport = 
EasyMock.niceMock(BundleInstallSupport.class);
+        FrameworkInfo dummyInfo = new FrameworkInfo();
+        expect(installSupport.getInfo()).andReturn(dummyInfo).atLeastOnce();
+        EasyMock.replay(installSupport);
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(new 
Storage(), null, null, this.resolver,
+                                                                 
installSupport, null, cfg);
+        URI activemqRepo = URI.create("custom:remove/a.xml");
+        impl.addRepository(activemqRepo);
+        Feature a1Feature = impl.getFeature("a1");
+        installFeature(impl, a1Feature);
+        Feature b1Feature = impl.getFeature("b1");
+        installFeature(impl, b1Feature);
+        impl.removeRepository(activemqRepo);
+        assertFalse("a1 feature should not be installed anymore after removal 
of repo",
+                    impl.isInstalled(a1Feature));
+        /*
+        assertFalse("b1 feature should not be installed anymore after removal 
of repo",
+                    impl.isInstalled(b1Feature));
+        */
+        assertTrue("b1 feature still present -> issue KARAF-5123 is not yet 
fixed",
+                    impl.isInstalled(b1Feature));
+    }
+
+    private void installFeature(final FeaturesServiceImpl impl, Feature 
a1Feature)
+        throws Exception, InterruptedException {
+        impl.installFeature(a1Feature, EnumSet.noneOf(Option.class));
+        while (!impl.isInstalled(a1Feature)) {
+            Thread.sleep(100);
+        }
+    }
+    
     /**
      * This test ensures that every feature get installed only once, even if 
it appears multiple times in the list
      * of transitive feature dependencies (KARAF-1600)

http://git-wip-us.apache.org/repos/asf/karaf/blob/14301700/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/a.xml
----------------------------------------------------------------------
diff --git 
a/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/a.xml
 
b/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/a.xml
new file mode 100644
index 0000000..cfde69f
--- /dev/null
+++ 
b/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/a.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"; 
name="a-references-b">
+    <repository>custom:remove/b.xml</repository>
+    <feature name="a1" version="1.0.0.SNAPSHOT">
+    </feature>
+</features>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf/blob/14301700/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/b.xml
----------------------------------------------------------------------
diff --git 
a/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/b.xml
 
b/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/b.xml
new file mode 100644
index 0000000..e640f86
--- /dev/null
+++ 
b/features/core/src/test/resources/org/apache/karaf/features/internal/service/remove/b.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    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.
+-->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"; 
name="b-references-c">
+    <feature name="b1" version="1.0.0.SNAPSHOT">
+    </feature>
+</features>
\ No newline at end of file

Reply via email to