You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by eg...@apache.org on 2008/11/07 11:20:57 UTC
svn commit: r712104 - in /cxf/sandbox/dosgi/felix/framework/src:
main/java/org/apache/felix/framework/
main/java/org/apache/felix/framework/util/ test/ test/java/ test/java/org/
test/java/org/apache/ test/java/org/apache/felix/ test/java/org/apache/fel...
Author: eglynn
Date: Fri Nov 7 02:20:52 2008
New Revision: 712104
URL: http://svn.apache.org/viewvc?rev=712104&view=rev
Log:
[dOSGi] More ListenerHook tests, on behalf of David Bosschaert (CXF-1897)
Added:
cxf/sandbox/dosgi/felix/framework/src/test/
cxf/sandbox/dosgi/felix/framework/src/test/java/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java (with props)
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java (with props)
cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java (with props)
Modified:
cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/Felix.java
cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
Modified: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=712104&r1=712103&r2=712104&view=diff
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/Felix.java Fri Nov 7 02:20:52 2008
@@ -2789,13 +2789,9 @@
releaseBundleLock(bundle);
}
- // TODO: CONCURRENCY - Reconsider firing event here, outside of the
- // bundle lock.
-
// NOTE: The service registered event is fired from the service
// registry to the framework, where it is then redistributed to
// interested service event listeners.
-
if (ListenerHook.class.isAssignableFrom(svcObj.getClass())
&& m_registry.hookRequested(classNames, ListenerHook.class.getName())) {
ListenerHook lHook = (ListenerHook)svcObj;
Modified: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java?rev=712104&r1=712103&r2=712104&view=diff
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java (original)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java Fri Nov 7 02:20:52 2008
@@ -73,7 +73,7 @@
// Pooled requests to avoid memory allocation.
private static final ArrayList m_requestPool = new ArrayList();
- private EventDispatcher(Logger logger)
+ EventDispatcher(Logger logger)
{
m_logger = logger;
}
Added: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java?rev=712104&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java Fri Nov 7 02:20:52 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.felix.framework;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+public class ServiceRegistryHooksTest extends TestCase {
+ private Object getMock(Class<?> clazz) {
+ return Proxy.newProxyInstance(
+ getClass().getClassLoader(), new Class [] {clazz},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ if (method.getName().equals("equals")) {
+ return proxy == args[0];
+ } else if (method.getName().equals("hashCode")) {
+ return System.identityHashCode(proxy);
+ }
+ return null;
+ }
+ });
+ }
+
+ public void testServiceRegistryHooks() {
+ ServiceRegistry sr = new ServiceRegistry(null);
+
+ Bundle b = (Bundle) getMock(Bundle.class);
+
+ TestListenerHook lh = new TestListenerHook();
+ sr.registerService(b, new String [] {ListenerHook.class.getName()}, lh, new Hashtable());
+
+ assertEquals(1, sr.getListenerHooks().size());
+ assertSame(lh, sr.getListenerHooks().get(0));
+
+ String abcService = "abcService";
+ sr.registerService(b, new String [] {CharSequence.class.getName()}, abcService, new Hashtable());
+ assertEquals("Should not have registered abcService as a listenerHook",
+ 1, sr.getListenerHooks().size());
+ assertSame(lh, sr.getListenerHooks().get(0));
+
+ sr.removeHook(abcService);
+ assertEquals("RemoveHook on a non-hook object shoud have no effect",
+ 1, sr.getListenerHooks().size());
+ assertSame(lh, sr.getListenerHooks().get(0));
+
+ sr.removeHook(lh);
+ assertEquals("Hook should have been removed", 0, sr.getListenerHooks().size());
+ }
+
+ private static class TestListenerHook implements ListenerHook {
+ public void added(Collection listeners) {
+ }
+
+ public void removed(Collection listener) {
+ }
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/ServiceRegistryHooksTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java?rev=712104&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java Fri Nov 7 02:20:52 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.felix.framework.util;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.felix.framework.FilterImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.hooks.service.ListenerHook;
+
+public class EventDispatcherTest extends TestCase {
+ private Object getMock(Class<?> clazz) {
+ return Proxy.newProxyInstance(
+ getClass().getClassLoader(), new Class [] {clazz},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ if (method.getName().equals("equals")) {
+ return proxy == args[0];
+ }
+ return null;
+ }
+ });
+ }
+
+ public void testWrapAllServiceListeners() throws Exception {
+ EventDispatcher ed = new EventDispatcher(null) {};
+ String f1 = "(objectClass=org.example.Blah)";
+ String f2 = "(&(objectClass=org.example.boo)(osgi.remote=true))";
+
+ Bundle b = (Bundle) getMock(Bundle.class);
+ ServiceListener sl = (ServiceListener) getMock(ServiceListener.class);
+ ServiceListener sl2 = (ServiceListener) getMock(ServiceListener.class);
+ ed.addListener(b, ServiceListener.class, sl, new FilterImpl(f1));
+ ed.addListener(b, ServiceListener.class, sl2, new FilterImpl(f2));
+ List<ListenerHook.ListenerInfo> listenerInfos =
+ new ArrayList<ListenerHook.ListenerInfo>(ed.wrapAllServiceListeners());
+ assertEquals(2, listenerInfos.size());
+ assertEquals(f1, listenerInfos.get(0).getFilter());
+ assertEquals(f2, listenerInfos.get(1).getFilter());
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java?rev=712104&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java Fri Nov 7 02:20:52 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.felix.framework.util;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import junit.framework.TestCase;
+
+import org.osgi.framework.BundleContext;
+
+public class ListenerHookInfoImplTest extends TestCase {
+ private Object getMock(Class<?> clazz) {
+ return Proxy.newProxyInstance(
+ getClass().getClassLoader(), new Class [] {BundleContext.class},
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ return null;
+ }
+ });
+ }
+
+ public void testListenerHookInfoImpl() {
+ // Just create a dummy bundle context for testing...
+ BundleContext bc = (BundleContext) getMock(BundleContext.class);
+
+ String filter = "(objectClass=a.b.c.MyClass)";
+ ListenerHookInfoImpl lhi = new ListenerHookInfoImpl(bc, filter);
+
+ assertSame(bc, lhi.getBundleContext());
+ assertEquals(filter, lhi.getFilter());
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/test/java/org/apache/felix/framework/util/ListenerHookInfoImplTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date