Search in sources :

Example 11 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class FanoutTransportBrokerTest method testPublisherFansout.

@Test
public void testPublisherFansout() throws Exception {
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a fanout publisher.
    LOG.info("Starting the fanout connection.");
    StubConnection connection3 = createFanoutConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connection1));
    assertNoMessagesLeft(connection1);
    Assert.assertNotNull(receiveMessage(connection2));
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)

Example 12 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class FanoutTransportBrokerTest method createFanoutConnection.

protected StubConnection createFanoutConnection() throws Exception {
    URI fanoutURI = new URI("fanout://(static://(" + newURI(0) + "," + "mock://" + newURI(1) + "))?fanOutQueues=true");
    Transport transport = TransportFactory.connect(fanoutURI);
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport) MockTransport(org.apache.activemq.transport.mock.MockTransport) URI(java.net.URI)

Example 13 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class TransportBrokerTestSupport method tearDown.

@Override
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();
    }
    super.tearDown();
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection)

Example 14 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class AdvisoryBrokerTest method testConnectionAdvisories.

public void testConnectionAdvisories() throws Exception {
    ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should get an advisory of our own connection.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());
    // Setup a second connection
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    connection2.send(connectionInfo2);
    // We should get an advisory of the second connection.
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConnectionInfo) m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());
    // Close the second connection.
    connection2.send(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the second connection closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), connectionInfo2.getConnectionId());
    assertNoMessagesLeft(connection1);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 15 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class AdvisoryBrokerTest method testConsumerAdvisories.

public void testConsumerAdvisories() throws Exception {
    ActiveMQDestination queue = new ActiveMQQueue("test");
    ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(consumerInfo1);
    // We should not see and advisory for the advisory consumer.
    assertNoMessagesLeft(connection1);
    // Setup a second consumer.
    StubConnection connection2 = createConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
    consumerInfo1.setPrefetchSize(100);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.send(consumerInfo2);
    // We should get an advisory of the new consumer.
    Message m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    assertEquals(((ConsumerInfo) m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());
    // Close the second connection.
    connection2.request(closeConnectionInfo(connectionInfo2));
    connection2.stop();
    // We should get an advisory of the consumer closing
    m1 = receiveMessage(connection1);
    assertNotNull(m1);
    assertNotNull(m1.getDataStructure());
    RemoveInfo r = (RemoveInfo) m1.getDataStructure();
    assertEquals(r.getObjectId(), consumerInfo2.getConsumerId());
    assertNoMessagesLeft(connection2);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) RemoveInfo(org.apache.activemq.command.RemoveInfo) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

StubConnection (org.apache.activemq.broker.StubConnection)39 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)17 Transport (org.apache.activemq.transport.Transport)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)14 Message (org.apache.activemq.command.Message)13 URI (java.net.URI)9 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)8 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)5 MockTransport (org.apache.activemq.transport.mock.MockTransport)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 OpenwireArtemisBaseTest (org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)3 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)3 FailoverTransport (org.apache.activemq.transport.failover.FailoverTransport)2 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MessageNotWriteableException (javax.jms.MessageNotWriteableException)1