use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.
the class GroupingTest method testGroupingRollbackOnClose.
@Test
public void testGroupingRollbackOnClose() throws Exception {
ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
fact.setConsumerWindowSize(1000);
fact.setTransactionBatchSize(0);
Connection connection = fact.createConnection();
RemotingConnection rc = server.getRemotingService().getConnections().iterator().next();
Connection connection2 = fact.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Session session2 = connection2.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
MessageConsumer consumer2 = session2.createConsumer(queue);
connection.start();
connection2.start();
String jmsxgroupID = null;
for (int j = 0; j < 100; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
setProperty(message);
producer.send(message);
String prop = message.getStringProperty("JMSXGroupID");
assertNotNull(prop);
if (jmsxgroupID != null) {
assertEquals(jmsxgroupID, prop);
} else {
jmsxgroupID = prop;
}
}
session.commit();
// consume 5 msgs from 1st first consumer
for (int j = 0; j < 1; j++) {
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message" + j, tm.getText());
assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
}
Thread.sleep(2000);
// session.rollback();
// session.close();
// consume all msgs from 2nd first consumer
// ClientSession amqs = ((ActiveMQSession) session).getCoreSession();
// ((DelegatingSession) amqs).getChannel().close();
rc.fail(new ActiveMQNotConnectedException());
for (int j = 0; j < 10; j++) {
TextMessage tm = (TextMessage) consumer2.receive(10000);
assertNotNull(tm);
long text = ((ActiveMQTextMessage) tm).getCoreMessage().getMessageID();
System.out.println(tm.getJMSMessageID() + " text = " + text);
// assertEquals("Message" + j, text);
assertEquals(tm.getStringProperty("JMSXGroupID"), jmsxgroupID);
}
connection.close();
connection2.close();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.
the class MessageHeaderTest method testCopyOnForeignTextMessage.
@Test
public void testCopyOnForeignTextMessage() throws JMSException {
ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
ClientSession session = new FakeSession(clientMessage);
TextMessage foreignTextMessage = new SimpleJMSTextMessage();
ActiveMQTextMessage copy = new ActiveMQTextMessage(foreignTextMessage, session);
MessageHeaderTestBase.ensureEquivalent(foreignTextMessage, copy);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.
the class MessageConsumerRollbackTest method sendMessages.
/**
* @param numberOfMessages
* @param session
* @throws Exception
*/
private void sendMessages(int numberOfMessages, ClientSession session) throws Exception {
ClientProducer producer = session.createProducer(inQueue);
for (int i = 0; i < numberOfMessages; i++) {
ActiveMQTextMessage txt = new ActiveMQTextMessage(session);
txt.setIntProperty("msg", i);
txt.setText("Message Number (" + i + ")");
txt.doBeforeSend();
producer.send(txt.getCoreMessage());
}
session.commit();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.
the class JournalPendingMessageTest method testQueueLargeMessageSize.
@Test
public void testQueueLargeMessageSize() throws Exception {
ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
acf.setMinLargeMessageSize(1000);
Connection connection = cf.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
String testText = StringUtils.repeat("t", 5000);
ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
session.createProducer(session.createQueue(defaultQueueName)).send(message);
verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
connection.close();
this.killServer();
this.restartServer();
verifyPendingStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
verifyPendingDurableStats(defaultQueueName, 1, message.getCoreMessage().getPersistentSize());
}
use of org.apache.activemq.artemis.jms.client.ActiveMQTextMessage in project activemq-artemis by apache.
the class JournalPendingMessageTest method testQueueLargeMessageSizeTX.
@Test
public void testQueueLargeMessageSizeTX() throws Exception {
ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf;
acf.setMinLargeMessageSize(1000);
Connection connection = cf.createConnection();
connection.start();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
String testText = StringUtils.repeat("t", 2000);
MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName));
ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText);
for (int i = 0; i < 10; i++) {
producer.send(message);
}
// not commited so should be 0
verifyPendingStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);
verifyPendingDurableStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10);
session.commit();
verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);
verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10);
connection.close();
this.killServer();
this.restartServer();
verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize());
}
Aggregations