You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by cs...@apache.org on 2013/05/17 09:28:04 UTC
svn commit: r1483673 - in /cxf/dosgi/trunk:
dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/
dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/
dsw/cxf-topology-manager/src/test/java/org/ap...
Author: cschneider
Date: Fri May 17 07:28:03 2013
New Revision: 1483673
URL: http://svn.apache.org/r1483673
Log:
DOSGI-184 Split Endpoint repository from TopologyManagerExport
Added:
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java
- copied, changed from r1483403, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java
Removed:
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java
Modified:
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java Fri May 17 07:28:03 2013
@@ -25,6 +25,7 @@ import java.util.Hashtable;
import java.util.List;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -38,26 +39,33 @@ import org.slf4j.LoggerFactory;
* Tracks EndpointListeners and allows to notify them of endpoints
*/
public class EndpointListenerNotifier {
- private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerNotifier.class);
+ private static final String ENDPOINT_LISTENER_FILTER =
+ "(&(" + Constants.OBJECTCLASS + "=" + EndpointListener.class.getName() + ")"
+ + "(" + EndpointListener.ENDPOINT_LISTENER_SCOPE + "=*))";
+ private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerNotifier.class);
private BundleContext bctx;
private ServiceTracker stEndpointListeners;
- private EndpointRepository exportRepository;
- public EndpointListenerNotifier(BundleContext bctx, EndpointRepository exportRepository) {
+ public EndpointListenerNotifier(BundleContext bctx, final EndpointRepository endpointRepository) {
this.bctx = bctx;
- this.exportRepository = exportRepository;
- this.stEndpointListeners = new ServiceTracker(bctx, EndpointListener.class.getName(), null) {
+ Filter filter;
+ try {
+ filter = bctx.createFilter(ENDPOINT_LISTENER_FILTER);
+ } catch (InvalidSyntaxException e) {
+ throw new RuntimeException("Unexpected exception creating filter", e);
+ }
+ this.stEndpointListeners = new ServiceTracker(bctx, filter, null) {
@Override
public Object addingService(ServiceReference epListenerRef) {
LOG.debug("new EndpointListener detected");
- notifyListenerOfAllExistingExports(epListenerRef);
+ notifyListenerOfAdding(epListenerRef, endpointRepository.getAllEndpoints());
return super.addingService(epListenerRef);
}
@Override
public void modifiedService(ServiceReference epListenerRef, Object service) {
LOG.debug("EndpointListener modified");
- notifyListenerOfAllExistingExports(epListenerRef);
+ notifyListenerOfAdding(epListenerRef, endpointRepository.getAllEndpoints());
super.modifiedService(epListenerRef, service);
}
@@ -73,29 +81,15 @@ public class EndpointListenerNotifier {
stEndpointListeners.close();
}
- private void notifyListenerOfAllExistingExports(
- ServiceReference reference) {
- Collection<EndpointDescription> registrations = exportRepository.getAllEndpoints();
- notifyListenerOfAdding(reference, registrations);
- }
-
void nofifyEndpointListenersOfAdding(Collection<EndpointDescription> endpoints) {
- ServiceReference[] epListeners = getEndpointListeners(bctx);
- for (ServiceReference eplistener : epListeners) {
+ for (ServiceReference eplistener : stEndpointListeners.getServiceReferences()) {
notifyListenerOfAdding(eplistener, endpoints);
}
}
- void notifyAllListenersOfRemoval(Collection<EndpointDescription> endpoints) {
- ServiceReference[] refs = getEndpointListeners(bctx);
- for (ServiceReference epListenerReference : refs) {
- notifyListenersOfRemoval(epListenerReference, endpoints);
- }
- }
-
void notifyListenersOfRemoval(Collection<EndpointDescription> endpoints) {
for (ServiceReference epListenerReference : stEndpointListeners.getServiceReferences()) {
- notifyListenersOfRemoval(epListenerReference, endpoints);
+ notifyListenerOfRemoval(epListenerReference, endpoints);
}
}
@@ -120,7 +114,7 @@ public class EndpointListenerNotifier {
}
- void notifyListenersOfRemoval(ServiceReference epListenerReference,
+ void notifyListenerOfRemoval(ServiceReference epListenerReference,
Collection<EndpointDescription> endpoints) {
EndpointListener epl = (EndpointListener)bctx.getService(epListenerReference);
List<Filter> filters = getFiltersFromEndpointListenerScope(epListenerReference, bctx);
@@ -182,23 +176,6 @@ public class EndpointListenerNotifier {
}
return matchingFilters;
}
-
- /**
- * Find all EndpointListeners; They must have the Scope property otherwise they have to be ignored
- * @param bctx
- * @return
- * @throws InvalidSyntaxException
- */
- private static ServiceReference[] getEndpointListeners(BundleContext bctx) {
- ServiceReference[] result = null;
- try {
- String filter = "(" + EndpointListener.ENDPOINT_LISTENER_SCOPE + "=*)";
- result = bctx.getServiceReferences(EndpointListener.class.getName(), filter);
- } catch (InvalidSyntaxException e) {
- LOG.error(e.getMessage(), e);
- }
- return (result == null) ? new ServiceReference[]{} : result;
- }
/**
* Retrieve endpoint properties as Dictionary
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java Fri May 17 07:28:03 2013
@@ -18,10 +18,93 @@
*/
package org.apache.cxf.dosgi.topologymanager.exporter;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Holds all endpoints that are exported by a TopologyManager.
+ * For each ServiceReference that is exported a map is maintained which contains information
+ * on the endpoints for each RemoteAdminService that created the endpoints
+ */
+public class EndpointRepository {
+ private static final Logger LOG = LoggerFactory.getLogger(EndpointRepository.class);
+
+ private final Map<ServiceReference,
+ Map<RemoteServiceAdmin, Collection<EndpointDescription>>> exportedServices =
+ new LinkedHashMap<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>>();
+
+ /**
+ * Remove all services exported by the given rsa and notify listeners
+ * @param rsa
+ * @return list of removed endpoints
+ */
+ synchronized List<EndpointDescription> removeRemoteServiceAdmin(RemoteServiceAdmin rsa) {
+ List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>();
+ for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices
+ .values()) {
+ if (exports.containsKey(rsa)) {
+ removedEndpoints.addAll(exports.get(rsa));
+ exports.remove(rsa);
+ }
+ }
+ return removedEndpoints;
+ }
+
+ synchronized List<EndpointDescription> removeService(ServiceReference sref) {
+ List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>();
+ if (exportedServices.containsKey(sref)) {
+ Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsas = exportedServices.get(sref);
+ for (Map.Entry<RemoteServiceAdmin, Collection<EndpointDescription>> entry : rsas.entrySet()) {
+ if (entry.getValue() != null) {
+ removedEndpoints.addAll(entry.getValue());
+ }
+ }
+ exportedServices.remove(sref);
+ }
+ return removedEndpoints;
+ }
+
+ synchronized void addService(ServiceReference sref) {
+ LOG.info("TopologyManager: adding service to exportedServices list to export it --- from bundle: "
+ + sref.getBundle().getSymbolicName());
+ exportedServices.put(sref,
+ new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
+ }
+
+ synchronized void addEndpoints(ServiceReference sref, RemoteServiceAdmin rsa, List<EndpointDescription> endpoints) {
+ Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref);
+ exports.put(rsa, endpoints);
+ }
+
+ synchronized boolean isAlreadyExportedForRsa(ServiceReference sref, RemoteServiceAdmin rsa) {
+ Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref);
+ return exports.containsKey(rsa);
+ }
+
+ synchronized Collection<EndpointDescription> getAllEndpoints() {
+ List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+ for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices.values()) {
+ for (Collection<EndpointDescription> regs : exports.values()) {
+ if (regs != null) {
+ endpoints.addAll(regs);
+ }
+ }
+ }
+ return endpoints;
+ }
+
+ synchronized Set<ServiceReference> getServices() {
+ return exportedServices.keySet();
+ }
-public interface EndpointRepository {
- Collection<EndpointDescription> getAllEndpoints();
}
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java Fri May 17 07:28:03 2013
@@ -20,10 +20,7 @@ package org.apache.cxf.dosgi.topologyman
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -55,7 +52,7 @@ import org.slf4j.LoggerFactory;
* <li> When a service is unpublished the EndpointListeners are notified.
* The endpoints are not closed as the ExportRegistration takes care of this
*/
-public class TopologyManagerExport implements EndpointRepository {
+public class TopologyManagerExport {
private static final String DOSGI_SERVICES = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)";
@@ -66,27 +63,22 @@ public class TopologyManagerExport imple
private final ExecutorService execService;
private final RemoteServiceAdminTracker remoteServiceAdminTracker;
private final ServiceListener serviceListener;
-
- /**
- * Holds all services that are exported by this TopologyManager for each ServiceReference that should be
- * exported a map is maintained which contains information on the endpoints for each RemoteAdminService
- */
- private final Map<ServiceReference,
- Map<RemoteServiceAdmin, Collection<EndpointDescription>>> exportedServices =
- new LinkedHashMap<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>>();
+ private final EndpointRepository endpointRepo;
public TopologyManagerExport(BundleContext ctx, RemoteServiceAdminTracker rsaTracker) {
+ endpointRepo = new EndpointRepository();
+ epListenerNotifier = createEndpointListenerNotifier(ctx, endpointRepo);
execService = new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
bctx = ctx;
this.remoteServiceAdminTracker = rsaTracker;
this.remoteServiceAdminTracker.addListener(new RemoteServiceAdminLifeCycleListener() {
-
public void added(RemoteServiceAdmin rsa) {
triggerExportForRemoteServiceAdmin(rsa);
}
public void removed(RemoteServiceAdmin rsa) {
- removeRemoteServiceAdmin(rsa);
+ List<EndpointDescription> endpoints = endpointRepo.removeRemoteServiceAdmin(rsa);
+ epListenerNotifier.notifyListenersOfRemoval(endpoints);
}
});
serviceListener = new ServiceListener() {
@@ -99,12 +91,17 @@ public class TopologyManagerExport imple
}
} else if (event.getType() == ServiceEvent.UNREGISTERING) {
LOG.debug("Received UNREGISTERING ServiceEvent: {}", event);
- removeService(sref);
+ List<EndpointDescription> endpoints = endpointRepo.removeService(sref);
+ epListenerNotifier.notifyListenersOfRemoval(endpoints);
}
}
};
+
- epListenerNotifier = new EndpointListenerNotifier(ctx, this);
+ }
+
+ protected EndpointListenerNotifier createEndpointListenerNotifier(BundleContext ctx, EndpointRepository endpointRepository) {
+ return new EndpointListenerNotifier(ctx, endpointRepository);
}
/**
@@ -114,85 +111,36 @@ public class TopologyManagerExport imple
return sref.getProperty(RemoteConstants.SERVICE_EXPORTED_INTERFACES) != null;
}
- /**
- * Remove all services exported by the given rsa and notify listeners
- * @param rsa
- */
- protected void removeRemoteServiceAdmin(RemoteServiceAdmin rsa) {
- synchronized (exportedServices) {
- for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices
- .values()) {
- if (exports.containsKey(rsa)) {
- Collection<EndpointDescription> endpoints = exports.get(rsa);
- this.epListenerNotifier.notifyAllListenersOfRemoval(endpoints);
- exports.remove(rsa);
- }
- }
- }
- }
-
- protected void triggerExportForRemoteServiceAdmin(RemoteServiceAdmin rsa) {
- LOG.debug("triggerExportImportForRemoteSericeAdmin()");
-
- synchronized (exportedServices) {
- for (ServiceReference serviceRef : exportedServices.keySet()) {
- Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsaExports = exportedServices.get(serviceRef);
- String bundleName = serviceRef.getBundle().getSymbolicName();
- if (rsaExports.containsKey(rsa)) {
- // already handled....
- LOG.debug("service from bundle {} is already handled by this RSA", bundleName);
- } else {
- // trigger export of this service....
- LOG.debug("service from bundle {} is to be exported by this RSA", bundleName);
- exportService(serviceRef);
- }
- }
- }
-
- }
+ protected void triggerExportForRemoteServiceAdmin(RemoteServiceAdmin rsa) {
+ for (ServiceReference serviceRef : endpointRepo.getServices()) {
+ String bundleName = serviceRef.getBundle().getSymbolicName();
+ if (endpointRepo.isAlreadyExportedForRsa(serviceRef, rsa)) {
+ LOG.debug("service from bundle {} is already handled by this RSA", bundleName);
+ } else {
+ LOG.debug("service from bundle {} is to be exported by this RSA", bundleName);
+ exportService(serviceRef);
+ }
+ }
+ }
public void start() {
epListenerNotifier.start();
bctx.addServiceListener(serviceListener);
- remoteServiceAdminTracker.open();
exportExistingServices();
}
public void stop() {
execService.shutdown();
- remoteServiceAdminTracker.close();
bctx.removeServiceListener(serviceListener);
epListenerNotifier.stop();
}
-
- void removeService(ServiceReference sref) {
- synchronized (exportedServices) {
- if (exportedServices.containsKey(sref)) {
- Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsas = exportedServices.get(sref);
- for (Map.Entry<RemoteServiceAdmin, Collection<EndpointDescription>> entry : rsas.entrySet()) {
- if (entry.getValue() != null) {
- Collection<EndpointDescription> registrations = entry.getValue();
- this.epListenerNotifier.notifyListenersOfRemoval(registrations);
- }
- }
-
- exportedServices.remove(sref);
- }
- }
- }
protected void exportService(ServiceReference sref) {
- // add to local list of services that should/are be exported
- synchronized (exportedServices) {
- LOG.info("TopologyManager: adding service to exportedServices list to export it --- from bundle: "
- + sref.getBundle().getSymbolicName());
- exportedServices.put(sref,
- new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
- }
+ endpointRepo.addService(sref);
triggerExport(sref);
}
- private void triggerExport(final ServiceReference sref) {
+ protected void triggerExport(final ServiceReference sref) {
execService.execute(new Runnable() {
public void run() {
doExportService(sref);
@@ -200,32 +148,21 @@ public class TopologyManagerExport imple
});
}
- private void doExportService(final ServiceReference sref) {
+ protected void doExportService(final ServiceReference sref) {
LOG.debug("Exporting service");
-
- Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = null;
-
- synchronized (exportedServices) {
- exports = Collections.synchronizedMap(exportedServices.get(sref));
- }
- // FIXME: Not thread safe...?
- if (exports == null) {
- return;
- }
- if (remoteServiceAdminTracker == null || remoteServiceAdminTracker.size() == 0) {
+ List<RemoteServiceAdmin> rsaList = remoteServiceAdminTracker.getList();
+ if (rsaList.size() == 0) {
LOG.error(
"No RemoteServiceAdmin available! Unable to export service from bundle {}, interfaces: {}",
sref.getBundle().getSymbolicName(),
sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS));
}
-
- for (final RemoteServiceAdmin remoteServiceAdmin : remoteServiceAdminTracker
- .getList()) {
+ for (final RemoteServiceAdmin remoteServiceAdmin : rsaList) {
LOG.info("TopologyManager: handling remoteServiceAdmin "
+ remoteServiceAdmin);
- if (exports.containsKey(remoteServiceAdmin)) {
+ if (endpointRepo.isAlreadyExportedForRsa(sref, remoteServiceAdmin)) {
// already handled by this remoteServiceAdmin
LOG.debug("already handled by this remoteServiceAdmin -> skipping");
} else {
@@ -233,21 +170,18 @@ public class TopologyManagerExport imple
LOG.debug("exporting ...");
Collection<ExportRegistration> exportRegs = remoteServiceAdmin
.exportService(sref, null);
+ List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
if (exportRegs == null) {
// TODO export failed -> What should be done here?
LOG.error("export failed");
- exports.put(remoteServiceAdmin, null);
} else {
- List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
for (ExportRegistration exportReg : exportRegs) {
endpoints.add(getExportedEndpoint(exportReg));
}
LOG.info("TopologyManager: export sucessful Endpoints: {}", endpoints);
- // enqueue in local list of endpoints
- exports.put(remoteServiceAdmin, endpoints);
-
epListenerNotifier.nofifyEndpointListenersOfAdding(endpoints);
}
+ endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
}
}
}
@@ -262,20 +196,6 @@ public class TopologyManagerExport imple
return (ref == null) ? null : ref.getExportedEndpoint();
}
- public Collection<EndpointDescription> getAllEndpoints() {
- List<EndpointDescription> registrations = new ArrayList<EndpointDescription>();
- synchronized (exportedServices) {
- for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices.values()) {
- for (Collection<EndpointDescription> regs : exports.values()) {
- if (regs != null) {
- registrations.addAll(regs);
- }
- }
- }
- }
- return registrations;
- }
-
private void exportExistingServices() {
try {
ServiceReference[] references = bctx.getServiceReferences(null, DOSGI_SERVICES);
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java Fri May 17 07:28:03 2013
@@ -93,7 +93,7 @@ public class EndpointListenerNotifierTes
endpoints.add(epd);
endpoints.add(epd2);
- tm.notifyListenersOfRemoval(sref, endpoints);
+ tm.notifyListenerOfRemoval(sref, endpoints);
c.verify();
EasyMock.verify(epl);
Copied: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java (from r1483403, cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java)
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java?p2=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java&p1=cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java&r1=1483403&r2=1483673&rev=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/ExportServiceTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java Fri May 17 07:28:03 2013
@@ -16,27 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.cxf.dosgi.topologymanager;
+package org.apache.cxf.dosgi.topologymanager.exporter;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
+import org.apache.cxf.dosgi.topologymanager.rsatracker.RemoteServiceAdminLifeCycleListener;
+import org.apache.cxf.dosgi.topologymanager.rsatracker.RemoteServiceAdminTracker;
import org.easymock.IAnswer;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
-import org.osgi.service.remoteserviceadmin.EndpointListener;
import org.osgi.service.remoteserviceadmin.ExportReference;
import org.osgi.service.remoteserviceadmin.ExportRegistration;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -52,139 +50,108 @@ public class ExportServiceTest {
* @throws Exception
*/
@SuppressWarnings("unchecked")
- @Test
+ @Test
public void testServiceExport() throws Exception {
-
- final Semaphore sema = new Semaphore(1);
- sema.acquire();
-
- String scope = "(objectClass=abc)";
-
- IMocksControl c = EasyMock.createNiceControl();
-
+ IMocksControl c = EasyMock.createControl();
BundleContext bctx = c.createMock(BundleContext.class);
-
- Bundle topMgrBundle = c.createMock(Bundle.class);
-
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
- final ServiceReference rsaSref = c.createMock(ServiceReference.class);
- EndpointListener epl = c.createMock(EndpointListener.class);
- final ServiceReference eplSref = c.createMock(ServiceReference.class);
- EasyMock.expect(eplSref.getProperty(EasyMock.same(EndpointListener.ENDPOINT_LISTENER_SCOPE)))
- .andReturn(scope).anyTimes();
- EasyMock.expect(eplSref.getBundle()).andReturn(topMgrBundle).anyTimes();
+ final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
+ mockEpListenerNotifier.start();
+ EasyMock.expectLastCall().once();
+
+ final ServiceReference sref = createUserServiceBundle(c);
+
+ EasyMock.expect(bctx.getServiceReferences(EasyMock.<String>anyObject(), EasyMock.<String>anyObject()))
+ .andReturn(null).atLeastOnce();
+
+ RemoteServiceAdminTracker rsaTracker = createSingleRsaTracker(c, rsa);
+
+ EndpointDescription endpoint = createEndpoint(c);
+ ExportRegistration exportRegistration = createExportRegistration(c, endpoint);
+
+ // Main assertions
+ simulateUserServicePublished(bctx, sref);
+ EasyMock.expect(rsa.exportService(EasyMock.same(sref), (Map<String, Object>)EasyMock.anyObject()))
+ .andReturn(Collections.singletonList(exportRegistration)).once();
+ mockEpListenerNotifier.nofifyEndpointListenersOfAdding(EasyMock.eq(Collections.singletonList(endpoint)));
+ EasyMock.expectLastCall().once();
- final ServiceReference sref = c.createMock(ServiceReference.class);
- EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES)))
- .andReturn("*").anyTimes();
- Bundle srefBundle = c.createMock(Bundle.class);
- EasyMock.expect(sref.getBundle()).andReturn(srefBundle).anyTimes();
-
+ c.replay();
- EndpointDescription endpoint = c.createMock(EndpointDescription.class);
-
- Map<String, Object> props = new HashMap<String, Object>();
- String[] objs = new String[1];
- objs[0] = "abc";
- props.put("objectClass", objs);
- EasyMock.expect(endpoint.getProperties()).andReturn(props).anyTimes();
-
- ExportRegistration exportRegistration = c.createMock(ExportRegistration.class);
- ExportReference exportReference = c.createMock(ExportReference.class);
-
- EasyMock.expect(exportRegistration.getExportReference()).andReturn(exportReference).anyTimes();
- EasyMock.expect(exportReference.getExportedEndpoint()).andReturn(endpoint).anyTimes();
-
- List<ExportRegistration> ret = new ArrayList<ExportRegistration>();
- ret.add(exportRegistration);
- EasyMock.expect(rsa.exportService(EasyMock.same(sref),
- (Map<String, Object>)EasyMock.anyObject())).andReturn(ret)
- .once();
-
- epl.endpointAdded((EndpointDescription)EasyMock.anyObject(), (String)EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
-
- public Object answer() throws Throwable {
- System.out.println("Call made !!!");
- sema.release();
- return null;
- }
-
- }).once();
-
- //BCTX
- bctx.addServiceListener((ServiceListener)EasyMock.anyObject(), (String)EasyMock.anyObject());
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
-
- public Object answer() throws Throwable {
- System.out.println("-> addServiceListener: "
- + EasyMock.getCurrentArguments()[1]);
- ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];
+ TopologyManagerExport topManager = new TopologyManagerExport(bctx, rsaTracker) {
- if ("(objectClass=org.osgi.service.remoteserviceadmin.RemoteServiceAdmin)"
- .equals(EasyMock.getCurrentArguments()[1])) {
- ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, rsaSref);
- sl.serviceChanged(se);
- } else if ("(objectClass=org.osgi.service.remoteserviceadmin.EndpointListener)"
- .equals(EasyMock.getCurrentArguments()[1])) {
- ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, eplSref);
- sl.serviceChanged(se);
- }
+ /**
+ * Replace epListenerNotifier with mock
+ */
+ @Override
+ protected EndpointListenerNotifier createEndpointListenerNotifier(BundleContext ctx,
+ EndpointRepository endpointRepository) {
+ return mockEpListenerNotifier;
+ }
+
+ /**
+ * To avoid async call
+ */
+ @Override
+ protected void triggerExport(ServiceReference sref) {
+ doExportService(sref);
+ }
+
+ };
+ topManager.start();
+ c.verify();
- return null;
- }
- }).anyTimes();
+ }
- bctx.addServiceListener((ServiceListener)EasyMock.anyObject());
+ private void simulateUserServicePublished(BundleContext bctx,
+ final ServiceReference sref) {
+ bctx.addServiceListener((ServiceListener)EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
-
public Object answer() throws Throwable {
- System.out.println("-> addServiceListener ");
-
+ System.out.println("Simulating publishing the user service");
ServiceListener sl = (ServiceListener)EasyMock.getCurrentArguments()[0];
-
ServiceEvent se = new ServiceEvent(ServiceEvent.REGISTERED, sref);
sl.serviceChanged(se);
- se = new ServiceEvent(ServiceEvent.REGISTERED, eplSref);
- sl.serviceChanged(se);
- se = new ServiceEvent(ServiceEvent.REGISTERED, rsaSref);
- sl.serviceChanged(se);
-
return null;
}
- }).anyTimes();
-
- EasyMock.expect(bctx.getService(EasyMock.same(rsaSref))).andReturn(rsa).anyTimes();
- EasyMock.expect(bctx.getService(EasyMock.same(eplSref))).andReturn(epl).atLeastOnce();
-
- ServiceReference[] refs = new ServiceReference[1];
- refs[0] = eplSref;
- EasyMock
- .expect(
- bctx.getServiceReferences(EasyMock.same(EndpointListener.class.getName()),
- EasyMock
- .same("("
- + EndpointListener.ENDPOINT_LISTENER_SCOPE
- + "=*)"))).andReturn(refs).anyTimes();
-
- EasyMock.expect(bctx.createFilter(EasyMock.same(scope)))
- .andReturn(FrameworkUtil.createFilter(scope)).anyTimes();
-
-
- c.replay();
+ }).once();
+ }
- // TopologyManager tm = new TopologyManager(bctx);
- // tm.start();
+ private RemoteServiceAdminTracker createSingleRsaTracker(IMocksControl c,
+ RemoteServiceAdmin rsa) {
+ RemoteServiceAdminTracker rsaTracker = c.createMock(RemoteServiceAdminTracker.class);
+ rsaTracker.addListener(EasyMock.<RemoteServiceAdminLifeCycleListener>anyObject());
+ EasyMock.expectLastCall().once();
+ EasyMock.expect(rsaTracker.getList()).andReturn(Collections.singletonList(rsa));
+ return rsaTracker;
+ }
+
+ private ExportRegistration createExportRegistration(IMocksControl c,
+ EndpointDescription endpoint) {
+ ExportRegistration exportRegistration = c.createMock(ExportRegistration.class);
+ ExportReference exportReference = c.createMock(ExportReference.class);
+ EasyMock.expect(exportRegistration.getExportReference()).andReturn(exportReference).anyTimes();
+ EasyMock.expect(exportReference.getExportedEndpoint()).andReturn(endpoint).anyTimes();
+ return exportRegistration;
+ }
- Activator a = new Activator();
- a.start(bctx);
-
- // Wait until the EndpointListener.endpointAdded call was made as the controlflow is asynchronous
- sema.tryAcquire(30, TimeUnit.SECONDS);
-
- c.verify();
+ private EndpointDescription createEndpoint(IMocksControl c) {
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(RemoteConstants.ENDPOINT_ID, "1");
+ props.put(Constants.OBJECTCLASS, new String[]{"abc"});
+ props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "cxf");
+ return new EndpointDescription(props);
+ }
- }
+ private ServiceReference createUserServiceBundle(IMocksControl c) {
+ final ServiceReference sref = c.createMock(ServiceReference.class);
+ EasyMock.expect(sref.getProperty(EasyMock.same(RemoteConstants.SERVICE_EXPORTED_INTERFACES)))
+ .andReturn("*").anyTimes();
+ Bundle srefBundle = c.createMock(Bundle.class);
+ EasyMock.expect(sref.getBundle()).andReturn(srefBundle).atLeastOnce();
+ EasyMock.expect(srefBundle.getSymbolicName()).andReturn("serviceBundleName").atLeastOnce();
+ return sref;
+ }
}
Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestCustomIntent.java Fri May 17 07:28:03 2013
@@ -76,7 +76,7 @@ public class TestCustomIntent extends Ab
public static Option[] configure() throws Exception {
return new Option[] {
MultiBundleTools.getDistro(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
mavenBundle().groupId("org.apache.servicemix.bundles")
.artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
mavenBundle().groupId("org.apache.cxf.dosgi.samples")
Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportRestService.java Fri May 17 07:28:03 2013
@@ -41,7 +41,7 @@ public class TestExportRestService exten
public static Option[] configure() throws Exception {
return new Option[] {
MultiBundleTools.getDistroWithDiscovery(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
mavenBundle().groupId("org.apache.servicemix.bundles")
.artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
mavenBundle().groupId("org.apache.cxf.dosgi.samples")
Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java?rev=1483673&r1=1483672&r2=1483673&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java (original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java Fri May 17 07:28:03 2013
@@ -57,7 +57,7 @@ public class TestExportService extends A
public static Option[] configure() throws Exception {
return new Option[] {
MultiBundleTools.getDistroWithDiscovery(),
- systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
mavenBundle().groupId("org.apache.servicemix.bundles")
.artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
mavenBundle().groupId("org.apache.cxf.dosgi.samples")