Search in sources :

Example 1 with ClusterConnectionBridge

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge 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 2 with ClusterConnectionBridge

use of org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge in project activemq-artemis by apache.

the class ClusteredBridgeReconnectTest method testReconnectBridge.

@Test
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) {
            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();
    connection = servers[0].getClusterManager().getClusterConnections().toArray(new ClusterConnectionImpl[0])[0];
    Assert.assertEquals(1, connection.getRecords().size());
    Assert.assertNotNull(bridge.getSessionFactory());
    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)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 MessageFlowRecord (org.apache.activemq.artemis.core.server.cluster.MessageFlowRecord)2 ClusterConnectionBridge (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionBridge)2 ClusterConnectionImpl (org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)2 Test (org.junit.Test)2 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)1