ARTEMIS-277 IncompatibleVersionTest fails on slower machines

This closes #216
This commit is contained in:
Clebert Suconic 2015-10-26 09:53:21 -04:00
parent c9e823b1ca
commit 487d976760
2 changed files with 63 additions and 9 deletions

View File

@ -19,15 +19,16 @@ package org.apache.activemq.artemis.tests.integration.client;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; 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.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQIncompatibleClientServerException; import org.apache.activemq.artemis.api.core.ActiveMQIncompatibleClientServerException;
import org.apache.activemq.artemis.api.core.TransportConfiguration; 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.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; 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.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.Configuration;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.protocol.core.Channel; 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.core.version.impl.VersionImpl;
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger; import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; 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.apache.activemq.artemis.utils.VersionLoader;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -51,6 +54,7 @@ import static org.apache.activemq.artemis.tests.util.RandomUtil.randomString;
public class IncompatibleVersionTest extends ActiveMQTestBase { public class IncompatibleVersionTest extends ActiveMQTestBase {
private static final String WORD_START = "&*STARTED&*";
private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER; private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER;
// Constants ----------------------------------------------------- // Constants -----------------------------------------------------
@ -182,9 +186,16 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
Process serverProcess = null; Process serverProcess = null;
boolean result = false; boolean result = false;
try { try {
serverProcess = SpawnedVMSupport.spawnVM("org.apache.activemq.artemis.tests.integration.client.IncompatibleVersionTest", new String[]{"-D" + VersionLoader.VERSION_PROP_FILE_KEY + "=" + propFileName}, "server", serverStartedString); final CountDownLatch latch = new CountDownLatch(1);
Thread.sleep(2000); 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"); 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) { if (client.waitFor() == 0) {
@ -212,6 +223,8 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, false); ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, false);
server.start(); server.start();
System.out.println(WORD_START);
log.info("### server: " + startedString); log.info("### server: " + startedString);
} }
} }

View File

@ -59,6 +59,13 @@ public final class SpawnedVMSupport {
return SpawnedVMSupport.spawnVM(className, "-Xms512m", "-Xmx512m", vmargs, logOutput, true, args); 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, public static Process spawnVM(final String className,
final String memoryArg1, final String memoryArg1,
final String memoryArg2, final String memoryArg2,
@ -66,6 +73,18 @@ public final class SpawnedVMSupport {
final boolean logOutput, final boolean logOutput,
final boolean logErrorOutput, final boolean logErrorOutput,
final String... args) throws Exception { 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(); ProcessBuilder builder = new ProcessBuilder();
final String javaPath = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath().toString(); final String javaPath = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath().toString();
builder.command(javaPath, memoryArg1, memoryArg2, "-cp", System.getProperty("java.class.path")); builder.command(javaPath, memoryArg1, memoryArg2, "-cp", System.getProperty("java.class.path"));
@ -100,13 +119,13 @@ public final class SpawnedVMSupport {
Process process = builder.start(); Process process = builder.start();
if (logOutput) { 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: // 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 // 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(); errorLogger.start();
return process; return process;
@ -118,11 +137,20 @@ public final class SpawnedVMSupport {
* @param process * @param process
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
public static void startLogger(final String className, final Process process) throws ClassNotFoundException { 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); ProcessLogger outputLogger = new ProcessLogger(true, process.getInputStream(), className, wordMatch, wordRunanble);
outputLogger.start(); 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 * 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 * the <code>sameValue</code> is expected or not). The method waits 5
@ -165,10 +193,18 @@ public final class SpawnedVMSupport {
private final boolean print; 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.is = is;
this.print = print; this.print = print;
this.className = className; this.className = className;
this.wordMatch = wordMatch;
this.wordRunner = wordRunner;
setDaemon(true); setDaemon(true);
} }
@ -179,6 +215,11 @@ public final class SpawnedVMSupport {
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
String line = null; String line = null;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
if (wordMatch != null && wordRunner != null) {
if (line.contains(wordMatch)) {
wordRunner.run();
}
}
if (print) { if (print) {
System.out.println(className + ":" + line); System.out.println(className + ":" + line);
} }