use of org.apache.activemq.artemis.jms.client.ActiveMQSession in project activemq-artemis by apache.
the class JMSFailoverTest method testSendReceiveLargeMessages.
@Test
public void testSendReceiveLargeMessages() throws Exception {
SimpleString QUEUE = new SimpleString("somequeue");
ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc, backuptc);
jbcf.setReconnectAttempts(-1);
jbcf.setBlockOnDurableSend(true);
jbcf.setBlockOnNonDurableSend(true);
jbcf.setMinLargeMessageSize(1024);
// jbcf.setConsumerWindowSize(0);
// jbcf.setMinLargeMessageSize(1024);
final CountDownLatch flagAlign = new CountDownLatch(1);
final CountDownLatch waitToKill = new CountDownLatch(1);
final AtomicBoolean killed = new AtomicBoolean(false);
jbcf.getServerLocator().addIncomingInterceptor(new Interceptor() {
int count = 0;
@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
if (packet instanceof SessionReceiveContinuationMessage) {
if (count++ == 300 && !killed.get()) {
System.out.println("sending countDown on latch waitToKill");
killed.set(true);
waitToKill.countDown();
}
}
return true;
}
});
Connection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
final ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
// The thread that will fail the server
Thread spoilerThread = new Thread() {
@Override
public void run() {
flagAlign.countDown();
// a large timeout just to help in case of debugging
try {
waitToKill.await(120, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println("Killing server...");
JMSUtil.crash(liveServer, coreSession);
} catch (Exception e) {
e.printStackTrace();
}
}
};
coreSession.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, true);
Queue queue = sess.createQueue("somequeue");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
for (int i = 0; i < 100; i++) {
TextMessage message = sess.createTextMessage(new String(new byte[10 * 1024]));
producer.send(message);
if (i % 10 == 0) {
sess.commit();
}
}
sess.commit();
conn.start();
spoilerThread.start();
assertTrue(flagAlign.await(10, TimeUnit.SECONDS));
MessageConsumer consumer = sess.createConsumer(queue);
// this test is not meant to validate transactionality during Failover as that would require XA and recovery
for (int i = 0; i < 90; i++) {
TextMessage message = null;
int retryNrs = 0;
do {
retryNrs++;
try {
message = (TextMessage) consumer.receive(5000);
assertNotNull(message);
break;
} catch (JMSException e) {
new Exception("Exception on receive message", e).printStackTrace();
}
} while (retryNrs < 10);
assertNotNull(message);
try {
sess.commit();
} catch (Exception e) {
new Exception("Exception during commit", e);
sess.rollback();
}
}
conn.close();
spoilerThread.join();
}
Aggregations