Search in sources :

Example 31 with BytesMessage

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();
        }
    }
}
Also used : BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Test(org.junit.Test)

Example 32 with BytesMessage

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();
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Test(org.junit.Test)

Example 33 with BytesMessage

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();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 34 with BytesMessage

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();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with BytesMessage

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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Aggregations

BytesMessage (javax.jms.BytesMessage)195 Session (javax.jms.Session)79 MessageProducer (javax.jms.MessageProducer)78 MessageConsumer (javax.jms.MessageConsumer)71 Test (org.junit.Test)62 Message (javax.jms.Message)57 TextMessage (javax.jms.TextMessage)54 Connection (javax.jms.Connection)41 JMSException (javax.jms.JMSException)39 Queue (javax.jms.Queue)37 MapMessage (javax.jms.MapMessage)34 ObjectMessage (javax.jms.ObjectMessage)30 StreamMessage (javax.jms.StreamMessage)24 HashMap (java.util.HashMap)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Map (java.util.Map)15 Topic (javax.jms.Topic)14 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)12 IOException (java.io.IOException)11 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10