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-1579] Use cleaner way to start second container
Date Wed, 22 Jun 2016 10:07:13 GMT
[ARIES-1579] Use cleaner way to start second container


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

Branch: refs/heads/master
Commit: 08463cb2413433c5c17db5fd6daeb3110980d32a
Parents: 7627ef9
Author: Christian Schneider <chris@die-schneider.net>
Authored: Wed Jun 22 12:07:05 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Wed Jun 22 12:07:05 2016 +0200

----------------------------------------------------------------------
 itests/felix/pom.xml                            |  2 +-
 .../rsa/itests/felix/ServerConfiguration.java   | 12 ++++
 .../rsa/itests/felix/TwoContainerPaxExam.java   | 63 ++++++++++++++++++++
 .../felix/fastbin/TestFastbinRoundTrip.java     | 24 ++------
 .../rsa/itests/felix/tcp/TestRoundTrip.java     | 23 ++-----
 5 files changed, 86 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/08463cb2/itests/felix/pom.xml
----------------------------------------------------------------------
diff --git a/itests/felix/pom.xml b/itests/felix/pom.xml
index 4728c9e..1fead7a 100644
--- a/itests/felix/pom.xml
+++ b/itests/felix/pom.xml
@@ -124,7 +124,7 @@
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
-            <artifactId>pax-exam-container-native</artifactId>
+            <artifactId>pax-exam-container-forked</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/08463cb2/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/ServerConfiguration.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/ServerConfiguration.java
b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/ServerConfiguration.java
new file mode 100644
index 0000000..ab4e8f5
--- /dev/null
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/ServerConfiguration.java
@@ -0,0 +1,12 @@
+package org.apache.aries.rsa.itests.felix;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface ServerConfiguration {
+
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/08463cb2/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java
b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java
new file mode 100644
index 0000000..555a5ac
--- /dev/null
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/TwoContainerPaxExam.java
@@ -0,0 +1,63 @@
+package org.apache.aries.rsa.itests.felix;
+
+import java.lang.reflect.Method;
+
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.InitializationError;
+import org.ops4j.pax.exam.ExamSystem;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.TestContainer;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.PaxExamRuntime;
+
+public class TwoContainerPaxExam extends PaxExam {
+
+    private Class<?> testClass;
+
+    public TwoContainerPaxExam(Class<?> klass) throws InitializationError {
+        super(klass);
+        this.testClass = klass;
+    }
+
+    @Override
+    public void run(RunNotifier notifier) {
+        TestContainer remoteContainer = null;
+        try {
+            
+            ExamSystem testSystem = PaxExamRuntime.createTestSystem(remoteConfig());
+            remoteContainer = PaxExamRuntime.createContainer(testSystem);
+            remoteContainer.start();
+            super.run(notifier);
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (remoteContainer != null) {
+                remoteContainer.stop();
+            }
+        }
+        
+    }
+
+    private Option[] remoteConfig() throws Exception {
+        Object testO = this.testClass.newInstance();
+        Method configMethod = getServerConfigMethod();
+        return (Option[])configMethod.invoke(testO);
+    }
+
+    private Method getServerConfigMethod() throws NoSuchMethodException, SecurityException
{
+        Method[] methods = testClass.getMethods();
+        for (Method method : methods) {
+            if (method.getAnnotation(ServerConfiguration.class) != null) {
+                if (method.getParameterTypes().length > 0) {
+                    throw new IllegalArgumentException("ServerConfiguration method must have
no params");
+                }
+                if (method.getReturnType() != Option[].class) {
+                    throw new IllegalArgumentException("ServerConfiguration method must return
Option[]");
+                }
+                return method;
+            }
+        }
+        throw new IllegalArgumentException("One method must be annotated with @ServerConfiguration");
+    }
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/08463cb2/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java
b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java
index a86d303..c73d822 100644
--- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/fastbin/TestFastbinRoundTrip.java
@@ -26,29 +26,20 @@ import javax.inject.Inject;
 
 import org.apache.aries.rsa.examples.echotcp.api.EchoService;
 import org.apache.aries.rsa.itests.felix.RsaTestBase;
+import org.apache.aries.rsa.itests.felix.ServerConfiguration;
+import org.apache.aries.rsa.itests.felix.TwoContainerPaxExam;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.ExamSystem;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.TestContainer;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.PaxExamRuntime;
 
-@RunWith(PaxExam.class)
+@RunWith(TwoContainerPaxExam.class)
 public class TestFastbinRoundTrip extends RsaTestBase {
-    private static TestContainer remoteContainer;
-
     @Inject
     EchoService echoService;
 
-    public static void startRemote() throws IOException, InterruptedException {
-        ExamSystem testSystem = PaxExamRuntime.createTestSystem(remoteConfig());
-        remoteContainer = PaxExamRuntime.createContainer(testSystem);
-        remoteContainer.start();
-    }
-
-    private static Option[] remoteConfig() throws IOException {
+    @ServerConfiguration
+    public static Option[] remoteConfig() throws IOException {
         return new Option[] {
                              rsaCoreZookeeper(),
                              rsaFastBin(),
@@ -61,7 +52,6 @@ public class TestFastbinRoundTrip extends RsaTestBase {
 
     @Configuration
     public static Option[] configure() throws Exception {
-        startRemote();
         return new Option[] {
                              rsaCoreZookeeper(),
                              rsaFastBin(),
@@ -76,8 +66,4 @@ public class TestFastbinRoundTrip extends RsaTestBase {
         assertEquals("test", echoService.echo("test"));
     }
 
-    public static void shutdownRemote() {
-        remoteContainer.stop();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/08463cb2/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java
----------------------------------------------------------------------
diff --git a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java
b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java
index 0f80df2..b3ea522 100644
--- a/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java
+++ b/itests/felix/src/test/java/org/apache/aries/rsa/itests/felix/tcp/TestRoundTrip.java
@@ -27,30 +27,21 @@ import javax.inject.Inject;
 
 import org.apache.aries.rsa.examples.echotcp.api.EchoService;
 import org.apache.aries.rsa.itests.felix.RsaTestBase;
+import org.apache.aries.rsa.itests.felix.ServerConfiguration;
+import org.apache.aries.rsa.itests.felix.TwoContainerPaxExam;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.ExamSystem;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.TestContainer;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.PaxExamRuntime;
 
-@RunWith(PaxExam.class)
+@RunWith(TwoContainerPaxExam.class)
 public class TestRoundTrip extends RsaTestBase {
 
-    private static TestContainer remoteContainer;
-
     @Inject
     EchoService echoService;
 
-    public static void startRemote() throws IOException, InterruptedException {
-        ExamSystem testSystem = PaxExamRuntime.createTestSystem(remoteConfig());
-        remoteContainer = PaxExamRuntime.createContainer(testSystem);
-        remoteContainer.start();
-    }
-
-    private static Option[] remoteConfig() throws IOException {
+    @ServerConfiguration
+    public static Option[] remoteConfig() throws IOException {
         return new Option[] {
             rsaCoreZookeeper(),
             rsaTcp(),
@@ -62,7 +53,6 @@ public class TestRoundTrip extends RsaTestBase {
 
     @Configuration
     public static Option[] configure() throws Exception {
-        startRemote();
         return new Option[] {
                 rsaCoreZookeeper(),
                 rsaTcp(),
@@ -76,7 +66,4 @@ public class TestRoundTrip extends RsaTestBase {
         assertEquals("test", echoService.echo("test"));
     }
 
-    public static void shutdownRemote() {
-        remoteContainer.stop();
-    }
 }


Mime
View raw message