activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1441209 - in /activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest: AbstractFeatureTest.java ActiveMQBrokerFeatureTest.java
Date Thu, 31 Jan 2013 21:44:45 GMT
Author: gtully
Date: Thu Jan 31 21:44:45 2013
New Revision: 1441209

URL: http://svn.apache.org/viewvc?rev=1441209&view=rev
Log:
add some commamd assertions to broker feature test

Modified:
    activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractFeatureTest.java
    activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerFeatureTest.java

Modified: activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractFeatureTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractFeatureTest.java?rev=1441209&r1=1441208&r2=1441209&view=diff
==============================================================================
--- activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractFeatureTest.java
(original)
+++ activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/AbstractFeatureTest.java
Thu Jan 31 21:44:45 2013
@@ -16,20 +16,33 @@
  */
 package org.apache.activemq.karaf.itest;
 
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
 import org.junit.After;
 import org.junit.Before;
 import org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.exam.junit.ProbeBuilder;
 import org.ops4j.pax.exam.options.UrlReference;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+
 
 import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
 import static org.openengsb.labs.paxexam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
@@ -38,6 +51,9 @@ import static org.ops4j.pax.exam.CoreOpt
 public abstract class AbstractFeatureTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureTest.class);
+    private static final long ASSERTION_TIMEOUT = 20000L;
+    private static final long COMMAND_TIMEOUT = 10000L;
+
     static String basedir;
     static {
         try {
@@ -59,6 +75,57 @@ public abstract class AbstractFeatureTes
     public void tearDown() throws Exception {
     }
 
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*,org.ops4j.pax.exam.options.*,org.apache.felix.service.*;status=provisional");
+        return probe;
+    }
+
+    @Inject
+    CommandProcessor commandProcessor;
+    ExecutorService executor = Executors.newCachedThreadPool();
+
+    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 CommandSession commandSession = commandProcessor.createSession(System.in,
printStream, printStream);
+            commandSession.put("APPLICATION", System.getProperty("karaf.name", "root"));
+            commandSession.put("USER", "karaf");
+            FutureTask<String> commandFuture = new FutureTask<String>(
+                    new Callable<String>() {
+                        public String call() {
+                            try {
+                                if (!silent) {
+                                    System.out.println(command);
+                                    System.out.flush();
+                                }
+                                commandSession.execute(command);
+                            } catch (Exception e) {
+                                e.printStackTrace(System.err);
+                            }
+                            printStream.flush();
+                            return byteArrayOutputStream.toString();
+                        }
+                    });
+
+            try {
+                executor.submit(commandFuture);
+                response = commandFuture.get(timeout, TimeUnit.MILLISECONDS);
+            } catch (Exception e) {
+                e.printStackTrace(System.err);
+                response = "SHELL COMMAND TIMED OUT: ";
+            }
+
+            return response;
+        }
+
+    protected String executeCommand(final String command) {
+        return executeCommand(command, COMMAND_TIMEOUT, false);
+    }
+
+
 //    protected void testComponent(String component) throws Exception {
 //        long max = System.currentTimeMillis() + 10000;
 //        while (true) {
@@ -172,9 +239,25 @@ public abstract class AbstractFeatureTes
                 replaceConfigurationFile("etc/custom.properties", new File(basedir+"/src/test/resources/org/apache/activemq/karaf/itest/custom.properties")),
                 replaceConfigurationFile("etc/org.apache.activemq.server-default.cfg", new
File(basedir+"/src/test/resources/org/apache/activemq/karaf/itest/org.apache.activemq.server-default.cfg")),
                 replaceConfigurationFile("etc/activemq.xml", new File(basedir+"/src/test/resources/org/apache/activemq/karaf/itest/activemq.xml")),
+                replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", new File(basedir+"/src/test/resources/org/apache/activemq/karaf/itest/org.ops4j.pax.logging.cfg")),
                 scanFeatures(getActiveMQKarafFeatureUrl(), f.toArray(new String[f.size()]))};
 
         return options;
     }
 
+    protected boolean withinReason(Callable<Boolean> callable) throws Throwable {
+        long max = System.currentTimeMillis() + ASSERTION_TIMEOUT;
+        while (true) {
+            try {
+                return callable.call();
+            } catch (Throwable t) {
+                if (System.currentTimeMillis() < max) {
+                    TimeUnit.SECONDS.sleep(1);
+                    continue;
+                } else {
+                    throw t;
+                }
+            }
+        }
+    }
 }

Modified: activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerFeatureTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerFeatureTest.java?rev=1441209&r1=1441208&r2=1441209&view=diff
==============================================================================
--- activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerFeatureTest.java
(original)
+++ activemq/trunk/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerFeatureTest.java
Thu Jan 31 21:44:45 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.karaf.itest;
 
+import java.util.concurrent.Callable;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -23,6 +24,9 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 @RunWith(JUnit4TestRunner.class)
 public class ActiveMQBrokerFeatureTest extends AbstractFeatureTest {
 
@@ -32,9 +36,26 @@ public class ActiveMQBrokerFeatureTest e
     }
 
     @Test
-    public void test() throws Exception {
+    public void test() throws Throwable {
         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
         factory.getBrokerURL();
-    }
 
+        withinReason(new Callable<Boolean>(){
+            @Override
+            public Boolean call() throws Exception {
+                assertEquals("brokerName = amq-broker", executeCommand("activemq:list").trim());
+                return true;
+            }
+        });
+
+
+        withinReason(new Callable<Boolean>(){
+            @Override
+            public Boolean call() throws Exception {
+                assertTrue(executeCommand("activemq:bstat").trim().contains("BrokerName =
amq-broker"));
+                return true;
+            }
+        });
+
+    }
 }



Mime
View raw message