Package org.apache.activemq.broker

Examples of org.apache.activemq.broker.StubConnection


        return connection;
    }

    protected StubConnection createSecondRemoteConnection() throws Exception {
        Transport transport = TransportFactory.connect(secondRemoteConnector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here


    }

    public void testSendThenAddConsumer() throws Exception {

        // Start a producer on local broker
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo);

        destination = createDestinationInfo(connection1, connectionInfo1, destinationType);

        // Start a consumer on a remote broker
        final StubConnection connection2 = createRemoteConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);

        // Send the message to the local broker.
        connection1.send(createMessage(producerInfo, destination, deliveryMode));

        // Verify that the message stayed on the local broker.
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
        connection1.send(consumerInfo1);
        Message m = receiveMessage(connection1);
        assertNotNull(m);
        // Close consumer to cause the message to rollback.
        connection1.send(consumerInfo1.createRemoveCommand());

        // Now create remote consumer that should cause message to move to this
        // remote consumer.
        ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
        connection2.request(consumerInfo2);

        // Make sure the message was delivered via the remote.
        assertTrue("message was received", Wait.waitFor(new Wait.Condition() {
            @Override
            public boolean isSatisified() throws Exception {
View Full Code Here

    }

    public void testAddConsumerThenSend() throws Exception {

        // Start a producer on local broker
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo);

        destination = createDestinationInfo(connection1, connectionInfo1, destinationType);

        // Start a consumer on a remote broker
        StubConnection connection2 = createRemoteConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo2, destination);
        connection2.send(consumerInfo);

        // Give demand forwarding bridge a chance to finish forwarding the
        // subscriptions.
        try {
            Thread.sleep(1000);
View Full Code Here

    }

    @Override
    protected StubConnection createConnection() throws Exception {
        Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

        return connection;
    }

    protected StubConnection createRemoteConnection() throws Exception {
        Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

    }

    @Override
    protected void tearDown() throws Exception {
        for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
            StubConnection connection = iter.next();
            connection.stop();
            iter.remove();
        }

        BrokerRegistry.getInstance().unbind("remotehost");
        remoteConnector.stop();
View Full Code Here

    public void testLargeQueuePersistentMessagesNotLostOnRestart() throws Exception {

        ActiveMQDestination destination = new ActiveMQQueue("TEST");

        // Setup the producer and send the message.
        StubConnection connection = createConnection();
        ConnectionInfo connectionInfo = createConnectionInfo();
        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        connection.send(producerInfo);

        ArrayList<String> expected = new ArrayList<String>();

        int MESSAGE_COUNT = 10000;
        for(int i=0; i < MESSAGE_COUNT; i++) {
            Message message = createMessage(producerInfo, destination);
            message.setPersistent(true);
            connection.send(message);
            expected.add(message.getMessageId().toString());
        }
        connection.request(closeConnectionInfo(connectionInfo));

        // restart the broker.
        restartBroker();

        // Setup the consumer and receive the message.
        connection = createConnection();
        connectionInfo = createConnectionInfo();
        sessionInfo = createSessionInfo(connectionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
        connection.send(consumerInfo);
        producerInfo = createProducerInfo(sessionInfo);
        connection.send(producerInfo);

        for(int i=0; i < MESSAGE_COUNT/2; i++) {
            Message m = receiveMessage(connection);
            assertNotNull("Should have received message "+expected.get(0)+" by now!", m);
            assertEquals(expected.remove(0), m.getMessageId().toString());
            MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
            connection.send(ack);
        }

        connection.request(closeConnectionInfo(connectionInfo));

        // restart the broker.
        restartBroker();

        // Setup the consumer and receive the message.
        connection = createConnection();
        connectionInfo = createConnectionInfo();
        sessionInfo = createSessionInfo(connectionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        consumerInfo = createConsumerInfo(sessionInfo, destination);
        connection.send(consumerInfo);

        for(int i=0; i < MESSAGE_COUNT/2; i++) {
            Message m = receiveMessage(connection);
            assertNotNull("Should have received message "+expected.get(i)+" by now!", m);
            assertEquals(expected.get(i), m.getMessageId().toString());
            MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
            connection.send(ack);


        }

        connection.request(closeConnectionInfo(connectionInfo));
    }
View Full Code Here

   
    protected abstract String getBindLocation();

    protected void tearDown() throws Exception {
        for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext();) {
            StubConnection connection = iter.next();
            connection.stop();
            iter.remove();
        }
        if( connector!=null ) {
            connector.stop();
        }
View Full Code Here

        URI actualURI = connector.getServer().getConnectURI();
        URI connectURI = new URI(actualURI.getScheme(), actualURI.getUserInfo(), bindURI.getHost(), actualURI.getPort(), actualURI.getPath(), bindURI
                .getQuery(), bindURI.getFragment());

        Transport transport = TransportFactory.connect(connectURI);
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

    public void testConsumerPrefetchAtOne() throws Exception {
       
        // Make sure the broker is created due to the connection being started.
        assertNull(BrokerRegistry.getInstance().lookup("localhost"));       
        StubConnection connection = createConnection();
        assertNotNull(BrokerRegistry.getInstance().lookup("localhost"));

        // Start a producer and consumer
        ConnectionInfo connectionInfo = createConnectionInfo();
        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        connection.send(producerInfo);
       
        ActiveMQQueue destination = new ActiveMQQueue("TEST");

        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination)
        consumerInfo.setPrefetchSize(1);
        connection.send(consumerInfo);
       
        // Send 2 messages to the broker.
        connection.send(createMessage(producerInfo, destination, DeliveryMode.NON_PERSISTENT));
        connection.send(createMessage(producerInfo, destination, DeliveryMode.NON_PERSISTENT));
       
        // Make sure only 1 message was delivered.
        Message m = receiveMessage(connection);
        assertNotNull(m);
        assertNoMessagesLeft(connection);
       
        // Make sure the broker is shutdown when the connection is stopped.
        assertNotNull(BrokerRegistry.getInstance().lookup("localhost"));       
        connection.stop();
        assertNull(BrokerRegistry.getInstance().lookup("localhost"));       
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.broker.StubConnection

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.