You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by io...@apache.org on 2011/12/02 23:52:12 UTC

svn commit: r1209762 - in /karaf/cellar/branches/cellar-2.2.x: ./ itests/src/test/java/org/apache/karaf/cellar/itests/

Author: iocanel
Date: Fri Dec  2 22:52:11 2011
New Revision: 1209762

URL: http://svn.apache.org/viewvc?rev=1209762&view=rev
Log:
Merged from trunk
[KARAF-1026] Added dosgi integration test. Enhanced operations such as create child, execute command etc. Removed obsolete cluster setup calls. Added missing license headers. [from revision 1209757]

Added:
    karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarSampleDosgiGreeterTest.java
      - copied unchanged from r1209757, karaf/cellar/trunk/itests/src/test/java/org/apache/karaf/cellar/itests/CellarSampleDosgiGreeterTest.java
Modified:
    karaf/cellar/branches/cellar-2.2.x/   (props changed)
    karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarChildNodesTest.java
    karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarFeaturesTest.java
    karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarGroupsTest.java
    karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java

Propchange: karaf/cellar/branches/cellar-2.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec  2 22:52:11 2011
@@ -1 +1 @@
-/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077,1164523,1164989,1164994,1166403,1166434,1181287,1186085,1202090,1202105,1202108,1202111,1203975,1204173,1204184,1204209,1205187,1209264,1209753,1209755
+/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077,1164523,1164989,1164994,1166403,1166434,1181287,1186085,1202090,1202105,1202108,1202111,1203975,1204173,1204184,1204209,1205187,1209264,1209753,1209755,1209757

Modified: karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarChildNodesTest.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarChildNodesTest.java?rev=1209762&r1=1209761&r2=1209762&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarChildNodesTest.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarChildNodesTest.java Fri Dec  2 22:52:11 2011
@@ -1,3 +1,16 @@
+/*
+ * Licensed 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.
+ */
 package org.apache.karaf.cellar.itests;
 
 import java.util.Set;
@@ -6,6 +19,7 @@ import org.apache.karaf.cellar.core.Node
 import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.openengsb.labs.paxexam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.ExamReactorStrategy;
@@ -15,6 +29,7 @@ import org.ops4j.pax.exam.spi.reactors.A
 
 import static org.junit.Assert.*;
 import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.logLevel;
 
 @RunWith(JUnit4TestRunner.class)
 @ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
@@ -23,7 +38,6 @@ public class CellarChildNodesTest extend
     @Test
     public void testClusterWithChildNodes() throws InterruptedException {
         installCellar();
-        configureLocalDiscovery(2);
         createCellarChild("child1");
         Thread.sleep(DEFAULT_TIMEOUT);
         ClusterManager clusterManager = getOsgiService(ClusterManager.class);
@@ -40,8 +54,8 @@ public class CellarChildNodesTest extend
     @After
     public void tearDown() {
         try {
-            unInstallCellar();
             destroyCellarChild("child1");
+            unInstallCellar();
         } catch (Exception ex) {
             //Ignore
         }
@@ -51,6 +65,6 @@ public class CellarChildNodesTest extend
     @Configuration
     public Option[] config() {
         return new Option[]{
-                cellarDistributionConfiguration(), keepRuntimeFolder()};
+                cellarDistributionConfiguration(), keepRuntimeFolder(),logLevel(LogLevelOption.LogLevel.ERROR)};
     }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarFeaturesTest.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarFeaturesTest.java?rev=1209762&r1=1209761&r2=1209762&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarFeaturesTest.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarFeaturesTest.java Fri Dec  2 22:52:11 2011
@@ -1,3 +1,16 @@
+/*
+ * Licensed 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.
+ */
 package org.apache.karaf.cellar.itests;
 
 import java.util.Set;
@@ -6,6 +19,7 @@ import org.apache.karaf.cellar.core.Node
 import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.openengsb.labs.paxexam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.ExamReactorStrategy;
@@ -16,6 +30,7 @@ import org.ops4j.pax.exam.spi.reactors.A
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.logLevel;
 
 @RunWith(JUnit4TestRunner.class)
 @ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
@@ -27,7 +42,6 @@ public class CellarFeaturesTest extends 
     @Test
     public void testCellarFeaturesModule() throws InterruptedException {
         installCellar();
-        configureLocalDiscovery(2);
         createCellarChild("child1");
         Thread.sleep(DEFAULT_TIMEOUT);
         ClusterManager clusterManager = getOsgiService(ClusterManager.class);
@@ -67,6 +81,14 @@ public class CellarFeaturesTest extends 
         System.err.println(httpFeatureStatus);
         assertTrue(httpFeatureStatus.startsWith(UNINSTALLED));
 
+        //Test feature command - install - before a node joins
+        System.err.println(executeCommand("cluster:features-install testgroup eventadmin"));
+        System.err.println(executeCommand("cluster:group-set testgroup "+getNodeIdOfChild("child1")));
+        Thread.sleep(5000);
+        httpFeatureStatus = executeCommand("admin:connect child1 features:list | grep eventadmin");
+        System.err.println(httpFeatureStatus);
+        assertTrue(httpFeatureStatus.startsWith(INSTALLED));
+
 
         Node localNode = clusterManager.getNode();
         Set<Node> nodes =clusterManager.listNodes();
@@ -79,8 +101,8 @@ public class CellarFeaturesTest extends 
     @After
     public void tearDown() {
         try {
-            unInstallCellar();
             destroyCellarChild("child1");
+            unInstallCellar();
         } catch (Exception ex) {
             //Ignore
         }
@@ -90,6 +112,6 @@ public class CellarFeaturesTest extends 
     @Configuration
     public Option[] config() {
         return new Option[]{
-                cellarDistributionConfiguration(), keepRuntimeFolder()};
+                cellarDistributionConfiguration(), keepRuntimeFolder(),logLevel(LogLevelOption.LogLevel.ERROR)};
     }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarGroupsTest.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarGroupsTest.java?rev=1209762&r1=1209761&r2=1209762&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarGroupsTest.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarGroupsTest.java Fri Dec  2 22:52:11 2011
@@ -1,3 +1,16 @@
+/*
+ * Licensed 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.
+ */
 package org.apache.karaf.cellar.itests;
 
 import java.util.Set;
@@ -8,6 +21,7 @@ import org.apache.karaf.cellar.core.Node
 import org.junit.After;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.openengsb.labs.paxexam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.ExamReactorStrategy;
@@ -19,6 +33,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.logLevel;
 
 @RunWith(JUnit4TestRunner.class)
 @ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
@@ -27,7 +42,6 @@ public class CellarGroupsTest extends Ce
     @Test
     public void testGroupsWithChildNodes() throws InterruptedException {
         installCellar();
-        configureLocalDiscovery(2);
         createCellarChild("child1");
         Thread.sleep(DEFAULT_TIMEOUT);
         ClusterManager clusterManager = getOsgiService(ClusterManager.class);
@@ -35,7 +49,7 @@ public class CellarGroupsTest extends Ce
 
         System.err.println(executeCommand("cluster:nodes-list"));
         Node localNode = clusterManager.getNode();
-        Set<Node> nodes =clusterManager.listNodes();
+        Set<Node> nodes = clusterManager.listNodes();
         assertTrue("There should be at least 2 cellar nodes running", 2 <= nodes.size());
 
         System.err.println(executeCommand("cluster:group-list"));
@@ -58,8 +72,8 @@ public class CellarGroupsTest extends Ce
     @After
     public void tearDown() {
         try {
-            unInstallCellar();
             destroyCellarChild("child1");
+            unInstallCellar();
         } catch (Exception ex) {
             //Ignore
         }
@@ -69,6 +83,6 @@ public class CellarGroupsTest extends Ce
     @Configuration
     public Option[] config() {
         return new Option[]{
-                cellarDistributionConfiguration(), keepRuntimeFolder()};
+                cellarDistributionConfiguration(), keepRuntimeFolder(),logLevel(LogLevelOption.LogLevel.ERROR)};
     }
 }

Modified: karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java?rev=1209762&r1=1209761&r2=1209762&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/itests/src/test/java/org/apache/karaf/cellar/itests/CellarTestSupport.java Fri Dec  2 22:52:11 2011
@@ -25,7 +25,15 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import javax.inject.Inject;
+import EDU.oswego.cs.dl.util.concurrent.Sync;
 import org.apache.felix.service.command.CommandProcessor;
 import org.apache.felix.service.command.CommandSession;
 import org.ops4j.pax.exam.MavenUtils;
@@ -47,13 +55,19 @@ import static org.ops4j.pax.exam.CoreOpt
 
 public class CellarTestSupport {
 
+    static final Long COMMAND_TIMEOUT = 10000L;
     static final Long DEFAULT_TIMEOUT = 20000L;
     static final Long SERVICE_TIMEOUT = 30000L;
     static final String GROUP_ID = "org.apache.karaf";
     static final String ARTIFACT_ID = "apache-karaf";
 
+    static final String INSTANCE_STARTED = "Started";
+    static final String INSTANCE_STARTING = "Starting";
+
     static final String CELLAR_FEATURE_URL = String.format("mvn:org.apache.karaf.cellar/apache-karaf-cellar/%s/xml/features","3.0.0-SNAPSHOT");
 
+    ExecutorService executor = Executors.newCachedThreadPool();
+
     @Inject
     protected BundleContext bundleContext;
 
@@ -99,16 +113,35 @@ public class CellarTestSupport {
     }
 
     protected void unInstallCellar() {
-        executeCommand("features:uninstall cellar");
+        System.err.println(executeCommand("features:uninstall cellar"));
     }
 
     /**
      * Creates a child instance that runs cellar.
      */
     protected void createCellarChild(String name) {
-        System.err.println(executeCommand("admin:create --featureURL " + CELLAR_FEATURE_URL + " --feature cellar -r " +
-                getFreePort(1100)+ " -rs " + getFreePort(44445) + " -s " + getFreePort(8102) + " " + name));
+        int instances = 0;
+        System.err.println(executeCommand("admin:create --featureURL " + CELLAR_FEATURE_URL + " --feature cellar "+name));
         System.err.println(executeCommand("admin:start " + name));
+
+        //Wait till the node is listed as Starting
+        System.err.print("Waiting for " + name + " to start ");
+        for (int i = 0; i < 5 && instances == 0; i++) {
+            String response = executeCommand("admin:list | grep " + name + " | grep -c " + INSTANCE_STARTED, COMMAND_TIMEOUT, true);
+            instances = Integer.parseInt(response.trim());
+            System.err.print(".");
+            try {
+                Thread.sleep(3000);
+            } catch (InterruptedException e) {
+                //Ignore
+            }
+        }
+
+        if(instances > 0) {
+            System.err.println(".Started!");
+        } else {
+            System.err.println(".Timed Out!");
+        }
     }
 
     /**
@@ -120,6 +153,21 @@ public class CellarTestSupport {
     }
 
     /**
+     * Returns the node id of a specific child instance.
+     * @param name
+     * @return
+     */
+    protected String getNodeIdOfChild(String name) {
+        String nodeId = null;
+        String nodesList = executeCommand("admin:connect " + name+" cluster:nodes-list | grep \\\\*");
+        String[] tokens = nodesList.split(" ");
+        if(tokens != null && tokens.length > 0) {
+            nodeId = tokens[tokens.length - 1].trim().replaceAll("\n","");
+        }
+        return nodeId;
+    }
+
+    /**
      * Create an {@link org.ops4j.pax.exam.Option} for using a .
      *
      * @return
@@ -132,43 +180,91 @@ public class CellarTestSupport {
 
     /**
      * Executes a shell command and returns output as a String.
-     *
+     * Commands have a default timeout of 10 seconds.
      * @param command
      * @return
      */
-    protected String executeCommand(String command) {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        PrintStream printStream = new PrintStream(byteArrayOutputStream);
-        CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
-        CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
+    protected String executeCommand(final String command) {
+       return executeCommand(command,COMMAND_TIMEOUT,false);
+    }
+
+     /**
+     * Executes a shell command and returns output as a String.
+     * Commands have a default timeout of 10 seconds.
+     * @param command The command to execute.
+     * @param timeout The amount of time in millis to wait for the command to execute.
+     * @param silent  Specifies if the command should be displayed in the screen.
+     * @return
+     */
+    protected String executeCommand(final String command, final Long timeout, final Boolean silent) {
+        String response;
+        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
+        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
+        final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
+        FutureTask<String> commandFuture = new FutureTask<String>(
+                new Callable<String>() {
+                    public String call() {
+                        try {
+                            if (!silent) {
+                                System.err.println(command);
+                            }
+                            commandSession.execute(command);
+                        } catch (Exception e) {
+                            e.printStackTrace(System.err);
+                        }
+                        printStream.flush();
+                        return byteArrayOutputStream.toString();
+                    }
+                });
+
         try {
-            System.err.println(command);
-            commandSession.execute(command);
+            executor.submit(commandFuture);
+            response =  commandFuture.get(timeout, TimeUnit.MILLISECONDS);
         } catch (Exception e) {
             e.printStackTrace(System.err);
+            response = "SHELL COMMAND TIMED OUT: ";
         }
-        return byteArrayOutputStream.toString();
+
+        return response;
     }
 
     /**
      * Executes multiple commands inside a Single Session.
+     * Commands have a default timeout of 10 seconds.
      * @param commands
      * @return
      */
-    protected String executeCommands(String ...commands) {
-        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-        PrintStream printStream = new PrintStream(byteArrayOutputStream);
-        CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
-        CommandSession commandSession = commandProcessor.createSession(System.in, printStream, printStream);
+    protected String executeCommands(final String ...commands) {
+        String response;
+        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        final PrintStream printStream = new PrintStream(byteArrayOutputStream);
+        final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class);
+        final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
+        FutureTask<String> commandFuture = new FutureTask<String>(
+                new Callable<String>() {
+                    public String call() {
+                        try {
+                            for(String command:commands) {
+                             System.err.println(command);
+                             commandSession.execute(command);
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace(System.err);
+                        }
+                        return byteArrayOutputStream.toString();
+                    }
+                });
+
         try {
-            for (String cmd : commands) {
-                System.err.println(cmd);
-                commandSession.execute(cmd);
-            }
+            executor.submit(commandFuture);
+            response =  commandFuture.get(COMMAND_TIMEOUT, TimeUnit.MILLISECONDS);
         } catch (Exception e) {
             e.printStackTrace(System.err);
+            response = "SHELL COMMAND TIMED OUT: ";
         }
-        return byteArrayOutputStream.toString();
+
+        return response;
     }
 
     protected Bundle getInstalledBundle(String symbolicName) {