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 2016/06/24 12:17:03 UTC

[1/2] aries-rsa git commit: [ARIES-1581] RSA does not include the ExportReference in RSA Events

Repository: aries-rsa
Updated Branches:
  refs/heads/master b33cdf310 -> 659bba76d


[ARIES-1581] RSA does not include the ExportReference in RSA Events

adds a new method getExportReferenceAlways that returns the export
reference even if the registration is closed.



Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/21129482
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/21129482
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/21129482

Branch: refs/heads/master
Commit: 21129482b7753041ecb7ece61fe657084c35c43c
Parents: b33cdf3
Author: Johannes Utzig <j....@seeburger.de>
Authored: Thu Jun 23 10:29:24 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Jun 24 12:53:45 2016 +0200

----------------------------------------------------------------------
 .../rsa/itests/felix/rsa/TestRSAListener.java   | 88 ++++++++++++++++++++
 .../apache/aries/rsa/core/EventProducer.java    |  4 +-
 .../aries/rsa/core/ExportRegistrationImpl.java  | 10 +++
 .../aries/rsa/core/RemoteServiceAdminCore.java  |  2 +-
 4 files changed, 101 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/21129482/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
new file mode 100644
index 0000000..ca2347f
--- /dev/null
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
@@ -0,0 +1,88 @@
+package org.apache.aries.rsa.itests.felix.rsa;
+/**
+ * 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.
+ */
+
+
+import static org.junit.Assert.*;
+
+import javax.inject.Inject;
+
+import org.apache.aries.rsa.itests.felix.RsaTestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
+import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
+
+@RunWith(PaxExam.class)
+public class TestRSAListener extends RsaTestBase implements RemoteServiceAdminListener {
+
+    @Inject
+    BundleContext context;
+
+    private RemoteServiceAdminEvent lastEvent;
+
+
+    @Configuration
+    public static Option[] configure() throws Exception {
+        return new Option[] {
+                rsaCoreZookeeper(),
+                configZKServer(),
+                rsaFastBin(),
+                echoTcpService(),
+                configFastBin("2545"),
+                configZKConsumer()
+        };
+    }
+
+    @Test
+    public void testListener() throws Exception {
+
+        Thread.sleep(1000);
+        context.registerService(RemoteServiceAdminListener.class, this, null);
+        Bundle serviceBundle = null;
+        Bundle[] bundles = context.getBundles();
+        for (Bundle bundle : bundles) {
+            if("org.apache.aries.rsa.examples.echotcp.service".equals(bundle.getSymbolicName())) {
+                serviceBundle = bundle;
+                break;
+            }
+        }
+        serviceBundle.stop();
+        assertNotNull(lastEvent);
+        assertEquals(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, lastEvent.getType());
+        assertNotNull("ExportReference must be available",lastEvent.getExportReference());
+
+        serviceBundle.start();
+        Thread.sleep(3000);
+        assertNotNull(lastEvent);
+        assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, lastEvent.getType());
+        assertNotNull("ExportReference must be available",lastEvent.getExportReference());
+    }
+
+    @Override
+    public void remoteAdminEvent(RemoteServiceAdminEvent event) {
+        lastEvent = event;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/21129482/rsa/src/main/java/org/apache/aries/rsa/core/EventProducer.java
----------------------------------------------------------------------
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/EventProducer.java b/rsa/src/main/java/org/apache/aries/rsa/core/EventProducer.java
index 0d9453b..fb1addb 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/EventProducer.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/EventProducer.java
@@ -64,8 +64,8 @@ public class EventProducer {
         }
     }
 
-    public void notifyRemoval(ExportRegistration er) {
-        notify(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, er.getExportReference(), null);
+    public void notifyRemoval(ExportReference er) {
+        notify(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, er, null);
     }
 
     public void notifyRemoval(ImportRegistration ir) {

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/21129482/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
----------------------------------------------------------------------
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
index 0f0dcef..8f54a3b 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
@@ -78,6 +78,16 @@ public class ExportRegistrationImpl implements ExportRegistration {
         }
     }
 
+    /**
+     * Returns the ExportReference even if this
+     * instance is closed or has an exception.
+     *
+     * @return the export reference
+     */
+    public ExportReference getExportReferenceAlways() {
+        return exportReference;
+    }
+
     public ExportReference getExportReference() {
         if (exportReference == null) {
             throw new IllegalStateException(getException());

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/21129482/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
----------------------------------------------------------------------
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
index b7a93f1..3316a93 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
@@ -467,7 +467,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin {
                 for (Iterator<ExportRegistration> it2 = value.iterator(); it2.hasNext();) {
                     ExportRegistration er = it2.next();
                     if (er.equals(eri)) {
-                        eventProducer.notifyRemoval(eri);
+                        eventProducer.notifyRemoval(eri.getExportReferenceAlways());
                         it2.remove();
                         if (value.isEmpty()) {
                             it.remove();


[2/2] aries-rsa git commit: [ARIES-1581] Improve itest

Posted by cs...@apache.org.
[ARIES-1581] Improve itest


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/659bba76
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/659bba76
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/659bba76

Branch: refs/heads/master
Commit: 659bba76d00db68760d8dde1e25b469ec5e5b299
Parents: 2112948
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Jun 24 14:16:53 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Jun 24 14:16:53 2016 +0200

----------------------------------------------------------------------
 .../rsa/itests/felix/rsa/TestRSAListener.java   | 63 +++++++++++++-------
 1 file changed, 42 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/659bba76/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
index ca2347f..5c9374f 100644
--- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/rsa/TestRSAListener.java
@@ -21,6 +21,8 @@ package org.apache.aries.rsa.itests.felix.rsa;
 
 import static org.junit.Assert.*;
 
+import java.util.concurrent.TimeoutException;
+
 import javax.inject.Inject;
 
 import org.apache.aries.rsa.itests.felix.RsaTestBase;
@@ -31,6 +33,7 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;
 
@@ -46,43 +49,61 @@ public class TestRSAListener extends RsaTestBase implements RemoteServiceAdminLi
     @Configuration
     public static Option[] configure() throws Exception {
         return new Option[] {
-                rsaCoreZookeeper(),
-                configZKServer(),
+                rsaCore(),
                 rsaFastBin(),
                 echoTcpService(),
                 configFastBin("2545"),
-                configZKConsumer()
         };
     }
 
     @Test
     public void testListener() throws Exception {
+        Bundle serviceBundle = getBundle("org.apache.aries.rsa.examples.echotcp.service");
+        serviceBundle.stop();
+        ServiceRegistration<RemoteServiceAdminListener> sreg = context.registerService(RemoteServiceAdminListener.class, this, null);
+
+        serviceBundle.start();
+        assertEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION);
+
+        serviceBundle.stop();
+        assertEvent(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION);
+
+        sreg.unregister();
+    }
+
+    @Override
+    public synchronized void remoteAdminEvent(RemoteServiceAdminEvent event) {
+        lastEvent = event;
+        this.notifyAll();
+    }
+
+    private void assertEvent(int eventType) throws InterruptedException, TimeoutException {
+        waitEvent();
+        assertEquals(eventType, lastEvent.getType());
+        assertNotNull("ExportReference must be available",lastEvent.getExportReference());
+        this.lastEvent = null;
+    }
 
-        Thread.sleep(1000);
-        context.registerService(RemoteServiceAdminListener.class, this, null);
+    private synchronized void waitEvent() throws InterruptedException, TimeoutException {
+        long start = System.currentTimeMillis();
+        while (this.lastEvent == null) {
+            this.wait(1000);
+            if (System.currentTimeMillis() - start > 2000) {
+                throw new TimeoutException("Timeout waiting for Event");
+            }
+        }
+    }
+
+    private Bundle getBundle(String symName) {
         Bundle serviceBundle = null;
         Bundle[] bundles = context.getBundles();
         for (Bundle bundle : bundles) {
-            if("org.apache.aries.rsa.examples.echotcp.service".equals(bundle.getSymbolicName())) {
+            if(symName.equals(bundle.getSymbolicName())) {
                 serviceBundle = bundle;
                 break;
             }
         }
-        serviceBundle.stop();
-        assertNotNull(lastEvent);
-        assertEquals(RemoteServiceAdminEvent.EXPORT_UNREGISTRATION, lastEvent.getType());
-        assertNotNull("ExportReference must be available",lastEvent.getExportReference());
-
-        serviceBundle.start();
-        Thread.sleep(3000);
-        assertNotNull(lastEvent);
-        assertEquals(RemoteServiceAdminEvent.EXPORT_REGISTRATION, lastEvent.getType());
-        assertNotNull("ExportReference must be available",lastEvent.getExportReference());
-    }
-
-    @Override
-    public void remoteAdminEvent(RemoteServiceAdminEvent event) {
-        lastEvent = event;
+        return serviceBundle;
     }
 
 }