felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1722772 - in /felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest: api/ bundle/
Date Sun, 03 Jan 2016 23:32:03 GMT
Author: pderop
Date: Sun Jan  3 23:32:03 2016
New Revision: 1722772

URL: http://svn.apache.org/viewvc?rev=1722772&view=rev
Log:
FELIX-5153: Added test for 5153 issue.

Added:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5153_StopBeforeUngetServiceTest.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorld.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldService.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldServiceFactory.java
Modified:
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
    felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/Activator.java

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java?rev=1722772&r1=1722771&r2=1722772&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/DiagnosticsTest.java
Sun Jan  3 23:32:03 2016
@@ -35,10 +35,11 @@ import org.apache.felix.dm.itest.util.Te
 
 public class DiagnosticsTest extends TestBase {
 	
-	// there is one TestComponent created by org.apache.felix.dm.itest.bundle
-	// this component is always registered, so we only need to take it into 
+	// there are two components (TestComponent and HelloWorldServiceFactory) created by 
+    // org.apache.felix.dm.itest.bundle
+	// These component is always registered, so we only need to take them into 
 	// account when we build the graph with ALL components
-	private static final int InitialComponentCount = 1;
+	private static final int InitialComponentCount = 2;
 	
 	private boolean checkComponentCount(int expected, int count) {
 		return count == expected + InitialComponentCount;

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5153_StopBeforeUngetServiceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5153_StopBeforeUngetServiceTest.java?rev=1722772&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5153_StopBeforeUngetServiceTest.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5153_StopBeforeUngetServiceTest.java
Sun Jan  3 23:32:03 2016
@@ -0,0 +1,59 @@
+/*
+ * 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.dm.itest.api;
+
+import org.apache.felix.dm.itest.bundle.HelloWorld;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class FELIX5153_StopBeforeUngetServiceTest extends TestBase {
+    public void testCallStopAfterUngetService() throws Throwable {
+        Bundle testBundle = null;
+        
+        try {
+    	    ServiceReference[] refs = context.getServiceReferences(HelloWorld.class.getName(),
"(dm=dm4)");
+    	    HelloWorld service = (HelloWorld) context.getService(refs[0]);
+    	    System.out.println(service.sayIt("DM4"));
+
+    		for (Bundle b : context.getBundles()) {
+    			if (b.getSymbolicName().equals("org.apache.felix.dependencymanager.itest.bundle"))
{
+    				testBundle = b;
+    				// Stop the test bundle. In this test bundle, we have a service factory component,
and its unget method
+    				// is expected to be called *before* its stop() method.
+    				b.stop();
+    				break;
+    			}
+    		}
+    	} 
+    	
+    	catch (Throwable t) {
+    		error("test failed", t);
+    	}
+    	
+    	finally {
+    	    if (testBundle != null) {
+    	        testBundle.start(); // restart the test bundle
+    	    }
+    	}
+    }
+}

Modified: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/Activator.java?rev=1722772&r1=1722771&r2=1722772&view=diff
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/Activator.java
(original)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/Activator.java
Sun Jan  3 23:32:03 2016
@@ -18,6 +18,9 @@
  */
 package org.apache.felix.dm.itest.bundle;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 import org.apache.felix.dm.DependencyActivatorBase;
 import org.apache.felix.dm.DependencyManager;
 import org.osgi.framework.BundleContext;
@@ -28,11 +31,15 @@ import org.osgi.framework.BundleContext;
 public class Activator extends DependencyActivatorBase {
 
 	@Override
-	public void init(BundleContext ctx, DependencyManager m)
-			throws Exception {
+	public void init(BundleContext ctx, DependencyManager m) throws Exception {
 		m.add(createComponent()
-				.setImplementation(TestComponent.class)
-				.setInterface(TestService.class.getName(), null));
+		    .setImplementation(TestComponent.class)
+		    .setInterface(TestService.class.getName(), null));
+		
+        Dictionary<String, Object> props = new Hashtable<>();
+        props.put("dm", "dm4");
+        m.add(createComponent().setInterface(HelloWorld.class.getName(), props)
+         .setImplementation(new HelloWorldServiceFactory()));
 	}
 
 }

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorld.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorld.java?rev=1722772&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorld.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorld.java
Sun Jan  3 23:32:03 2016
@@ -0,0 +1,24 @@
+/*
+ * 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.dm.itest.bundle;
+
+public interface HelloWorld {
+
+	String sayIt(String msg);
+}

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldService.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldService.java?rev=1722772&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldService.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldService.java
Sun Jan  3 23:32:03 2016
@@ -0,0 +1,27 @@
+/*
+ * 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.dm.itest.bundle;
+
+public class HelloWorldService implements HelloWorld {
+
+	@Override
+	public String sayIt(String arg) {
+		return "Hello " + arg;
+	}
+}

Added: felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldServiceFactory.java?rev=1722772&view=auto
==============================================================================
--- felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldServiceFactory.java
(added)
+++ felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/bundle/HelloWorldServiceFactory.java
Sun Jan  3 23:32:03 2016
@@ -0,0 +1,57 @@
+/*
+ * 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.dm.itest.bundle;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class HelloWorldServiceFactory implements ServiceFactory {
+	private final Map<ServiceRegistration, HelloWorldService> m_services = new HashMap<>();
+
+	public void stop() {
+		synchronized (m_services) {
+			if (!m_services.isEmpty()) {
+				throw new IllegalStateException("All services should be closed");
+			}
+		}
+	}
+
+	@Override
+	public HelloWorld getService(Bundle bundle, ServiceRegistration registration) {
+		HelloWorldService service = new HelloWorldService();
+		synchronized (m_services) {
+			HelloWorldService old = m_services.put(registration, service);
+			assert old == null;
+		}
+		return service;
+	}
+
+	@Override
+	public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
{
+		synchronized (m_services) {
+			HelloWorldService old = m_services.remove(registration);
+			HelloWorldService serv = (HelloWorldService) service;
+			assert serv == old;
+		}
+	}
+}



Mime
View raw message