use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSPagingFileDeleteTest method testTopics.
@Test
public void testTopics() throws Exception {
connection = null;
try {
connection = cf.createConnection();
connection.setClientID("cid");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic1);
subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");
// -----------------(Step1) Publish Messages to make Paging Files. --------------------
System.out.println("---------- Send messages. ----------");
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++) {
producer.send(bytesMessage);
}
System.out.println("Sent " + JMSPagingFileDeleteTest.MESSAGE_NUM + " messages.");
pagingStore = server.getPagingManager().getPageStore(new SimpleString("topic1"));
printPageStoreInfo(pagingStore);
assertTrue(pagingStore.isPaging());
connection.start();
// -----------------(Step2) Restart the server. --------------------------------------
// If try this test without restarting server, please comment out this line;
stopAndStartServer();
// -----------------(Step3) Subscribe to all the messages from the topic.--------------
System.out.println("---------- Receive all messages. ----------");
for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++) {
Message message1 = subscriber1.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
assertNotNull(message1);
Message message2 = subscriber2.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
assertNotNull(message2);
}
pagingStore = server.getPagingManager().getPageStore(new SimpleString("topic1"));
long timeout = System.currentTimeMillis() + 5000;
while (timeout > System.currentTimeMillis() && pagingStore.isPaging()) {
Thread.sleep(100);
}
assertFalse(pagingStore.isPaging());
printPageStoreInfo(pagingStore);
assertEquals(0, pagingStore.getAddressSize());
// assertEquals(1, pagingStore.getNumberOfPages()); //I expected number of the page is 1, but It was not.
// I expected IsPaging is false, but It was true.
assertFalse(pagingStore.isPaging());
// If the server is not restart, this test pass.
// -----------------(Step4) Publish a message. the message is stored in the paging file.
producer = session.createProducer(topic1);
bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
producer.send(bytesMessage);
printPageStoreInfo(pagingStore);
timeout = System.currentTimeMillis() + 10000;
while (timeout > System.currentTimeMillis() && pagingStore.getNumberOfPages() != 1) {
Thread.sleep(100);
}
// I expected number of the page is 1, but It was not.
assertEquals(1, pagingStore.getNumberOfPages());
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSPagingFileDeleteTest method testTopicsWithNonDurableSubscription.
/**
* Test replicating issue JBPAPP-9603
*
* @throws Exception
*/
@Test
public void testTopicsWithNonDurableSubscription() throws Exception {
connection = null;
try {
for (int repeat = 0; repeat < 2; repeat++) {
connection = cf.createConnection();
connection.setClientID("cid");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic1);
subscriber1 = session.createConsumer(topic1);
// -----------------(Step1) Publish Messages to make Paging Files. --------------------
System.out.println("---------- Send messages. ----------");
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++) {
producer.send(bytesMessage);
}
System.out.println("Sent " + JMSPagingFileDeleteTest.MESSAGE_NUM + " messages.");
pagingStore = server.getPagingManager().getPageStore(new SimpleString("topic1"));
printPageStoreInfo(pagingStore);
assertTrue(pagingStore.isPaging());
// -----------------(Step2) Closing the connection alone should cleanup pages -------
connection.close();
// note that if we closed subscriber or session the bug wouldn't happen
// as they were already deleting the page-subscription properly
// So, you can't close subscriber1 or session as that would change the test
// subscriber1.close(); // << you can't call this on this test
// session.close(); // << can't call this on this test
Wait.assertFalse(pagingStore::isPaging);
printPageStoreInfo(pagingStore);
}
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromOpenWire.
@Test(timeout = 30000)
public void testSendLargeMessageToClientFromOpenWire() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
JmsConnection connection = (JmsConnection) factory.createConnection();
sendLargeMessageViaOpenWire();
try {
Session session = connection.createSession();
Queue queue = session.createQueue(getQueueName());
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(1000);
assertNotNull(message);
assertTrue(message instanceof BytesMessage);
} finally {
connection.close();
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromAMQP.
@Ignore("Broker can't accept messages over 65535 right now")
@Test(timeout = 30000)
public void testSendLargeMessageToClientFromAMQP() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
JmsConnection connection = (JmsConnection) factory.createConnection();
sendLargeMessageViaAMQP();
try {
Session session = connection.createSession();
Queue queue = session.createQueue(getQueueName());
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
Message message = consumer.receive(1000);
assertNotNull(message);
assertTrue(message instanceof BytesMessage);
} finally {
connection.close();
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class JMSConsumerTest method testSendReceiveBytesMessage.
public void testSendReceiveBytesMessage() throws Exception {
// Receive a message with the JMS API
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = createDestination(session, destinationType);
MessageConsumer consumer = session.createConsumer(destination);
MessageProducer producer = session.createProducer(destination);
BytesMessage message = session.createBytesMessage();
message.writeBoolean(true);
message.writeBoolean(false);
producer.send(message);
// Make sure only 1 message was delivered.
BytesMessage m = (BytesMessage) consumer.receive(1000);
assertNotNull(m);
assertTrue(m.readBoolean());
assertFalse(m.readBoolean());
assertNull(consumer.receiveNoWait());
}
Aggregations