aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [2/2] aries-rsa git commit: [ARIES-1581] Improve itest
Date Fri, 24 Jun 2016 12:17:04 GMT
[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 <chris@die-schneider.net>
Authored: Fri Jun 24 14:16:53 2016 +0200
Committer: Christian Schneider <chris@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;
     }
 
 }


Mime
View raw message