aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jut...@apache.org
Subject [2/3] aries-rsa git commit: [ARIES-1713] TopologyManagerExport fails with multiple interfaces
Date Tue, 11 Apr 2017 11:09:09 GMT
[ARIES-1713] TopologyManagerExport fails with multiple interfaces

if the exported interfaces are not a simple string but a String+ there
was a ClassCastException in shouldExport



Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/33b1e4d2
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/33b1e4d2
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/33b1e4d2

Branch: refs/heads/master
Commit: 33b1e4d282f1af5135768d013e780009d00d405c
Parents: d779ff1
Author: Johannes Utzig <jutzig@apache.org>
Authored: Tue Feb 21 10:03:45 2017 +0100
Committer: Johannes Utzig <jutzig@apache.org>
Committed: Tue Apr 11 13:05:00 2017 +0200

----------------------------------------------------------------------
 .../exporter/TopologyManagerExport.java         | 16 ++---
 .../exporter/TopologyManagerExportTest.java     | 61 +++++++++++++++++---
 2 files changed, 62 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/33b1e4d2/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java
b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java
index 6200a29..0be28a4 100644
--- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java
+++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java
@@ -27,6 +27,7 @@ import java.util.Set;
 import java.util.concurrent.Executor;
 
 import org.apache.aries.rsa.spi.ExportPolicy;
+import org.apache.aries.rsa.util.StringPlus;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
@@ -86,7 +87,7 @@ public class TopologyManagerExport implements ServiceListener {
             export(serviceRef);
         }
     };
-    
+
     public void remove(RemoteServiceAdmin rsa) {
         rsaSet.remove(rsa);
         endpointRepo.removeRemoteServiceAdmin(rsa);
@@ -122,17 +123,18 @@ public class TopologyManagerExport implements ServiceListener {
                 // already handled by this remoteServiceAdmin
                 LOG.debug("already handled by this remoteServiceAdmin -> skipping");
             } else {
-                
+
                 exportServiceUsingRemoteServiceAdmin(sref, remoteServiceAdmin, addProps);
             }
         }
     }
 
     private boolean shouldExport(ServiceReference<?> sref, Map<String, ?> addProps)
{
-        String exported = (String)sref.getProperty(RemoteConstants.SERVICE_EXPORTED_INTERFACES);
-        String addExported = (String)addProps.get(RemoteConstants.SERVICE_EXPORTED_INTERFACES);
-        String effectiveExported = addExported != null ? addExported : exported;
-        return (effectiveExported != null) && !effectiveExported.isEmpty();
+        List<String> exported= StringPlus.normalize(sref.getProperty(RemoteConstants.SERVICE_EXPORTED_INTERFACES));
+        List<String> addExported = StringPlus.normalize(addProps.get(RemoteConstants.SERVICE_EXPORTED_INTERFACES));
+        int length = exported == null ? 0 : exported.size();
+        length += addExported == null ? 0 : addExported.size();
+        return length>0;
     }
 
     private Object getSymbolicName(Bundle bundle) {
@@ -140,7 +142,7 @@ public class TopologyManagerExport implements ServiceListener {
     }
 
     private void exportServiceUsingRemoteServiceAdmin(final ServiceReference<?> sref,
-                                                      final RemoteServiceAdmin remoteServiceAdmin,

+                                                      final RemoteServiceAdmin remoteServiceAdmin,
                                                       Map<String, ?> addProps) {
         // abort if the service was unregistered by the time we got here
         // (we check again at the end, but this optimization saves unnecessary heavy processing)

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/33b1e4d2/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java
----------------------------------------------------------------------
diff --git a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java
b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java
index 4c9d28f..2307566 100644
--- a/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java
+++ b/topology-manager/src/test/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExportTest.java
@@ -20,8 +20,10 @@ package org.apache.aries.rsa.topologymanager.exporter;
 
 import static org.easymock.EasyMock.expectLastCall;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executor;
 
@@ -57,7 +59,7 @@ public class TopologyManagerExportTest {
         final ServiceReference sref = createUserService(c);
         EndpointDescription epd = createEndpoint();
         expectServiceExported(c, rsa, notifier, sref, epd);
-        
+
         c.replay();
         EndpointRepository endpointRepo = new EndpointRepository();
         endpointRepo.setNotifier(notifier);
@@ -67,19 +69,19 @@ public class TopologyManagerExportTest {
         exportManager.add(rsa);
         exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
         c.verify();
-        
+
         c.reset();
         notifier.endpointRemoved(epd, null);
         expectLastCall().once();
         c.replay();
         exportManager.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, sref));
         c.verify();
-        
+
         c.reset();
         c.replay();
         exportManager.serviceChanged(new ServiceEvent(ServiceEvent.MODIFIED, sref));
         c.verify();
-        
+
         c.reset();
         c.replay();
         exportManager.remove(rsa);
@@ -104,13 +106,50 @@ public class TopologyManagerExportTest {
         c.verify();
     }
 
+    @Test
+    public void testExportExistingMultipleInterfaces() throws Exception {
+        IMocksControl c = EasyMock.createControl();
+        RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
+        final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
+        List<String> exportedInterfaces = Arrays.asList("a.b.C","foo.Bar");
+        final ServiceReference sref = createUserService(c, exportedInterfaces);
+        expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
+        c.replay();
+
+        EndpointRepository endpointRepo = new EndpointRepository();
+        endpointRepo.setNotifier(mockEpListenerNotifier);
+        ExportPolicy policy = new DefaultExportPolicy();
+        TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(),
policy);
+        exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
+        exportManager.add(rsa);
+        c.verify();
+    }
+
+    @Test
+    public void testExportExistingNoExportedInterfaces() throws Exception {
+        IMocksControl c = EasyMock.createControl();
+        RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
+        final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
+        String exportedInterfaces = "";
+        final ServiceReference sref = createUserService(c, exportedInterfaces);
+        c.replay();
+
+        EndpointRepository endpointRepo = new EndpointRepository();
+        endpointRepo.setNotifier(mockEpListenerNotifier);
+        ExportPolicy policy = new DefaultExportPolicy();
+        TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(),
policy);
+        exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
+        exportManager.add(rsa);
+        c.verify();
+    }
+
     private void expectServiceExported(IMocksControl c, RemoteServiceAdmin rsa,
                                        final EndpointListener listener,
                                        final ServiceReference sref, EndpointDescription epd)
{
         ExportRegistration exportRegistration = createExportRegistration(c, epd);
         EasyMock.expect(rsa.exportService(EasyMock.same(sref), (Map<String, Object>)EasyMock.anyObject()))
             .andReturn(Collections.singletonList(exportRegistration)).once();
-        listener.endpointAdded(epd, null); 
+        listener.endpointAdded(epd, null);
         EasyMock.expectLastCall().once();
     }
 
@@ -141,13 +180,19 @@ public class TopologyManagerExportTest {
     }
 
     private ServiceReference createUserService(IMocksControl c) {
+        return createUserService(c, "*");
+    }
+
+    private ServiceReference createUserService(IMocksControl c, Object exportedInterfaces)
{
         final ServiceReference sref = c.createMock(ServiceReference.class);
         EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES)))
-            .andReturn("*").anyTimes();
+            .andReturn(exportedInterfaces).anyTimes();
         Bundle srefBundle = c.createMock(Bundle.class);
-        EasyMock.expect(sref.getBundle()).andReturn(srefBundle).atLeastOnce();
+        if(!"".equals(exportedInterfaces)) {
+            EasyMock.expect(sref.getBundle()).andReturn(srefBundle).atLeastOnce();
+            EasyMock.expect(srefBundle.getSymbolicName()).andReturn("serviceBundleName").atLeastOnce();
+        }
         EasyMock.expect(sref.getProperty("objectClass")).andReturn("org.My").anyTimes();
-        EasyMock.expect(srefBundle.getSymbolicName()).andReturn("serviceBundleName").atLeastOnce();
         return sref;
     }
 }


Mime
View raw message