Skip to content

Commit

Permalink
ARTEMIS-4250 Spawning VM to avoid thread leaking on ShutdownOnCritica…
Browse files Browse the repository at this point in the history
…lIOErrorMoveNextTest
  • Loading branch information
clebertsuconic committed Apr 24, 2023
1 parent ef45012 commit 0eefc38
Showing 1 changed file with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.jms.MessageProducer;
import javax.jms.Session;
import java.io.File;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.activemq.artemis.api.core.Message;
Expand All @@ -40,35 +41,57 @@
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.Wait;
import org.apache.activemq.artemis.utils.SpawnedVMSupport;
import org.junit.Assert;
import org.junit.Test;

public class ShutdownOnCriticalIOErrorMoveNextTest extends ActiveMQTestBase {

private static final int OK = 3;

public static void main(String[] arg) {
ShutdownOnCriticalIOErrorMoveNextTest testInst = new ShutdownOnCriticalIOErrorMoveNextTest();
// some methods are not static, so we need an instance
testInst.testSimplyDownAfterErrorSpawned();
}

@Test
public void testSimplyDownAfterError() throws Exception {
deleteDirectory(new File("./target/server"));
ActiveMQServer server = createServer("./target/server");
Process process = SpawnedVMSupport.spawnVM(ShutdownOnCriticalIOErrorMoveNextTest.class.getName());
runAfter(process::destroyForcibly);
Assert.assertTrue(process.waitFor(10, TimeUnit.SECONDS));
Assert.assertEquals(OK, process.exitValue());
}

server.start();
public void testSimplyDownAfterErrorSpawned() {
try {
deleteDirectory(new File("./target/server"));
ActiveMQServer server = createServer("./target/server");

ConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection();
server.start();

Session session = connection.createSession();
ConnectionFactory factory = new ActiveMQConnectionFactory();
Connection connection = factory.createConnection();

MessageProducer producer = session.createProducer(session.createQueue("queue"));
Session session = connection.createSession();

try {
for (int i = 0; i < 500; i++) {
producer.send(session.createTextMessage("text"));
MessageProducer producer = session.createProducer(session.createQueue("queue"));

try {
for (int i = 0; i < 500; i++) {
producer.send(session.createTextMessage("text"));
}
} catch (JMSException expected) {
}
} catch (JMSException expected) {
}

Wait.waitFor(() -> !server.isStarted());
Wait.waitFor(() -> !server.isStarted());

Assert.assertFalse(server.isStarted());
Assert.assertFalse(server.isStarted());
System.exit(OK);
} catch (Throwable e) {
e.printStackTrace(System.out);
System.exit(-1);
}

}

Expand Down

0 comments on commit 0eefc38

Please sign in to comment.