Search in sources :

Example 1 with QueueFactory

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

use of org.apache.activemq.artemis.core.server.QueueFactory in project activemq-artemis by apache.

the class InterruptedLargeMessageTest method testConsumeAfterRestart.

@Test
public void testConsumeAfterRestart() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    QueueFactory original = server.getQueueFactory();
    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();
    sf.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    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 : 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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) IOException(java.io.IOException) 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) 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)

Aggregations

IOException (java.io.IOException)2 Message (org.apache.activemq.artemis.api.core.Message)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)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 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 SessionContinuationMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 QueueFactory (org.apache.activemq.artemis.core.server.QueueFactory)2 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)2 Test (org.junit.Test)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 Filter (org.apache.activemq.artemis.core.filter.Filter)1 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)1 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)1 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)1 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)1 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)1