diff options
author | Thomas Watson | 2014-04-28 14:40:40 +0000 |
---|---|---|
committer | Thomas Watson | 2014-04-28 14:40:40 +0000 |
commit | df0a2bd47e475887ab02be8ae9f7c76f77e06bbd (patch) | |
tree | 4f2b47cd74125c5314c41ec6012ec8ba7f205f96 | |
parent | 6b09ecff786fa3c9f7e970b90562a23e201609a9 (diff) | |
download | rt.equinox.framework-df0a2bd47e475887ab02be8ae9f7c76f77e06bbd.tar.gz rt.equinox.framework-df0a2bd47e475887ab02be8ae9f7c76f77e06bbd.tar.xz rt.equinox.framework-df0a2bd47e475887ab02be8ae9f7c76f77e06bbd.zip |
Bug 433661 - Consider a warning when service ranking is set to a
non-integer
3 files changed, 58 insertions, 5 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java index a93f31758..5de8e206b 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/serviceregistry/ServiceRegistryTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 IBM Corporation and others. + * Copyright (c) 2008, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,8 @@ package org.eclipse.osgi.tests.serviceregistry; import java.util.Hashtable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.osgi.tests.OSGiTestsActivator; @@ -481,6 +483,46 @@ public class ServiceRegistryTests extends AbstractBundleTests { } } + public void testInvalidRanking() { + final CountDownLatch warning = new CountDownLatch(1); + FrameworkListener warningListener = new FrameworkListener() { + + @Override + public void frameworkEvent(FrameworkEvent event) { + if (FrameworkEvent.WARNING == event.getType() && OSGiTestsActivator.getContext().getBundle().equals(event.getBundle())) { + warning.countDown(); + } + } + }; + Runnable runIt = new Runnable() { + + @Override + public void run() { + // nothing + } + }; + Hashtable props = new Hashtable(); + props.put(getName(), Boolean.TRUE); + props.put(Constants.SERVICE_RANKING, "15"); + ServiceRegistration reg1 = null; + try { + OSGiTestsActivator.getContext().addFrameworkListener(warningListener); + reg1 = getContext().registerService(Runnable.class.getName(), runIt, props); + } finally { + if (reg1 != null) { + reg1.unregister(); + } + OSGiTestsActivator.getContext().removeFrameworkListener(warningListener); + } + + try { + assertTrue("Timeout waiting for the warning.", warning.await(5, TimeUnit.SECONDS)); + } catch (InterruptedException e) { + fail("Interrupted.", e); + } + + } + private void clearResults(boolean[] results) { for (int i = 0; i < results.length; i++) results[i] = false; diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java index dedc6d063..18c3c181d 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistrationImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2013 IBM Corporation and others. + * Copyright (c) 2003, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -316,9 +316,16 @@ public class ServiceRegistrationImpl<S> implements ServiceRegistration<S>, Compa } props.set(Constants.SERVICE_SCOPE, scope, true); props.setReadOnly(); - Object ranking = props.getProperty(Constants.SERVICE_RANKING); - serviceranking = (ranking instanceof Integer) ? ((Integer) ranking).intValue() : 0; + Object ranking = props.getProperty(Constants.SERVICE_RANKING); + if (ranking instanceof Integer) { + serviceranking = ((Integer) ranking).intValue(); + } else { + serviceranking = 0; + if (ranking != null) { + registry.getContainer().getEventPublisher().publishFrameworkEvent(FrameworkEvent.WARNING, getBundle(), new ServiceException("Invalid ranking type: " + ranking.getClass(), ServiceException.UNSPECIFIED)); //$NON-NLS-1$ + } + } return props; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java index edcdf4e7a..c16852de3 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/serviceregistry/ServiceRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2013 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1395,4 +1395,8 @@ public class ServiceRegistry { } }); } + + final EquinoxContainer getContainer() { + return container; + } } |