You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2014/03/03 00:49:13 UTC
svn commit: r1573407 - in
/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it:
FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java
MultipleServiceDependencyTest.java
Author: pderop
Date: Sun Mar 2 23:49:13 2014
New Revision: 1573407
URL: http://svn.apache.org/r1573407
Log:
added more tests from old dm codebase
Added:
felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java
felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/MultipleServiceDependencyTest.java
Added: felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java?rev=1573407&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/FELIX3337_UpdatedConfigurationDependencyWithPropagationTest.java Sun Mar 2 23:49:13 2014
@@ -0,0 +1,147 @@
+/*
+ * 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 dm.it;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+import dm.Component;
+import dm.DependencyManager;
+
+
+/**
+ * This test validates the following scenario:
+ * - Service S1 depends on a ConfigurationDependency with propagate = true
+ * - Service S2 depends on S1 (and has access to the S1 configuration using the S1 service
+ * properties (because the ConfigurationDependency is propagated)
+ * - then the S1 PID is updated from ConfigAdmin
+ * - S1 is then called in its updated callback
+ * - S2 is called in its "change" callback.
+ */
+public class FELIX3337_UpdatedConfigurationDependencyWithPropagationTest extends TestBase {
+ /*
+ * This Pojo creates the configuration pid "test".
+ */
+ static class ConfigurationCreator {
+ private volatile ConfigurationAdmin m_ca;
+ org.osgi.service.cm.Configuration m_conf;
+
+ public void init() {
+ try {
+ m_conf = m_ca.getConfiguration("test", null);
+ Hashtable props = new Properties();
+ props.put("testkey", "testvalue");
+ m_conf.update(props);
+ }
+ catch (IOException e) {
+ Assert.fail("Could not create configuration: " + e.getMessage());
+ }
+ }
+
+ public void update() {
+ try {
+ Hashtable props = new Properties();
+ props.put("testkey", "testvalue");
+ props.put("testkey2", "testvalue2");
+ m_conf.update(props);
+ } catch (IOException e) {
+ Assert.fail("Could not update the configured property: " + e.toString());
+ }
+ }
+ }
+
+ static class S1 implements ManagedService {
+ private Ensure m_ensure;
+ private boolean m_initialized;
+
+ public S1(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void updated(Dictionary props) throws ConfigurationException {
+ if (props != null) {
+ if (!m_initialized) {
+ m_ensure.step(1);
+ m_initialized = true;
+ } else {
+ // we are updated
+ m_ensure.step(3);
+ }
+ }
+ }
+ }
+
+ static class S2 {
+ private final Ensure m_ensure;
+
+ public S2(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void add(S1 s1) {
+ m_ensure.step(2);
+ }
+
+ public void change(S1 runnable) {
+ m_ensure.step(4);
+ }
+ }
+
+ public void testComponentWithRequiredUpdatedConfigurationAndServicePropertyPropagation() {
+ DependencyManager m = new DependencyManager(context);
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+ ConfigurationCreator confCreator = new ConfigurationCreator();
+ Component s1 = m.createComponent()
+ .setImplementation(new S1(e))
+ .setInterface(S1.class.getName(), null)
+ .add(m.createConfigurationDependency()
+ .setPid("test")
+ .setPropagate(true));
+ Component s2 = m.createComponent()
+ .setImplementation(new S2(e))
+ .add(m.createServiceDependency()
+ .setService(S1.class, ("(testkey=testvalue)"))
+ .setRequired(true)
+ .setCallbacks("add", "change", null));
+ Component s3 = m.createComponent()
+ .setImplementation(confCreator)
+ .add(m.createServiceDependency()
+ .setService(ConfigurationAdmin.class)
+ .setRequired(true));
+
+ m.add(s1);
+ m.add(s2);
+ m.add(s3);
+ e.waitForStep(2, 5000);
+ confCreator.update();
+ e.waitForStep(4, 5000);
+ m.remove(s1);
+ m.remove(s2);
+ m.remove(s3);
+ }
+}
Added: felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/MultipleServiceDependencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/MultipleServiceDependencyTest.java?rev=1573407&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/MultipleServiceDependencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager-prototype/dm.it/src/dm/it/MultipleServiceDependencyTest.java Sun Mar 2 23:49:13 2014
@@ -0,0 +1,142 @@
+/*
+ * 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 dm.it;
+
+import java.util.Properties;
+
+import org.osgi.framework.Constants;
+
+import dm.Component;
+import dm.DependencyManager;
+
+public class MultipleServiceDependencyTest extends TestBase {
+ public void testMultipleServiceRegistrationAndConsumption() {
+ DependencyManager m = new DependencyManager(context);
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+ // create a service provider and consumer
+ Component provider = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
+ Component providerWithHighRank = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), new Properties() {{ put(Constants.SERVICE_RANKING, Integer.valueOf(5)); }});
+ Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+ m.add(provider);
+ m.add(providerWithHighRank);
+ m.add(consumer);
+ e.waitForStep(3, 5000);
+ m.remove(providerWithHighRank);
+ e.step(4);
+ e.waitForStep(5, 5000);
+ m.remove(provider);
+ m.remove(consumer);
+ e.waitForStep(6, 5000);
+ }
+
+ public void testReplacementAutoConfig() {
+ DependencyManager m = new DependencyManager(context);
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+ // create a service provider and consumer
+ Component provider = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
+ Component provider2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), null);
+ Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+ m.add(provider2);
+ m.add(consumer);
+ e.waitForStep(3, 5000);
+ m.add(provider);
+ m.remove(provider2);
+ e.step(4);
+ e.waitForStep(5, 5000);
+ m.remove(provider);
+ m.remove(consumer);
+ e.waitForStep(6, 5000);
+ }
+
+ public void testReplacementCallbacks() {
+ DependencyManager m = new DependencyManager(context);
+ // helper class that ensures certain steps get executed in sequence
+ Ensure e = new Ensure();
+ // create a service provider and consumer
+ Component provider = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
+ Component provider2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), null);
+ Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e))
+ .add(m.createServiceDependency()
+ .setService(ServiceInterface.class)
+ .setRequired(true)
+ .setCallbacks("add", "remove"));
+ m.add(provider2);
+ m.add(consumer);
+ e.waitForStep(3, 15000);
+ m.add(provider);
+ m.remove(provider2);
+ e.step(4);
+ e.waitForStep(5, 15000);
+ m.remove(provider);
+ m.remove(consumer);
+ e.waitForStep(6, 15000);
+ }
+
+ static interface ServiceInterface {
+ public void invoke();
+ }
+
+ static class ServiceProvider implements ServiceInterface {
+ private final Ensure m_ensure;
+ public ServiceProvider(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(5);
+ }
+ }
+
+ static class ServiceProvider2 implements ServiceInterface {
+ private final Ensure m_ensure;
+ public ServiceProvider2(Ensure e) {
+ m_ensure = e;
+ }
+ public void invoke() {
+ m_ensure.step(2);
+ }
+ }
+
+ static class ServiceConsumer implements Runnable {
+ private volatile ServiceInterface m_service;
+ private final Ensure m_ensure;
+
+ private void add(ServiceInterface service) { m_service = service; }
+ private void remove(ServiceInterface service) { if (m_service == service) { m_service = null; }};
+ public ServiceConsumer(Ensure e) { m_ensure = e; }
+
+ public void start() {
+ Thread t = new Thread(this);
+ t.start();
+ }
+
+ public void run() {
+ m_ensure.step(1);
+ m_service.invoke();
+ m_ensure.step(3);
+ m_ensure.waitForStep(4, 15000);
+ m_service.invoke();
+ }
+
+ public void stop() {
+ m_ensure.step(6);
+ }
+ }
+}