Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 55925 invoked from network); 7 Nov 2008 10:21:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Nov 2008 10:21:30 -0000 Received: (qmail 8938 invoked by uid 500); 7 Nov 2008 10:21:30 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 7814 invoked by uid 500); 7 Nov 2008 10:21:28 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 7783 invoked by uid 99); 7 Nov 2008 10:21:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Nov 2008 02:21:28 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Nov 2008 10:20:18 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 54E382388979; Fri, 7 Nov 2008 02:21:00 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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... Date: Fri, 07 Nov 2008 10:20:57 -0000 To: commits@cxf.apache.org From: eglynn@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081107102100.54E382388979@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 listenerInfos = + new ArrayList(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