Search in sources :

Example 31 with StubConnection

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

the class FailoverTransportBrokerTest method createRemoteConnection.

protected StubConnection createRemoteConnection() throws Exception {
    Transport transport = TransportFactory.connect(new URI(newURI(1)));
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport) URI(java.net.URI)

Example 32 with StubConnection

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

the class FanoutTransportBrokerTest method testPublisherWaitsForServerToBeUp.

/*
   public void initCombosForTestPublisherWaitsForServerToBeUp() {
      addCombinationValues("deliveryMode", new Object[]{Integer.valueOf(DeliveryMode.NON_PERSISTENT), Integer.valueOf(DeliveryMode.PERSISTENT)});
      addCombinationValues("destination", new Object[]{new ActiveMQTopic("TEST")});
   }
*/
@Test
public void testPublisherWaitsForServerToBeUp() throws Exception {
    if (name.getMethodName().contains("test-0") || name.getMethodName().contains("test-2")) {
        System.out.println("Discarding invalid test: " + name.getMethodName());
        return;
    }
    // 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.");
    final StubConnection connection3 = createFanoutConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    final 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);
    final CountDownLatch publishDone = new CountDownLatch(1);
    // The MockTransport is on the remote connection.
    // Slip in a new transport filter after the MockTransport
    MockTransport mt = connection3.getTransport().narrow(MockTransport.class);
    mt.install(new TransportFilter(mt.getNext()) {

        @Override
        public void oneway(Object command) throws IOException {
            LOG.info("Dropping: " + command);
        // just eat it! to simulate a recent failure.
        }
    });
    // Send a message (async) as this will block
    new Thread() {

        @Override
        public void run() {
            // Send the message using the fail over publisher.
            try {
                connection3.request(createMessage(producerInfo3, destination, deliveryMode));
            } catch (Throwable e) {
                e.printStackTrace();
            }
            publishDone.countDown();
        }
    }.start();
    // Assert that we block:
    Assert.assertFalse(publishDone.await(3, TimeUnit.SECONDS));
    // Restart the remote server. State should be re-played and the publish
    // should continue.
    LOG.info("Restarting Broker");
    restartRemoteBroker();
    LOG.info("Broker Restarted");
    // This should reconnect, and resend
    Assert.assertTrue(publishDone.await(20, TimeUnit.SECONDS));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) SessionInfo(org.apache.activemq.command.SessionInfo) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) TransportFilter(org.apache.activemq.transport.TransportFilter) StubConnection(org.apache.activemq.broker.StubConnection) MockTransport(org.apache.activemq.transport.mock.MockTransport) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) Test(org.junit.Test) OpenwireArtemisBaseTest(org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)

Example 33 with StubConnection

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

the class FanoutTransportBrokerTest method createRemoteConnection.

protected StubConnection createRemoteConnection() throws Exception {
    Transport transport = TransportFactory.connect(new URI(newURI(1)));
    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 34 with StubConnection

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

the class FanoutTransportBrokerTest method createConnection.

protected StubConnection createConnection() throws Exception {
    Transport transport = TransportFactory.connect(new URI(newURI(0)));
    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 35 with StubConnection

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

the class TransportBrokerTestSupport method createConnection.

@Override
protected StubConnection createConnection() throws Exception {
    URI bindURI = getBindURI();
    // Note: on platforms like OS X we cannot bind to the actual hostname, so we
    // instead use the original host name (typically localhost) to bind to
    URI actualURI = this.broker.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;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) URI(java.net.URI)

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