Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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