Search in sources :

Example 51 with ClientConsumer

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

the class InterruptedLargeMessageTest method testCloseConsumerDuringTransmission.

@Test
public void testCloseConsumerDuringTransmission() throws Exception {
    ActiveMQServer server = createServer(true, isNetty());
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    server.start();
    locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).addIncomingInterceptor(new LargeMessageTestInterceptorIgnoreLastPacket());
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
    producer.send(clientFile);
    session.commit();
    LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
    final AtomicInteger unexpectedErrors = new AtomicInteger(0);
    final AtomicInteger expectedErrors = new AtomicInteger(0);
    final ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                System.out.println("Receiving message");
                ClientMessage msg = cons.receive(5000);
                if (msg == null) {
                    System.err.println("Message not received");
                    unexpectedErrors.incrementAndGet();
                    return;
                }
                msg.checkCompletion();
            } catch (ActiveMQException e) {
                e.printStackTrace();
                expectedErrors.incrementAndGet();
            }
        }
    };
    t.start();
    LargeMessageTestInterceptorIgnoreLastPacket.awaitInterrupt();
    cons.close();
    t.join();
    Assert.assertEquals(0, unexpectedErrors.get());
    Assert.assertEquals(1, expectedErrors.get());
    session.close();
    server.stop();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 52 with ClientConsumer

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

the class InterruptedLargeMessageTest method testSendPreparedXA.

@Test
public void testSendPreparedXA() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, createDefaultConfig(isNetty()), 10000, 20000, new HashMap<String, AddressSettings>());
    server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    Xid xid1 = newXID();
    Xid xid2 = newXID();
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    session.start(xid1, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 1);
        producer.send(clientFile);
    }
    session.end(xid1, XAResource.TMSUCCESS);
    session.prepare(xid1);
    session.start(xid2, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 2);
        clientFile.putIntProperty("i", i);
        producer.send(clientFile);
    }
    session.end(xid2, XAResource.TMSUCCESS);
    session.prepare(xid2);
    session.close();
    sf.close();
    server.fail(false);
    server.start();
    for (int start = 0; start < 2; start++) {
        System.out.println("Start " + start);
        sf = createSessionFactory(locator);
        if (start == 0) {
            session = sf.createSession(true, false, false);
            session.commit(xid1, false);
            session.close();
        }
        session = sf.createSession(false, false, false);
        ClientConsumer cons1 = session.createConsumer(ADDRESS);
        session.start();
        for (int i = 0; i < 10; i++) {
            log.info("I = " + i);
            ClientMessage msg = cons1.receive(5000);
            Assert.assertNotNull(msg);
            Assert.assertEquals(1, msg.getIntProperty("txid").intValue());
            msg.acknowledge();
        }
        if (start == 1) {
            session.commit();
        } else {
            session.rollback();
        }
        session.close();
        sf.close();
        server.stop();
        server.start();
    }
    server.stop();
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 10);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    session.rollback(xid2);
    sf.close();
    server.stop();
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 53 with ClientConsumer

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

the class InterruptedLargeMessageTest method testSendNonPersistentQueue.

@Test
public void testSendNonPersistentQueue() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, false);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    for (int h = 0; h < 5; h++) {
        for (int i = 0; i < 10; i++) {
            ClientMessage clientMessage = cons.receive(5000);
            Assert.assertNotNull(clientMessage);
            for (int countByte = 0; countByte < LARGE_MESSAGE_SIZE; countByte++) {
                Assert.assertEquals(ActiveMQTestBase.getSamplebyte(countByte), clientMessage.getBodyBuffer().readByte());
            }
            clientMessage.acknowledge();
        }
        session.rollback();
    }
    server.fail(false);
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 54 with ClientConsumer

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

the class InterruptedLargeMessageTest method testRestartBeforeDelete.

@Test
public void testRestartBeforeDelete() throws Exception {
    class NoPostACKQueue extends QueueImpl {

        NoPostACKQueue(long id, SimpleString address, SimpleString name, Filter filter, SimpleString user, PageSubscription pageSubscription, boolean durable, boolean temporary, boolean autoCreated, ScheduledExecutorService scheduledExecutor, PostOffice postOffice, StorageManager storageManager, HierarchicalRepository<AddressSettings> addressSettingsRepository, ArtemisExecutor executor) {
            super(id, address, name, filter, pageSubscription, user, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, executor, null, null);
        }

        @Override
        public void postAcknowledge(final MessageReference ref) {
            System.out.println("Ignoring postACK on message " + ref);
        }

        @Override
        public void deliverScheduledMessages() {
        }
    }
    final class NoPostACKQueueFactory implements QueueFactory {

        final StorageManager storageManager;

        final PostOffice postOffice;

        final ScheduledExecutorService scheduledExecutor;

        final HierarchicalRepository<AddressSettings> addressSettingsRepository;

        final ExecutorFactory execFactory;

        NoPostACKQueueFactory(StorageManager storageManager, PostOffice postOffice, ScheduledExecutorService scheduledExecutor, HierarchicalRepository<AddressSettings> addressSettingsRepository, final ExecutorFactory execFactory) {
            this.storageManager = storageManager;
            this.postOffice = postOffice;
            this.scheduledExecutor = scheduledExecutor;
            this.addressSettingsRepository = addressSettingsRepository;
            this.execFactory = execFactory;
        }

        @Override
        public Queue createQueueWith(final QueueConfig config) {
            return new NoPostACKQueue(config.id(), config.address(), config.name(), config.filter(), config.user(), config.pageSubscription(), config.isDurable(), config.isTemporary(), config.isAutoCreated(), scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        @Deprecated
        @Override
        public Queue createQueue(long persistenceID, SimpleString address, SimpleString name, Filter filter, PageSubscription pageSubscription, SimpleString user, boolean durable, boolean temporary, boolean autoCreated) {
            return new NoPostACKQueue(persistenceID, address, name, filter, user, pageSubscription, durable, temporary, autoCreated, scheduledExecutor, postOffice, storageManager, addressSettingsRepository, execFactory.getExecutor());
        }

        /* (non-Javadoc)
          * @see org.apache.activemq.artemis.core.server.QueueFactory#setPostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)
          */
        @Override
        public void setPostOffice(PostOffice postOffice) {
        }
    }
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    QueueFactory original = server.getQueueFactory();
    ((ActiveMQServerImpl) server).replaceQueueFactory(new NoPostACKQueueFactory(server.getStorageManager(), server.getPostOffice(), server.getScheduledPool(), server.getAddressSettingsRepository(), server.getExecutorFactory()));
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = cons.receive(5000);
        Assert.assertNotNull(msg);
        msg.saveToOutputStream(new java.io.OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        });
        msg.acknowledge();
        session.commit();
    }
    ((ActiveMQServerImpl) server).replaceQueueFactory(original);
    server.fail(false);
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : HierarchicalRepository(org.apache.activemq.artemis.core.settings.HierarchicalRepository) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) PageSubscription(org.apache.activemq.artemis.core.paging.cursor.PageSubscription) IOException(java.io.IOException) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Filter(org.apache.activemq.artemis.core.filter.Filter) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 55 with ClientConsumer

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

the class LargeMessageCompressTest method testLargeMessageCompression3.

@Test
public void testLargeMessageCompression3() throws Exception {
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createTemporaryQueue(ADDRESS, ADDRESS);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);
    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);
    msg1.saveToOutputStream(output);
    msg1.acknowledge();
    output.close();
    session.commit();
    consumer.close();
    session.close();
    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
        byte b = (byte) input.read();
        assertEquals("position = " + i, getSamplebyte(i), b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) FileInputStream(java.io.FileInputStream) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) FileOutputStream(java.io.FileOutputStream) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) File(java.io.File) Test(org.junit.Test)

Aggregations

ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)720 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)642 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)624 Test (org.junit.Test)584 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)569 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)409 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)348 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)154 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)132 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)88 Configuration (org.apache.activemq.artemis.core.config.Configuration)81 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)79 CountDownLatch (java.util.concurrent.CountDownLatch)72 Queue (org.apache.activemq.artemis.core.server.Queue)63 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)62 Xid (javax.transaction.xa.Xid)55 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)52 HashMap (java.util.HashMap)48 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)46 ArrayList (java.util.ArrayList)44