Search in sources :

Example 56 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ClusteredBridgeReconnectTest method testReconnectBridge.

@Test
@BMRules(rules = { @BMRule(name = "enter", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.enterConnect();"), @BMRule(name = "exit", targetClass = "org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl", targetMethod = "connect", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.exitConnect();"), @BMRule(name = "send", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl", targetMethod = "send(org.apache.activemq.artemis.core.protocol.core.Packet)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.ClusteredBridgeReconnectTest.send();") })
public void testReconnectBridge() throws Exception {
    setupServer(0, isFileStorage(), isNetty());
    setupServer(1, isFileStorage(), isNetty());
    setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 0, 1);
    setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.ON_DEMAND, 1, isNetty(), 1, 0);
    startServers(0, 1);
    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());
    createQueue(0, "queues.testaddress", "queue0", null, true);
    createQueue(1, "queues.testaddress", "queue0", null, true);
    addConsumer(0, 0, "queue0", null);
    addConsumer(1, 1, "queue0", null);
    waitForBindings(0, "queues.testaddress", 1, 1, true);
    waitForBindings(1, "queues.testaddress", 1, 1, true);
    waitForBindings(0, "queues.testaddress", 1, 1, false);
    waitForBindings(1, "queues.testaddress", 1, 1, false);
    ClientSession session0 = sfs[0].createSession();
    ClientSession session1 = sfs[0].createSession();
    session0.start();
    session1.start();
    ClientProducer producer = session0.createProducer("queues.testaddress");
    int NUMBER_OF_MESSAGES = 100;
    Assert.assertEquals(1, servers[0].getClusterManager().getClusterConnections().size());
    ClusterConnectionImpl connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
    Assert.assertEquals(1, connection.getRecords().size());
    MessageFlowRecord record = connection.getRecords().values().toArray(new MessageFlowRecord[1])[0];
    ClusterConnectionBridge bridge = (ClusterConnectionBridge) record.getBridge();
    for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
        ClientMessage msg = session0.createMessage(true);
        producer.send(msg);
        session0.commit();
        if (i == 17) {
            shouldFail = true;
            bridge.getSessionFactory().getConnection().fail(new ActiveMQException("failed once!"));
        }
    }
    int cons0Count = 0, cons1Count = 0;
    while (true) {
        ClientMessage msg = consumers[0].getConsumer().receive(1000);
        if (msg == null) {
            break;
        }
        cons0Count++;
        msg.acknowledge();
        session0.commit();
    }
    while (true) {
        ClientMessage msg = consumers[1].getConsumer().receive(1000);
        if (msg == null) {
            break;
        }
        cons1Count++;
        msg.acknowledge();
        session1.commit();
    }
    Assert.assertEquals("cons0 = " + cons0Count + ", cons1 = " + cons1Count, NUMBER_OF_MESSAGES, cons0Count + cons1Count);
    session0.commit();
    session1.commit();
    stopServers(0, 1);
}
Also used : MessageFlowRecord(org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClusterConnectionBridge(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 57 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ReattachTest method testReattachAttemptsFailsToReconnect.

@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 3;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
    ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
    final int numMessages = 1000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        message.putIntProperty(new SimpleString("count"), i);
        message.getBodyBuffer().writeString("aardvarks");
        producer.send(message);
    }
    session.createConsumer(ReattachTest.ADDRESS);
    InVMConnector.failOnCreateConnection = true;
    RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    // Sleep for longer than max retries so should fail to reconnect
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(retryInterval * (reconnectAttempts + 1));
            } catch (InterruptedException ignore) {
            }
            InVMConnector.failOnCreateConnection = false;
        }
    };
    t.start();
    conn.fail(new ActiveMQNotConnectedException());
    try {
        session.start();
        Assert.fail("Should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
    sf.close();
    t.join();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 58 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ReattachTest method testOverflowCredits.

/*
    * Test failure on connection, but server is still up so should immediately reconnect
    */
@Test
public void testOverflowCredits() throws Exception {
    final long retryInterval = 500;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 1;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024).setProducerWindowSize(1000);
    final AtomicInteger count = new AtomicInteger(0);
    Interceptor intercept = new Interceptor() {

        @Override
        public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
            System.out.println("Intercept..." + packet.getClass().getName());
            if (packet instanceof SessionProducerCreditsMessage) {
                SessionProducerCreditsMessage credit = (SessionProducerCreditsMessage) packet;
                System.out.println("Credits: " + credit.getCredits());
                if (count.incrementAndGet() == 2) {
                    System.out.println("Failing");
                    connection.fail(new ActiveMQException(ActiveMQExceptionType.UNSUPPORTED_PACKET, "bye"));
                    return false;
                }
            }
            return true;
        }
    };
    locator.addIncomingInterceptor(intercept);
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
    ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
    final int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        message.putIntProperty(new SimpleString("count"), i);
        message.getBodyBuffer().writeBytes(new byte[5000]);
        producer.send(message);
    }
    session.close();
    sf.close();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) SessionProducerCreditsMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionProducerCreditsMessage) ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 59 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class BackupSyncDelay method intercept.

@Override
public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException {
    if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
        try {
            SharedNothingBackupActivation activation = (SharedNothingBackupActivation) backup.getActivation();
            ReplicationEndpoint repEnd = activation.getReplicationEndpoint();
            handler.addSubHandler(repEnd);
            Channel repChannel = repEnd.getChannel();
            repChannel.setHandler(handler);
            handler.setChannel(repChannel);
            live.getRemotingService().removeIncomingInterceptor(this);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}
Also used : ReplicationEndpoint(org.apache.activemq.artemis.core.replication.ReplicationEndpoint) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) SharedNothingBackupActivation(org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 60 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class TopologyClusterTestBase method testStopNodes.

@Test
public void testStopNodes() throws Throwable {
    startServers(0, 1, 2, 3, 4);
    String[] nodeIDs = getNodeIDs(0, 1, 2, 3, 4);
    ServerLocator locator = createHAServerLocator();
    waitForClusterConnections(0, 4);
    waitForClusterConnections(1, 4);
    waitForClusterConnections(2, 4);
    waitForClusterConnections(3, 4);
    waitForClusterConnections(4, 4);
    final List<String> nodes = Collections.synchronizedList(new ArrayList<String>());
    final CountDownLatch upLatch = new CountDownLatch(5);
    locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, new CountDownLatch(0)));
    ClientSessionFactory sf = createSessionFactory(locator);
    Assert.assertTrue("Was not notified that all servers are UP", upLatch.await(10, SECONDS));
    checkContains(new int[] { 0, 1, 2, 3, 4 }, nodeIDs, nodes);
    ClientSession session = sf.createSession();
    stopServers(0);
    Assert.assertFalse(servers[0].isStarted());
    session = checkSessionOrReconnect(session, locator);
    checkContains(new int[] { 1, 2, 3, 4 }, nodeIDs, nodes);
    stopServers(2);
    Assert.assertFalse(servers[2].isStarted());
    session = checkSessionOrReconnect(session, locator);
    checkContains(new int[] { 1, 3, 4 }, nodeIDs, nodes);
    stopServers(4);
    Assert.assertFalse(servers[4].isStarted());
    session = checkSessionOrReconnect(session, locator);
    checkContains(new int[] { 1, 3 }, nodeIDs, nodes);
    stopServers(3);
    Assert.assertFalse(servers[3].isStarted());
    session = checkSessionOrReconnect(session, locator);
    checkContains(new int[] { 1 }, nodeIDs, nodes);
    stopServers(1);
    Assert.assertFalse(servers[1].isStarted());
    try {
        session = checkSessionOrReconnect(session, locator);
        Assert.fail();
    } catch (ActiveMQException expected) {
        Assert.assertEquals(ActiveMQExceptionType.NOT_CONNECTED, expected.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) CountDownLatch(java.util.concurrent.CountDownLatch) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)140 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15