activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject activemq-artemis git commit: ARTEMIS-277 IncompatibleVersionTest fails on slower machines
Date Mon, 26 Oct 2015 14:50:20 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master c9e823b1c -> 487d97676


ARTEMIS-277 IncompatibleVersionTest fails on slower machines

This closes #216


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/487d9767
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/487d9767
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/487d9767

Branch: refs/heads/master
Commit: 487d976760c0f6d0b819c9b84efc0ca59e8ddf4f
Parents: c9e823b
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Mon Oct 26 09:53:21 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Mon Oct 26 10:49:49 2015 -0400

----------------------------------------------------------------------
 .../client/IncompatibleVersionTest.java         | 21 ++++++--
 .../artemis/tests/util/SpawnedVMSupport.java    | 51 ++++++++++++++++++--
 2 files changed, 63 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/487d9767/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IncompatibleVersionTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IncompatibleVersionTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IncompatibleVersionTest.java
index 2323e5d..fb4b4e6 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IncompatibleVersionTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/IncompatibleVersionTest.java
@@ -19,15 +19,16 @@ package org.apache.activemq.artemis.tests.integration.client;
 import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.ActiveMQIncompatibleClientServerException;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
 import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
-import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
-import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
 import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
 import org.apache.activemq.artemis.core.protocol.core.Channel;
@@ -42,8 +43,10 @@ import org.apache.activemq.artemis.core.server.ActiveMQServers;
 import org.apache.activemq.artemis.core.version.impl.VersionImpl;
 import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
 import org.apache.activemq.artemis.utils.VersionLoader;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -51,6 +54,7 @@ import static org.apache.activemq.artemis.tests.util.RandomUtil.randomString;
 
 public class IncompatibleVersionTest extends ActiveMQTestBase {
 
+   private static final String WORD_START = "&*STARTED&*";
    private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER;
    // Constants -----------------------------------------------------
 
@@ -182,9 +186,16 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
       Process serverProcess = null;
       boolean result = false;
       try {
-         serverProcess = SpawnedVMSupport.spawnVM("org.apache.activemq.artemis.tests.integration.client.IncompatibleVersionTest",
new String[]{"-D" + VersionLoader.VERSION_PROP_FILE_KEY + "=" + propFileName}, "server", serverStartedString);
-         Thread.sleep(2000);
+         final CountDownLatch latch = new CountDownLatch(1);
+         Runnable runnable = new Runnable() {
+            @Override
+            public void run() {
+               latch.countDown();
+            }
+         };
 
+         serverProcess = SpawnedVMSupport.spawnVMWithLogMacher(WORD_START, runnable, "org.apache.activemq.artemis.tests.integration.client.IncompatibleVersionTest",
new String[]{"-D" + VersionLoader.VERSION_PROP_FILE_KEY + "=" + propFileName}, true, "server",
serverStartedString);
+         Assert.assertTrue(latch.await(30, TimeUnit.SECONDS));
          Process client = SpawnedVMSupport.spawnVM("org.apache.activemq.artemis.tests.integration.client.IncompatibleVersionTest",
new String[]{"-D" + VersionLoader.VERSION_PROP_FILE_KEY + "=" + propFileName}, "client");
 
          if (client.waitFor() == 0) {
@@ -212,6 +223,8 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
          ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, false);
          server.start();
 
+         System.out.println(WORD_START);
+
          log.info("### server: " + startedString);
       }
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/487d9767/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java
b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java
index 01bbd68..d7afaab 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/util/SpawnedVMSupport.java
@@ -59,6 +59,13 @@ public final class SpawnedVMSupport {
       return SpawnedVMSupport.spawnVM(className, "-Xms512m", "-Xmx512m", vmargs, logOutput,
true, args);
    }
 
+   public static Process spawnVMWithLogMacher(String wordMatch, Runnable runnable, final
String className,
+                                 final String[] vmargs,
+                                 final boolean logOutput,
+                                 final String... args) throws Exception {
+      return SpawnedVMSupport.spawnVM(wordMatch, runnable, className, "-Xms512m", "-Xmx512m",
vmargs, logOutput, true, args);
+   }
+
    public static Process spawnVM(final String className,
                                  final String memoryArg1,
                                  final String memoryArg2,
@@ -66,6 +73,18 @@ public final class SpawnedVMSupport {
                                  final boolean logOutput,
                                  final boolean logErrorOutput,
                                  final String... args) throws Exception {
+      return spawnVM(null, null, className, memoryArg1, memoryArg2, vmargs, logOutput, logErrorOutput,
args);
+   }
+
+   public static Process spawnVM(final String wordMatch,
+                                 final Runnable wordRunning,
+                                 final String className,
+                                 final String memoryArg1,
+                                 final String memoryArg2,
+                                 final String[] vmargs,
+                                 final boolean logOutput,
+                                 final boolean logErrorOutput,
+                                 final String... args) throws Exception {
       ProcessBuilder builder = new ProcessBuilder();
       final String javaPath = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath().toString();
       builder.command(javaPath, memoryArg1, memoryArg2, "-cp", System.getProperty("java.class.path"));
@@ -100,13 +119,13 @@ public final class SpawnedVMSupport {
       Process process = builder.start();
 
       if (logOutput) {
-         SpawnedVMSupport.startLogger(className, process);
+         SpawnedVMSupport.startLogger(wordMatch, wordRunning, className, process);
 
       }
 
       // Adding a reader to System.err, so the VM won't hang on a System.err.println as identified
on this forum thread:
       // http://www.jboss.org/index.html?module=bb&op=viewtopic&t=151815
-      ProcessLogger errorLogger = new ProcessLogger(logErrorOutput, process.getErrorStream(),
className);
+      ProcessLogger errorLogger = new ProcessLogger(logErrorOutput, process.getErrorStream(),
className, wordMatch, wordRunning);
       errorLogger.start();
 
       return process;
@@ -118,12 +137,21 @@ public final class SpawnedVMSupport {
     * @param process
     * @throws ClassNotFoundException
     */
-   public static void startLogger(final String className, final Process process) throws ClassNotFoundException
{
-      ProcessLogger outputLogger = new ProcessLogger(true, process.getInputStream(), className);
+   public static void startLogger(final String wordMatch, final Runnable wordRunanble, final
String className, final Process process) throws ClassNotFoundException {
+      ProcessLogger outputLogger = new ProcessLogger(true, process.getInputStream(), className,
wordMatch, wordRunanble);
       outputLogger.start();
    }
 
    /**
+    * @param className
+    * @param process
+    * @throws ClassNotFoundException
+    */
+   public static void startLogger(final String className, final Process process) throws ClassNotFoundException
{
+      startLogger(null, null, className, process);
+   }
+
+   /**
     * Assert that a process exits with the expected value (or not depending if
     * the <code>sameValue</code> is expected or not). The method waits 5
     * seconds for the process to exit, then an Exception is thrown. In any case,
@@ -165,10 +193,18 @@ public final class SpawnedVMSupport {
 
       private final boolean print;
 
-      ProcessLogger(final boolean print, final InputStream is, final String className) throws
ClassNotFoundException {
+      private final String wordMatch;
+      /**
+       * This will be executed when wordMatch is within any line on the log *
+       * * */
+      private final Runnable wordRunner;
+
+      ProcessLogger(final boolean print, final InputStream is, final String className, String
wordMatch, Runnable wordRunner) throws ClassNotFoundException {
          this.is = is;
          this.print = print;
          this.className = className;
+         this.wordMatch = wordMatch;
+         this.wordRunner = wordRunner;
          setDaemon(true);
       }
 
@@ -179,6 +215,11 @@ public final class SpawnedVMSupport {
             BufferedReader br = new BufferedReader(isr);
             String line = null;
             while ((line = br.readLine()) != null) {
+               if (wordMatch != null && wordRunner != null) {
+                  if (line.contains(wordMatch)) {
+                     wordRunner.run();
+                  }
+               }
                if (print) {
                   System.out.println(className + ":" + line);
                }


Mime
View raw message