You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2021/03/09 14:30:13 UTC

[aries-component-dsl] branch master updated (30c0c17 -> 7cdde98)

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

csierra pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git.


    from 30c0c17  Update effects should execute in proper order
     new 58f9e92  Add test for refreshWhen nodes depending on other refreshWhen nodes
     new 7cdde98  Close programs when test finish

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/aries/component/dsl/test/DSLTest.java   | 132 ++++++++++++++-------
 1 file changed, 92 insertions(+), 40 deletions(-)


[aries-component-dsl] 02/02: Close programs when test finish

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit 7cdde989e30acfabc1400ba7fce79f28e6324842
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Tue Mar 9 15:27:01 2021 +0100

    Close programs when test finish
---
 .../apache/aries/component/dsl/test/DSLTest.java   | 93 +++++++++++-----------
 1 file changed, 48 insertions(+), 45 deletions(-)

diff --git a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
index 289bf12..74428b5 100644
--- a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
+++ b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
@@ -1825,18 +1825,21 @@ public class DSLTest {
 
         AtomicInteger atomicInteger = new AtomicInteger();
 
-        try {
+        try (
             /* reload only when property "good" has changed */
-            OSGi<?> program = serviceReferences(
-                Service.class, csr -> csr.isDirty("good")).map(
-                    csr -> csr.getProperty("good"));
-
-            program.run(bundleContext, (__) -> {
-                atomicInteger.incrementAndGet();
-
-                return NOOP;
-            });
+            OSGiResult osgiResult = serviceReferences(
+                Service.class, csr -> csr.isDirty("good")
+            ).map(
+                csr -> csr.getProperty("good")
+            ).run(
+                bundleContext,
+                (__) -> {
+                    atomicInteger.incrementAndGet();
 
+                    return NOOP;
+                }
+            )
+        ) {
             assertEquals(1, atomicInteger.get());
 
             serviceRegistration.setProperties(
@@ -1873,8 +1876,8 @@ public class DSLTest {
 
         AtomicInteger atomicInteger = new AtomicInteger();
 
-        try {
-            OSGi<?> program =
+        try (
+            OSGiResult osgiResult =
                 serviceReferences(
                     Service.class,
                     csr -> csr.getServiceReference().getProperty("property").equals("refresh")
@@ -1891,10 +1894,10 @@ public class DSLTest {
                         atomicReference.set(
                             String.valueOf(
                                 csr.getServiceReference().getProperty("property")))
-                );
-
-            program.run(bundleContext);
-
+                ).run(
+                    bundleContext
+                )
+        ) {
             assertEquals(1, atomicInteger.get());
             assertEquals("original", atomicReference.get());
 
@@ -1933,8 +1936,8 @@ public class DSLTest {
 
         AtomicInteger atomicInteger = new AtomicInteger();
 
-        try {
-            OSGi<?> program =
+        try (
+            OSGiResult osgiResult =
                 refreshAsUpdates(
                     serviceReferences(
                         Service.class
@@ -1954,10 +1957,10 @@ public class DSLTest {
                     sr ->
                         atomicReference.set(
                             String.valueOf(sr.getProperty("property")))
-                );
-
-            program.run(bundleContext);
-
+                ).run(
+                    bundleContext
+                )
+        ) {
             assertEquals(1, atomicInteger.get());
             assertEquals("original", atomicReference.get());
 
@@ -1984,7 +1987,6 @@ public class DSLTest {
         }
     }
 
-
     @Test
     public void testServiceReferenceUpdatesWithSelector() {
         AtomicReference<String> atomicReference = new AtomicReference<>();
@@ -1998,8 +2000,8 @@ public class DSLTest {
 
         AtomicInteger atomicInteger = new AtomicInteger();
 
-        try {
-            OSGi<?> program = refreshWhen(
+        try (
+            OSGiResult osgiResult = refreshWhen(
                     ServiceReferences.withUpdate(Service.class),
                     csr -> csr.getServiceReference().getProperty("property").equals("refresh")
             ).effects(
@@ -2014,10 +2016,10 @@ public class DSLTest {
                 csr ->
                     atomicReference.set(
                         String.valueOf(csr.getServiceReference().getProperty("property")))
-            );
-
-            program.run(bundleContext);
-
+            ).run(
+                bundleContext
+            )
+        ) {
             assertEquals(1, atomicInteger.get());
             assertEquals("original", atomicReference.get());
 
@@ -2215,8 +2217,8 @@ public class DSLTest {
                     put("property", "original");
                 }});
 
-        try {
-            OSGi<?> program =
+        try (
+            OSGiResult osgiResult =
                 serviceReferences(
                     Service.class, __ -> false
                 ).effects(
@@ -2233,9 +2235,10 @@ public class DSLTest {
                             __ -> updateEffects.add("second") //should never fire because refresh is true
                         )
                         , __ -> true)
-                );
-
-            program.run(bundleContext);
+                ).run(
+                    bundleContext
+                )
+        ) {
 
             assertEquals(Collections.singletonList("effect"), effects);
 
@@ -2263,8 +2266,8 @@ public class DSLTest {
                     put("property", "original");
                 }});
 
-        try {
-            OSGi<?> program =
+        try (
+            OSGiResult osgiResult =
                 serviceReferences(
                     Service.class, __ -> false
                 ).effects(
@@ -2275,10 +2278,10 @@ public class DSLTest {
                     __ -> {},
                     __ -> {},
                     __ -> updateEffects.add("second")
-                );
-
-            program.run(bundleContext);
-
+                ).run(
+                    bundleContext
+                )
+        ) {
             assertEquals(Collections.emptyList(), updateEffects);
 
             serviceRegistration.setProperties(
@@ -2304,8 +2307,8 @@ public class DSLTest {
                     put("property", "original");
                 }});
 
-        try {
-            OSGi<?> program =
+        try (
+            OSGiResult osgiResult =
                 refreshWhen(
                     serviceReferences(
                         Service.class, __ -> false
@@ -2319,10 +2322,10 @@ public class DSLTest {
                         __ -> updateEffects.add("second")
                     ),
                     __ -> true
+                ).run(
+                    bundleContext
                 );
-
-            program.run(bundleContext);
-
+        )  {
             assertEquals(Collections.emptyList(), updateEffects);
 
             serviceRegistration.setProperties(


[aries-component-dsl] 01/02: Add test for refreshWhen nodes depending on other refreshWhen nodes

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-component-dsl.git

commit 58f9e92a33c233b638c3cfe924543f8ad474bcc0
Author: Carlos Sierra Andrés <ca...@liferay.com>
AuthorDate: Tue Mar 9 15:17:24 2021 +0100

    Add test for refreshWhen nodes depending on other refreshWhen nodes
---
 .../apache/aries/component/dsl/test/DSLTest.java   | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
index f644a3c..289bf12 100644
--- a/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
+++ b/itests/src/main/java/org/apache/aries/component/dsl/test/DSLTest.java
@@ -2204,6 +2204,55 @@ public class DSLTest {
     }
 
     @Test
+    public void testRefreshWhenDoesNotPropagateUpdates() {
+        ArrayList<String> effects = new ArrayList<>();
+        ArrayList<String> updateEffects = new ArrayList<>();
+
+        ServiceRegistration<Service> serviceRegistration =
+            bundleContext.registerService(
+                Service.class, new Service(),
+                new Hashtable<String, Object>() {{
+                    put("property", "original");
+                }});
+
+        try {
+            OSGi<?> program =
+                serviceReferences(
+                    Service.class, __ -> false
+                ).effects(
+                    __ -> effects.add("effect"), //should not repeat by last __ -> true
+                    __ -> {},
+                    __ -> updateEffects.add("first")
+                ).then(
+                    refreshWhen(
+                        serviceReferences(
+                            Service.class, __ -> false
+                        ).effects(
+                            __ -> {},
+                            __ -> {},
+                            __ -> updateEffects.add("second") //should never fire because refresh is true
+                        )
+                        , __ -> true)
+                );
+
+            program.run(bundleContext);
+
+            assertEquals(Collections.singletonList("effect"), effects);
+
+            serviceRegistration.setProperties(
+                new Hashtable<String, Object>() {{
+                    put("property", "updated");
+                }});
+
+            assertEquals(Collections.singletonList("effect"), effects);
+            assertEquals(Collections.singletonList("first"), updateEffects);
+        }
+        finally {
+            serviceRegistration.unregister();
+        }
+    }
+
+    @Test
     public void testUpdateEffectsOrder() {
         ArrayList<String> updateEffects = new ArrayList<>();