This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new 347ee75946 FELIX-6470 : ConfigAdmin/Coordinator handling not optimal
347ee75946 is described below

commit 347ee7594695b3195d672ff568158cb69e16ea77
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Oct 25 17:38:31 2022 +0200

    FELIX-6470 : ConfigAdmin/Coordinator handling not optimal
---
 .../cm/integration/CoordinatorIntegrationTest.java | 235 ++++++++++-----------
 1 file changed, 116 insertions(+), 119 deletions(-)

diff --git 
a/configadmin/src/test/java/org/apache/felix/cm/integration/CoordinatorIntegrationTest.java
 
b/configadmin/src/test/java/org/apache/felix/cm/integration/CoordinatorIntegrationTest.java
index c3422d6e52..e765f89ba4 100644
--- 
a/configadmin/src/test/java/org/apache/felix/cm/integration/CoordinatorIntegrationTest.java
+++ 
b/configadmin/src/test/java/org/apache/felix/cm/integration/CoordinatorIntegrationTest.java
@@ -48,124 +48,121 @@ import org.osgi.service.coordinator.Coordinator;
 @RunWith(PaxExam.class)
 public class CoordinatorIntegrationTest extends ConfigurationTestBase {
 
-       @Override
-       protected Option[] additionalConfiguration() {
-               return new Option [] {
-                       mavenBundle("org.apache.felix", 
"org.apache.felix.coordinator", "1.0.2")
-               };
-       }
-
-       <T> T getService(Class<T> cls) {
-               ServiceReference<T> sref = 
bundleContext.getServiceReference(cls);
-               if (sref == null)
-                       return null;
-
-               return bundleContext.getService(sref);
-       }
-
-       void sleep() throws InterruptedException {
-               TimeUnit.MILLISECONDS.sleep(4000);
-       }
-
-       @Test
-       public void 
test_deliver_existing_Configuration_to_later_registered_ManagedService()
-       throws Exception {
-               ConfigurationAdmin cm = getService(ConfigurationAdmin.class);
-               Coordinator c = getService(Coordinator.class);
-               Coordination coord = c.begin("cm-test1", 0);
-               final List<String> events = new ArrayList<>();
-
-               String pid = getClass().getName() + ".mstestpid2";
-
-               try {
-                       // create the configuration
-                       Dictionary<String,Object> props = new Hashtable<>();
-                       props.put("key", "value");
-
-                       Configuration conf = cm.getConfiguration(pid);
-                       conf.update(props);
-
-                       // add managed service
-                       Dictionary<String,Object> msProps = new Hashtable<>();
-                       msProps.put(Constants.SERVICE_PID, pid);
-
-                       
bundleContext.registerService(ManagedService.class.getName(),
-                                       new ManagedService() {
-
-                                               @Override
-                                               public void 
updated(Dictionary<String, ? > properties)
-                                                               throws 
ConfigurationException {
-                                                       
events.add((String)properties.get("key2"));
-                                               }
-
-                                       }, msProps);
-
-                       // update configuration
-                       props.put("key2", "value2");
-                       conf.update(props);
-
-                       assertEquals(0, events.size());
-               } finally {
-                       coord.end();
-               }
-
-               // wait and verify listener
-               sleep();
-
-               assertEquals(1, events.size());
-        // last update
-               assertEquals("value2", events.get(0));
-       }
-
-       @Test
-       public void test_create_managedservice_delete()
-       throws Exception {
-               ConfigurationAdmin cm = getService(ConfigurationAdmin.class);
-               Coordinator c = getService(Coordinator.class);
-               Coordination coord = c.begin("cm-test1", 0);
-               final List<Boolean> events = new ArrayList<>();
-
-               String pid = getClass().getName() + ".mstestpid3";
-
-               try {
-                       // create the configuration
-                       Dictionary<String,Object> props = new Hashtable<>();
-                       props.put("key", "value");
-
-                       Configuration conf = cm.getConfiguration(pid);
-                       conf.update(props);
-
-                       // add managed service
-                       Dictionary<String,Object> msProps = new Hashtable<>();
-                       msProps.put(Constants.SERVICE_PID, pid);
-
-                       
bundleContext.registerService(ManagedService.class.getName(),
-                                       new ManagedService() {
-
-                                               @Override
-                                               public void 
updated(Dictionary<String, ? > properties)
-                                                               throws 
ConfigurationException {
-                                                       events.add(properties 
!= null);
-                                               }
-
-                                       }, msProps);
-
-                       // update configuration
-                       props.put("key2", "value2");
-                       conf.update(props);
+    @Override
+    protected Option[] additionalConfiguration() {
+        return new Option [] {
+            mavenBundle("org.apache.felix", "org.apache.felix.coordinator", 
"1.0.2")
+        };
+    }
+
+    Coordinator getCoordinatorService() {
+        final ServiceReference<Coordinator> sref = 
bundleContext.getServiceReference(Coordinator.class);
+        return bundleContext.getService(sref);
+    }
+
+    void sleep() throws InterruptedException {
+        TimeUnit.MILLISECONDS.sleep(3000);
+    }
+
+    @Test
+    public void 
test_deliver_existing_Configuration_to_later_registered_ManagedService()
+    throws Exception {
+        final ConfigurationAdmin cm = this.getConfigurationAdmin();
+        final Coordinator c = this.getCoordinatorService();
+        final Coordination coord = c.begin("cm-test1", 0);
+        final List<String> events = new ArrayList<>();
+
+        final String pid = getClass().getName() + ".mstestpid1";
+
+        try {
+            // create the configuration
+            final Dictionary<String,Object> props = new Hashtable<>();
+            props.put("key", "value");
+
+            final Configuration conf = cm.getConfiguration(pid);
+            conf.update(props);
+
+               // add managed service
+            final Dictionary<String,Object> msProps = new Hashtable<>();
+            msProps.put(Constants.SERVICE_PID, pid);
+
+            bundleContext.registerService(ManagedService.class.getName(),
+                new ManagedService() {
+
+                    @Override
+                    public void updated(Dictionary<String, ? > properties)
+                    throws ConfigurationException {
+                        events.add((String)properties.get("key2"));
+                    }
+
+                }, msProps);
+
+            // update configuration
+            props.put("key2", "value2");
+            conf.update(props);
+
+            assertEquals(0, events.size());
+        } finally {
+            coord.end();
+        }
+
+        // wait and verify listener
+        sleep();
+
+        assertEquals(1, events.size());
+        // last update only
+        assertEquals("value2", events.get(0));
+    }
+
+    @Test
+    public void test_create_managedservice_delete()
+    throws Exception {
+        final ConfigurationAdmin cm = this.getConfigurationAdmin();
+        final Coordinator c = this.getCoordinatorService();
+        final Coordination coord = c.begin("cm-test2", 0);
+        final List<Boolean> events = new ArrayList<>();
+
+        final String pid = getClass().getName() + ".mstestpid2";
+
+        try {
+            // create the configuration
+            final Dictionary<String,Object> props = new Hashtable<>();
+            props.put("key", "value");
+
+            final Configuration conf = cm.getConfiguration(pid);
+            conf.update(props);
+
+            // add managed service
+            final Dictionary<String,Object> msProps = new Hashtable<>();
+            msProps.put(Constants.SERVICE_PID, pid);
+
+            bundleContext.registerService(ManagedService.class.getName(),
+                new ManagedService() {
+
+                    @Override
+                    public void updated(Dictionary<String, ? > properties)
+                    throws ConfigurationException {
+                        events.add(properties != null);
+                    }
+
+                }, msProps);
+
+            // update configuration
+            props.put("key2", "value2");
+            conf.update(props);
+
+            // delete configuration
+            conf.delete();
+
+            assertEquals(0, events.size());
+        } finally {
+            coord.end();
+        }
 
-                       // delete configuration
-                       conf.delete();
-
-                       assertEquals(0, events.size());
-               } finally {
-                       coord.end();
-               }
-
-               // wait and verify listener
-               sleep();
-
-               assertEquals(1, events.size());
-               assertFalse(events.get(0));// no configuration, update with null
-       }
+        // wait and verify listener
+        sleep();
+
+        assertEquals(1, events.size());
+        assertFalse(events.get(0));// no configuration, update with null
+    }
 }
\ No newline at end of file

Reply via email to