Skip to content

Commit

Permalink
ARTEMIS-525 Adding test on interrupted exception and regular receivers
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed May 19, 2016
1 parent 1dcdc26 commit 37bc511
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.activemq.artemis.tests.integration.client;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.io.IOException;
Expand All @@ -37,6 +41,7 @@
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.config.StoreConfiguration;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
import org.apache.activemq.artemis.tests.integration.largemessage.LargeMessageTestBase;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
Expand Down Expand Up @@ -203,6 +208,64 @@ public void run() {
server.stop();
}



@Test
public void testForcedInterruptUsingJMS() throws Exception {
ActiveMQServer server = createServer(true, isNetty());

server.start();


SimpleString jmsAddress = new SimpleString("jms.queue.Test");

server.createQueue(jmsAddress, jmsAddress, null, true, false);

final AtomicInteger unexpectedErrors = new AtomicInteger(0);
final AtomicInteger expectedErrors = new AtomicInteger(0);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://0");
Connection connection = cf.createConnection();
Session session = connection.createSession(Session.SESSION_TRANSACTED);
connection.start();
final MessageConsumer consumer = session.createConsumer(session.createQueue(jmsAddress.toString()));

Thread t = new Thread() {
@Override
public void run() {
try {
System.out.println("Receiving message");
javax.jms.Message msg = consumer.receive(5000);
if (msg == null) {
System.err.println("Message not received");
unexpectedErrors.incrementAndGet();
return;
}
}
catch (JMSException e) {
log.debug("This exception was ok as it was expected", e);
expectedErrors.incrementAndGet();
}
catch (Throwable e) {
log.warn("Captured unexpected exception", e);
unexpectedErrors.incrementAndGet();
}
}
};

t.start();
t.interrupt();

t.join();

Assert.assertEquals(0, unexpectedErrors.get());
Assert.assertEquals(1, expectedErrors.get());

session.close();

server.stop();
}


@Test
public void testSendNonPersistentQueue() throws Exception {

Expand Down

0 comments on commit 37bc511

Please sign in to comment.