This commit is contained in:
Clebert Suconic 2018-05-04 22:47:07 -04:00
commit 25f8820c58
17 changed files with 192 additions and 33 deletions

View File

@ -44,6 +44,10 @@ public class ThreadLeakCheckRule extends TestWatcher {
protected boolean testFailed = false;
protected Description testDescription = null;
protected Throwable failure = null;
protected Map<Thread, StackTraceElement[]> previousThreads;
/**
@ -65,7 +69,9 @@ public class ThreadLeakCheckRule extends TestWatcher {
@Override
protected void failed(Throwable e, Description description) {
this.failure = e;
this.testFailed = true;
this.testDescription = description;
}
@Override
@ -86,7 +92,7 @@ public class ThreadLeakCheckRule extends TestWatcher {
boolean failedOnce = false;
// if the test failed.. there's no point on waiting a full minute.. we will report it once and go
long timeout = System.currentTimeMillis() + (testFailed ? 1000 : 60000);
long timeout = System.currentTimeMillis() + (testFailed ? 30000 : 60000);
while (failed && timeout > System.currentTimeMillis()) {
failed = checkThread();
@ -108,6 +114,8 @@ public class ThreadLeakCheckRule extends TestWatcher {
System.out.println("***********************************************************************");
System.out.println(" The test failed and there is a leak");
System.out.println("***********************************************************************");
failure.printStackTrace();
Assert.fail("Test " + testDescription + " Failed with a leak - " + failure.getMessage());
}
} else if (failedOnce) {
System.out.println("******************** Threads cleared after retries ********************");

View File

@ -41,7 +41,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
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.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.apache.activemq.artemis.utils.VersionLoader;
import org.junit.After;
@ -51,7 +51,7 @@ import org.junit.Test;
import static org.apache.activemq.artemis.tests.util.RandomUtil.randomString;
public class IncompatibleVersionTest extends ActiveMQTestBase {
public class IncompatibleVersionTest extends SpawnedTestBase {
private static final String WORD_START = "&*STARTED&*";
private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER;
@ -91,6 +91,7 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
closeServerLocator(locator);
stopComponent(server);
SpawnedVMSupport.forceKill();
super.tearDown();
}
@ -105,32 +106,32 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
}
@Test
public void testCompatibleClientVersionWithRealConnection1() throws Exception {
public void testCompatibleClientVersionWithRealConnection1() throws Throwable {
assertTrue(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 1));
}
@Test
public void testCompatibleClientVersionWithRealConnection2() throws Exception {
public void testCompatibleClientVersionWithRealConnection2() throws Throwable {
assertTrue(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 5));
}
@Test
public void testCompatibleClientVersionWithRealConnection3() throws Exception {
public void testCompatibleClientVersionWithRealConnection3() throws Throwable {
assertTrue(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 10));
}
@Test
public void testIncompatibleClientVersionWithRealConnection1() throws Exception {
public void testIncompatibleClientVersionWithRealConnection1() throws Throwable {
assertFalse(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 0));
}
@Test
public void testIncompatibleClientVersionWithRealConnection2() throws Exception {
public void testIncompatibleClientVersionWithRealConnection2() throws Throwable {
assertFalse(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 4));
}
@Test
public void testIncompatibleClientVersionWithRealConnection3() throws Exception {
public void testIncompatibleClientVersionWithRealConnection3() throws Throwable {
assertFalse(doTestClientVersionCompatibilityWithRealConnection("1-3,5,7-10", 100));
}
@ -168,7 +169,7 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
}
}
private boolean doTestClientVersionCompatibilityWithRealConnection(String verList, int ver) throws Exception {
private boolean doTestClientVersionCompatibilityWithRealConnection(String verList, int ver) throws Throwable {
String propFileName = "compatibility-test-activemq-version.properties";
String serverStartedString = "IncompatibleVersionTest---server---started";
@ -180,6 +181,7 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
prop.store(new FileOutputStream("target/test-classes/" + propFileName), null);
Process serverProcess = null;
Process client = null;
boolean result = false;
try {
final CountDownLatch latch = new CountDownLatch(1);
@ -192,7 +194,7 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
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");
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) {
result = true;
@ -205,6 +207,13 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
/* ignore */
}
}
if (client != null) {
try {
client.destroy();
} catch (Throwable t) {
/* ignore */
}
}
}
return result;
@ -217,6 +226,11 @@ public class IncompatibleVersionTest extends ActiveMQTestBase {
ActiveMQServer server = ActiveMQServers.newActiveMQServer(config, false);
server.start();
while (!server.isStarted()) {
System.out.println("Still starting");
Thread.sleep(100);
}
System.out.println(WORD_START);
log.info("### server: " + startedString);

View File

@ -34,12 +34,12 @@ import org.apache.activemq.artemis.core.journal.PreparedTransactionInfo;
import org.apache.activemq.artemis.core.journal.RecordInfo;
import org.apache.activemq.artemis.core.journal.impl.JournalImpl;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Test;
public class JournalCrashTest extends ActiveMQTestBase {
public class JournalCrashTest extends SpawnedTestBase {
private static final int FIRST_RUN = 4;

View File

@ -78,7 +78,7 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.apache.activemq.artemis.tests.util.Wait;
import org.junit.After;
@ -86,7 +86,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class SendAckFailTest extends ActiveMQTestBase {
public class SendAckFailTest extends SpawnedTestBase {
@Before
@After

View File

@ -18,11 +18,11 @@ package org.apache.activemq.artemis.tests.integration.clientcrash;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.junit.Assert;
import org.junit.Before;
public abstract class ClientTestBase extends ActiveMQTestBase {
public abstract class ClientTestBase extends SpawnedTestBase {
protected ActiveMQServer server;

View File

@ -21,7 +21,7 @@ import java.util.List;
import org.apache.activemq.artemis.core.server.NodeManager;
import org.apache.activemq.artemis.core.server.impl.InVMNodeManager;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.junit.Test;
import static org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction.AWAIT_LIVE;
@ -36,7 +36,7 @@ import static org.apache.activemq.artemis.tests.integration.cluster.NodeManagerA
import static org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction.START_LIVE;
import static org.apache.activemq.artemis.tests.integration.cluster.NodeManagerAction.STOP_BACKUP;
public class NodeManagerTest extends ActiveMQTestBase {
public class NodeManagerTest extends SpawnedTestBase {
@Test
public void testLive() throws Exception {

View File

@ -35,12 +35,12 @@ import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager;
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Test;
public class CriticalCrashTest extends ActiveMQTestBase {
public class CriticalCrashTest extends SpawnedTestBase {
@Test
public void testCrash() throws Exception {

View File

@ -32,13 +32,13 @@ import org.apache.activemq.artemis.core.journal.impl.AbstractJournalUpdateTask;
import org.apache.activemq.artemis.core.journal.impl.JournalCompactor;
import org.apache.activemq.artemis.core.journal.impl.JournalFile;
import org.apache.activemq.artemis.core.journal.impl.JournalImpl;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class CrashOnCompactTest extends ActiveMQTestBase {
public class CrashOnCompactTest extends SpawnedTestBase {
static int OK = 2;
static int NOT_OK = 3;

View File

@ -31,7 +31,7 @@ import org.apache.activemq.artemis.core.journal.PreparedTransactionInfo;
import org.apache.activemq.artemis.core.journal.RecordInfo;
import org.apache.activemq.artemis.core.journal.impl.JournalImpl;
import org.apache.activemq.artemis.jlibaio.LibaioContext;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Test;
@ -39,7 +39,7 @@ import org.junit.Test;
/**
* This test spawns a remote VM, as we want to "crash" the VM right after the journal is filled with data
*/
public class ValidateTransactionHealthTest extends ActiveMQTestBase {
public class ValidateTransactionHealthTest extends SpawnedTestBase {
private static final int OK = 10;

View File

@ -29,14 +29,14 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class PageCountSyncOnNonTXTest extends ActiveMQTestBase {
public class PageCountSyncOnNonTXTest extends SpawnedTestBase {
public static final String WORD_START = "&*STARTED&*";

View File

@ -24,13 +24,13 @@ import java.net.URLDecoder;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedTestBase;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class NettySecurityClientTest extends ActiveMQTestBase {
public class NettySecurityClientTest extends SpawnedTestBase {
private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER;

View File

@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.activemq.artemis.tests.util;
import org.junit.Rule;
public class SpawnedTestBase extends ActiveMQTestBase {
@Rule
public SpawnedVMCheck spawnedVMCheck = new SpawnedVMCheck();
}

View File

@ -19,9 +19,11 @@ package org.apache.activemq.artemis.amqpJMS;
import java.io.IOException;
import java.util.Properties;
import org.apache.activemq.artemis.tests.util.SpawnedVMCheck;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@ -51,6 +53,10 @@ import org.objectweb.jtests.jms.framework.JMSTestCase;
@SuiteClasses({TopicConnectionTest.class, ConnectionTest.class, MessageBodyTest.class, MessageDefaultTest.class, MessageTypeTest.class, MessageHeaderTest.class, JMSXPropertyTest.class, MessagePropertyConversionTest.class, MessagePropertyTest.class, QueueBrowserTest.class, TemporaryQueueTest.class, SelectorSyntaxTest.class, SelectorTest.class, QueueSessionTest.class, SessionTest.class, TopicSessionTest.class, UnifiedSessionTest.class, TemporaryTopicTest.class,})
public class JoramAMQPAggregationTest extends Assert {
@Rule
public SpawnedVMCheck check = new SpawnedVMCheck();
/**
* Should be overridden
*

View File

@ -19,9 +19,11 @@ package org.apache.activemq.artemis.jms;
import java.io.IOException;
import java.util.Properties;
import org.apache.activemq.artemis.tests.util.SpawnedVMCheck;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@ -51,6 +53,9 @@ import org.objectweb.jtests.jms.framework.JMSTestCase;
@SuiteClasses({TopicConnectionTest.class, ConnectionTest.class, MessageBodyTest.class, MessageDefaultTest.class, MessageTypeTest.class, MessageHeaderTest.class, JMSXPropertyTest.class, MessagePropertyConversionTest.class, MessagePropertyTest.class, QueueBrowserTest.class, TemporaryQueueTest.class, SelectorSyntaxTest.class, SelectorTest.class, QueueSessionTest.class, SessionTest.class, TopicSessionTest.class, UnifiedSessionTest.class, TemporaryTopicTest.class,})
public class JoramCoreAggregationTest extends Assert {
@Rule
public SpawnedVMCheck check = new SpawnedVMCheck();
/**
* Should be overridden
*

View File

@ -19,9 +19,11 @@ package org.apache.activemq.artemis.tests.unit.core.util;
import java.util.HashSet;
import org.apache.activemq.artemis.tests.util.SpawnedVMCheck;
import org.apache.activemq.artemis.tests.util.SpawnedVMSupport;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
/**
@ -29,6 +31,9 @@ import org.junit.Test;
*/
public class RandomUtilDistributionTest {
@Rule
public SpawnedVMCheck check = new SpawnedVMCheck();
public static void main(String[] arg) {
long start = Long.parseLong(arg[0]);

View File

@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.activemq.artemis.tests.util;
import org.junit.rules.ExternalResource;
public class SpawnedVMCheck extends ExternalResource {
@Override
protected void after() {
super.after();
SpawnedVMSupport.checkProcess();
}
}

View File

@ -21,12 +21,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.activemq.artemis.tests.unit.UnitTestLogger;
@ -37,6 +40,8 @@ import static java.util.concurrent.TimeUnit.SECONDS;
public final class SpawnedVMSupport {
static ConcurrentHashMap<Process, String> startedProcesses = new ConcurrentHashMap();
private static final UnitTestLogger log = UnitTestLogger.LOGGER;
public static Process spawnVM(final String className, final String... args) throws Exception {
@ -94,7 +99,6 @@ public final class SpawnedVMSupport {
}
public static Process spawnVM(String classPath,
String wordMatch,
Runnable wordRunning,
@ -106,11 +110,10 @@ public final class SpawnedVMSupport {
boolean logErrorOutput,
boolean useLogging,
String... args) throws IOException, ClassNotFoundException {
return spawnVM(classPath, wordMatch, wordRunning, className, memoryArg1,memoryArg2, vmargs, logOutput, logErrorOutput, useLogging, -1, args);
return spawnVM(classPath, wordMatch, wordRunning, className, memoryArg1, memoryArg2, vmargs, logOutput, logErrorOutput, useLogging, -1, args);
}
/**
*
* @param classPath
* @param wordMatch
* @param wordRunning
@ -121,7 +124,7 @@ public final class SpawnedVMSupport {
* @param logOutput
* @param logErrorOutput
* @param useLogging
* @param debugPort if <=0 it means no debug
* @param debugPort if <=0 it means no debug
* @param args
* @return
* @throws IOException
@ -200,9 +203,72 @@ public final class SpawnedVMSupport {
ProcessLogger errorLogger = new ProcessLogger(logErrorOutput, process.getErrorStream(), className, wordMatch, wordRunning);
errorLogger.start();
startedProcesses.put(process, className);
return process;
}
/**
* it will return a pair of dead / alive servers
*
* @return
*/
private static HashSet<Process> getAliveProcesses() {
HashSet<Process> aliveProcess = new HashSet<>();
for (;;) {
try {
aliveProcess.clear();
for (Process process : startedProcesses.keySet()) {
if (process.isAlive()) {
aliveProcess.add(process);
process.destroyForcibly();
}
}
break;
} catch (Throwable e) {
e.printStackTrace();
}
}
return aliveProcess;
}
public static void forceKill() {
HashSet<Process> aliveProcess = getAliveProcesses();
for (Process alive : aliveProcess) {
for (int i = 0; i < 5; i++) {
alive.destroyForcibly();
try {
alive.waitFor(5, TimeUnit.SECONDS);
} catch (Exception e) {
}
}
}
}
public static void checkProcess() {
HashSet<Process> aliveProcess = getAliveProcesses();
try {
if (!aliveProcess.isEmpty()) {
StringBuffer buffer = new StringBuffer();
for (Process alive : aliveProcess) {
alive.destroyForcibly();
buffer.append(startedProcesses.get(alive) + " ");
}
Assert.fail("There are " + aliveProcess.size() + " processes alive :: " + buffer.toString());
}
} finally {
startedProcesses.clear();
}
}
/**
* @param className
* @param process