Search in sources :

Example 1 with FailoverEventListener

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

the class RaceOnSyncLargeMessageOverReplication2Test method testSendLargeMessage.

@Test
@BMRules(rules = { @BMRule(name = "InterruptSending", targetClass = "org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext", targetMethod = "sendLargeMessageChunk", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplication2Test.messageChunkSent();"), @BMRule(name = "InterruptSync", targetClass = "org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager", targetMethod = "sendLargeMessageFiles", targetLocation = "ENTRY", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplication2Test.syncLargeMessage();") })
public void testSendLargeMessage() throws Exception {
    final CountDownLatch failedOver = new CountDownLatch(1);
    connection.setFailoverListener(new FailoverEventListener() {

        @Override
        public void failoverEvent(FailoverEventType eventType) {
            failedOver.countDown();
        }
    });
    Thread t;
    {
        final MapMessage message = createLargeMessage();
        t = new Thread() {

            @Override
            public void run() {
                try {
                    producer.send(message);
                    session.commit();
                } catch (JMSException expected) {
                    expected.printStackTrace();
                }
            }
        };
    }
    t.start();
    // I'm trying to simulate the following race here:
    // The message is syncing while the client is already sending the body of the message
    Assert.assertTrue(flagChunkEntered.await(10, TimeUnit.SECONDS));
    startBackup();
    Assert.assertTrue(flagSyncEntered.await(10, TimeUnit.SECONDS));
    flagChunkWait.countDown();
    t.join(5000);
    System.out.println("Thread joined");
    Assert.assertFalse(t.isAlive());
    flagSyncWait.countDown();
    Assert.assertTrue(((SharedNothingBackupActivation) backupServer.getActivation()).waitForBackupSync(10, TimeUnit.SECONDS));
    waitForRemoteBackup(connection.getSessionFactory(), 30);
    liveServer.fail(true);
    Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
    {
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        MapMessage message = (MapMessage) consumer.receive(5000);
        Assert.assertNotNull(message);
        for (int i = 0; i < 10; i++) {
            Assert.assertEquals(1024 * 1024, message.getBytes("test" + i).length);
        }
        session.commit();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MapMessage(javax.jms.MapMessage) FailoverEventType(org.apache.activemq.artemis.api.core.client.FailoverEventType) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) FailoverEventListener(org.apache.activemq.artemis.api.core.client.FailoverEventListener) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 2 with FailoverEventListener

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

the class RaceOnSyncLargeMessageOverReplicationTest method testSendLargeMessage.

/*
  * simple test to induce a potential race condition where the server's acceptors are active, but the server's
  * state != STARTED
  */
@Test
@BMRules(rules = { @BMRule(name = "InterruptSync", targetClass = "org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager", targetMethod = "createLargeMessage(long,org.apache.activemq.artemis.core.message.impl.MessageInternal)", targetLocation = "EXIT", action = "org.apache.activemq.artemis.tests.extras.byteman.RaceOnSyncLargeMessageOverReplicationTest.syncLargeMessage();") })
public void testSendLargeMessage() throws Exception {
    final CountDownLatch failedOver = new CountDownLatch(1);
    connection.setFailoverListener(new FailoverEventListener() {

        @Override
        public void failoverEvent(FailoverEventType eventType) {
            failedOver.countDown();
        }
    });
    Thread t;
    {
        final MapMessage message = createLargeMessage();
        t = new Thread() {

            @Override
            public void run() {
                try {
                    producer.send(message);
                    session.commit();
                } catch (JMSException expected) {
                    expected.printStackTrace();
                }
            }
        };
    }
    t.start();
    // I'm trying to simulate the following race here:
    // The message is syncing while the client is already sending the body of the message
    Assert.assertTrue(flagArrived.await(10, TimeUnit.SECONDS));
    startBackup();
    waitForRemoteBackup(connection.getSessionFactory(), 30);
    flagWait.countDown();
    t.join(5000);
    System.out.println("Thread joined");
    Assert.assertFalse(t.isAlive());
    liveServer.fail(true);
    Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
    {
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        MapMessage message = (MapMessage) consumer.receive(5000);
        Assert.assertNotNull(message);
        for (int i = 0; i < 10; i++) {
            Assert.assertEquals(1024 * 1024, message.getBytes("test" + i).length);
        }
        session.commit();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MapMessage(javax.jms.MapMessage) FailoverEventType(org.apache.activemq.artemis.api.core.client.FailoverEventType) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) FailoverEventListener(org.apache.activemq.artemis.api.core.client.FailoverEventListener) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 3 with FailoverEventListener

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

the class ReconnectTest method internalMetadataAfterRetry.

public void internalMetadataAfterRetry(final boolean isNetty) throws Exception {
    final int pingPeriod = 1000;
    ActiveMQServer server = createServer(false, isNetty);
    server.start();
    ClientSessionInternal session = null;
    try {
        for (int i = 0; i < 100; i++) {
            ServerLocator locator = createFactory(isNetty);
            locator.setClientFailureCheckPeriod(pingPeriod);
            locator.setRetryInterval(1);
            locator.setRetryIntervalMultiplier(1d);
            locator.setReconnectAttempts(-1);
            locator.setConfirmationWindowSize(-1);
            ClientSessionFactory factory = createSessionFactory(locator);
            session = (ClientSessionInternal) factory.createSession();
            session.addMetaData("meta1", "meta1");
            ServerSession[] sessions = countMetadata(server, "meta1", 1);
            Assert.assertEquals(1, sessions.length);
            final AtomicInteger count = new AtomicInteger(0);
            final CountDownLatch latch = new CountDownLatch(1);
            session.addFailoverListener(new FailoverEventListener() {

                @Override
                public void failoverEvent(FailoverEventType eventType) {
                    if (eventType == FailoverEventType.FAILOVER_COMPLETED) {
                        latch.countDown();
                    }
                }
            });
            sessions[0].getRemotingConnection().fail(new ActiveMQException("failure!"));
            Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
            sessions = countMetadata(server, "meta1", 1);
            Assert.assertEquals(1, sessions.length);
            locator.close();
        }
    } finally {
        try {
            session.close();
        } catch (Throwable e) {
        }
        server.stop();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FailoverEventType(org.apache.activemq.artemis.api.core.client.FailoverEventType) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) FailoverEventListener(org.apache.activemq.artemis.api.core.client.FailoverEventListener) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 4 with FailoverEventListener

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

the class ReplicationWithDivertTest method testSendLargeMessage.

@Test
public void testSendLargeMessage() throws Exception {
    final CountDownLatch failedOver = new CountDownLatch(1);
    connection.setFailoverListener(new FailoverEventListener() {

        @Override
        public void failoverEvent(FailoverEventType eventType) {
            failedOver.countDown();
        }
    });
    Thread t;
    final int numberOfMessage = 5;
    {
        final MapMessage message = createLargeMessage();
        t = new Thread() {

            @Override
            public void run() {
                try {
                    for (int i = 0; i < numberOfMessage; i++) {
                        producer.send(message);
                        session.commit();
                    }
                } catch (JMSException expected) {
                    expected.printStackTrace();
                }
            }
        };
    }
    t.start();
    t.join(10000);
    {
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        for (int msgi = 0; msgi < numberOfMessage; msgi++) {
            MapMessage message = (MapMessage) consumer.receive(5000);
            Assert.assertNotNull(message);
            for (int i = 0; i < 10; i++) {
                Assert.assertEquals(200 * 1024, message.getBytes("test" + i).length);
            }
            session.commit();
        }
        consumer.close();
    }
    Assert.assertFalse(t.isAlive());
    liveServer.fail(true);
    Assert.assertTrue(failedOver.await(10, TimeUnit.SECONDS));
    {
        MessageConsumer consumer = session.createConsumer(targetQueue);
        connection.start();
        for (int msgi = 0; msgi < numberOfMessage; msgi++) {
            MapMessage message = (MapMessage) consumer.receive(5000);
            Assert.assertNotNull(message);
            for (int i = 0; i < 10; i++) {
                Assert.assertEquals(200 * 1024, message.getBytes("test" + i).length);
            }
            session.commit();
        }
        consumer.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MapMessage(javax.jms.MapMessage) FailoverEventType(org.apache.activemq.artemis.api.core.client.FailoverEventType) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) FailoverEventListener(org.apache.activemq.artemis.api.core.client.FailoverEventListener) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)4 FailoverEventListener (org.apache.activemq.artemis.api.core.client.FailoverEventListener)4 FailoverEventType (org.apache.activemq.artemis.api.core.client.FailoverEventType)4 JMSException (javax.jms.JMSException)3 MapMessage (javax.jms.MapMessage)3 MessageConsumer (javax.jms.MessageConsumer)3 Test (org.junit.Test)3 BMRules (org.jboss.byteman.contrib.bmunit.BMRules)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)1