Package org.apache.qpid.testutil

Examples of org.apache.qpid.testutil.QpidClientConnection


     */
    public void testDrain() throws JMSException, InterruptedException
    {
        final String queueName = "direct://amq.direct//queue" + UUID.randomUUID().toString();

        QpidClientConnection conn = new QpidClientConnection(BROKER);

        conn.connect();
        // clear queue
        conn.consume(queueName, consumeTimeout);
        // load test data
        _logger.info("creating test data, " + numTestMessages + " messages");
        conn.put(queueName, payload, numTestMessages);
        // close this connection
        conn.disconnect();

        conn = new QpidClientConnection(BROKER);

        conn.connect();

        _logger.info("consuming queue " + queueName);
        Queue q = conn.getSession().createQueue(queueName);

        final MessageConsumer consumer = conn.getSession().createConsumer(q);
        int messagesReceived = 0;

        long[] messageLog = new long[numTestMessages + 1];

        _logger.info("consuming...");
        Message msg = consumer.receive(1000);
        while (msg != null)
        {
            messagesReceived++;

            long dt = ((AbstractJMSMessage) msg).getDeliveryTag();

            int msgindex = msg.getIntProperty("index");
            if (messageLog[msgindex] != 0)
            {
                _logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) msg).getDeliveryTag()
                    + ") more than once.");
            }

            if (_logger.isInfoEnabled())
            {
                _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt + "IN:" + msgindex);
            }

            if (dt == 0)
            {
                _logger.error("DT is zero for msg:" + msgindex);
            }

            messageLog[msgindex] = dt;

            // get Next message
            msg = consumer.receive(1000);
        }

        conn.getSession().commit();
        consumer.close();
        assertEquals("number of consumed messages does not match initial data", (int) numTestMessages, messagesReceived);

        int index = 0;
        StringBuilder list = new StringBuilder();
        list.append("Failed to receive:");
        int failed = 0;

        for (long b : messageLog)
        {
            if ((b == 0) && (index != 0)) // delivery tag of zero shouldn't exist
            {
                _logger.error("Index: " + index + " was not received.");
                list.append(" ");
                list.append(index);
                list.append(":");
                list.append(b);
                failed++;
            }

            index++;
        }

        assertEquals(list.toString(), 0, failed);
        _logger.info("consumed: " + messagesReceived);
        conn.disconnect();
        passed = true;

    }
View Full Code Here


     */
    public void testCompetingConsumers() throws JMSException, InterruptedException
    {
        final String queueName = "direct://amq.direct//queue" + UUID.randomUUID().toString();

        QpidClientConnection conn = new QpidClientConnection(BROKER);

        conn.connect();
        // clear queue
        conn.consume(queueName, consumeTimeout);
        // load test data
        _logger.info("creating test data, " + numTestMessages + " messages");
        conn.put(queueName, payload, numTestMessages);
        // close this connection
        conn.disconnect();

        Consumer c1 = new Consumer(queueName);
        Consumer c2 = new Consumer(queueName);
        Consumer c3 = new Consumer(queueName);
        Consumer c4 = new Consumer(queueName);
View Full Code Here

    public void testRequeue() throws JMSException, AMQException, URLSyntaxException, InterruptedException
    {
        final String queue = "direct://amq.direct//queue" + UUID.randomUUID().toString();

        QpidClientConnection conn = new QpidClientConnection(BROKER);

        conn.connect();
        // clear queue
        conn.consume(queue, consumeTimeout);
        // load test data
        _logger.info("creating test data, " + numTestMessages + " messages");
        conn.put(queue, payload, numTestMessages);
        // close this connection
        conn.disconnect();

        int run = 0;
        // while (run < 10)
        {
            run++;
View Full Code Here

        public void run()
        {
            try
            {
                _logger.info("consumer-" + id + ": starting");
                QpidClientConnection conn = new QpidClientConnection(BROKER);

                conn.connect();

                _logger.info("consumer-" + id + ": connected, consuming...");
                Message result;
                do
                {
                    result = conn.getNextMessage(_queueName, consumeTimeout);
                    if (result != null)
                    {

                        long dt = ((AbstractJMSMessage) result).getDeliveryTag();

                        if (testReception)
                        {
                            int msgindex = result.getIntProperty("index");
                            if (receieved[msgindex] != 0)
                            {
                                _logger.error("Received Message(" + msgindex + ":"
                                    + ((AbstractJMSMessage) result).getDeliveryTag() + ") more than once.");
                            }

                            if (_logger.isInfoEnabled())
                            {
                                _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt
                                    + "IN:" + msgindex);
                            }

                            if (dt == 0)
                            {
                                _logger.error("DT is zero for msg:" + msgindex);
                            }

                            receieved[msgindex] = dt;
                        }

                        count++;
                        if ((count % 100) == 0)
                        {
                            _logger.info("consumer-" + id + ": got " + result + ", new count is " + count);
                        }
                    }
                }
                while (result != null);

                _logger.info("consumer-" + id + ": complete");
                conn.disconnect();

            }
            catch (Exception e)
            {
                e.printStackTrace();
View Full Code Here

        public void run()
        {
            try
            {
                _logger.info("consumer-" + id + ": starting");
                QpidClientConnection conn = new QpidClientConnection(BROKER);

                conn.connect();

                _logger.info("consumer-" + id + ": connected, consuming...");
                Message result;
                do
                {
                    result = conn.getNextMessage(queue, consumeTimeout);
                    if (result != null)
                    {

                        long dt = ((AbstractJMSMessage) result).getDeliveryTag();

                        if (testReception)
                        {
                            int msgindex = result.getIntProperty("index");
                            if (receieved[msgindex] != 0)
                            {
                                _logger.error("Received Message(" + msgindex + ":"
                                    + ((AbstractJMSMessage) result).getDeliveryTag() + ") more than once.");
                            }

                            if (_logger.isInfoEnabled())
                            {
                                _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt
                                    + "IN:" + msgindex);
                            }

                            if (dt == 0)
                            {
                                _logger.error("DT is zero for msg:" + msgindex);
                            }

                            receieved[msgindex] = dt;
                        }

                        count++;
                        if ((count % 100) == 0)
                        {
                            _logger.info("consumer-" + id + ": got " + result + ", new count is " + count);
                        }
                    }
                }
                while (result != null);

                _logger.info("consumer-" + id + ": complete");
                conn.disconnect();

            }
            catch (Exception e)
            {
                e.printStackTrace();
View Full Code Here

    protected void setUp() throws Exception
    {
        super.setUp();
        TransportConnection.createVMBroker(1);

        QpidClientConnection conn = new QpidClientConnection(BROKER);

        conn.connect();
        // clear queue
        conn.consume(queue, consumeTimeout);
        // load test data
        _logger.info("creating test data, " + numTestMessages + " messages");
        conn.put(queue, payload, numTestMessages);
        // close this connection
        conn.disconnect();
    }
View Full Code Here

    {
        super.tearDown();

        if (!passed) // clean up
        {
            QpidClientConnection conn = new QpidClientConnection(BROKER);

            conn.connect();
            // clear queue
            conn.consume(queue, consumeTimeout);

            conn.disconnect();
        }

        TransportConnection.killVMBroker(1);
    }
View Full Code Here

     * @throws javax.jms.JMSException if a JMS problem occurs
     * @throws InterruptedException   on timeout
     */
    public void testDrain() throws JMSException, InterruptedException
    {
        QpidClientConnection conn = new QpidClientConnection(BROKER);

        conn.connect();

        _logger.info("consuming queue " + queue);
        Queue q = conn.getSession().createQueue(queue);

        final MessageConsumer consumer = conn.getSession().createConsumer(q);
        int messagesReceived = 0;

        long[] messageLog = new long[numTestMessages + 1];

        _logger.info("consuming...");
        Message msg = consumer.receive(1000);
        while (msg != null)
        {
            messagesReceived++;

            long dt = ((AbstractJMSMessage) msg).getDeliveryTag();

            int msgindex = msg.getIntProperty("index");
            if (messageLog[msgindex] != 0)
            {
                _logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) msg).getDeliveryTag()
                    + ") more than once.");
            }

            if (_logger.isInfoEnabled())
            {
                _logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt + "IN:" + msgindex);
            }

            if (dt == 0)
            {
                _logger.error("DT is zero for msg:" + msgindex);
            }

            messageLog[msgindex] = dt;

            // get Next message
            msg = consumer.receive(1000);
        }

        conn.getSession().commit();
        consumer.close();
        assertEquals("number of consumed messages does not match initial data", (int) numTestMessages, messagesReceived);

        int index = 0;
        StringBuilder list = new StringBuilder();
        list.append("Failed to receive:");
        int failed = 0;

        for (long b : messageLog)
        {
            if ((b == 0) && (index != 0)) // delivery tag of zero shouldn't exist
            {
                _logger.error("Index: " + index + " was not received.");
                list.append(" ");
                list.append(index);
                list.append(":");
                list.append(b);
                failed++;
            }

            index++;
        }

        assertEquals(list.toString(), 0, failed);
        _logger.info("consumed: " + messagesReceived);
        conn.disconnect();
        passed = true;
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.testutil.QpidClientConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.