Search in sources :

Example 11 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AutoCommitTransactionTest method createTestQueueEntries.

private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
    Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
    assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
    for (int i = 0; i < queueDurableFlags.length; i++) {
        final BaseQueue queue = createTestAMQQueue(queueDurableFlags[i]);
        final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
        final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
        queueEntries.add(new MockMessageInstance() {

            @Override
            public ServerMessage getMessage() {
                return message;
            }

            @Override
            public TransactionLogResource getOwningResource() {
                return queue;
            }

            @Override
            public MessageEnqueueRecord getEnqueueRecord() {
                if (hasRecord) {
                    return mock(MessageEnqueueRecord.class);
                } else {
                    return null;
                }
            }
        });
    }
    return queueEntries;
}
Also used : MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) MessageInstance(org.apache.qpid.server.message.MessageInstance) MockMessageInstance(org.apache.qpid.server.queue.MockMessageInstance) ArrayList(java.util.ArrayList) BaseQueue(org.apache.qpid.server.queue.BaseQueue) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 12 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class JDBCMessageStoreTest method testRemoveMessagesWhenNumberOfMessagesEqualsInClauseMaxSize.

@Test
public void testRemoveMessagesWhenNumberOfMessagesEqualsInClauseMaxSize() {
    final String queueName = getTestName();
    final UUID transactionalLogId = UUID.randomUUID();
    final TransactionLogResource resource = mockTransactionLogResource(transactionalLogId, queueName);
    final int numberOfMessages = 10;
    final GenericJDBCMessageStore store = (GenericJDBCMessageStore) getStore();
    reOpenStoreWithInClauseMaxSize(store, numberOfMessages);
    final List<MessageEnqueueRecord> records = enqueueMessages(store, resource, numberOfMessages);
    assertEquals(numberOfMessages, records.size());
    assertRecords(store, resource, records);
    store.removeMessages(records.stream().map(MessageEnqueueRecord::getMessageNumber).collect(Collectors.toList()));
    final List<StoredMessage> stored = new ArrayList<>();
    store.newMessageStoreReader().visitMessages(m -> {
        stored.add(m);
        return true;
    });
    assertTrue(stored.isEmpty());
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ArrayList(java.util.ArrayList) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) Test(org.junit.Test)

Example 13 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class PriorityQueueImpl method reenqueueEntryWithPriority.

private long reenqueueEntryWithPriority(final QueueEntry entry, final ServerTransaction txn, final byte newPriority) {
    txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {

        @Override
        public void postCommit() {
            entry.delete();
        }

        @Override
        public void onRollback() {
            entry.release();
        }
    });
    final ServerMessage newMessage = createMessageWithPriority(entry.getMessage(), newPriority);
    txn.enqueue(this, newMessage, new ServerTransaction.EnqueueAction() {

        @Override
        public void postCommit(MessageEnqueueRecord... records) {
            PriorityQueueImpl.this.enqueue(newMessage, null, records[0]);
        }

        @Override
        public void onRollback() {
        // noop
        }
    });
    return newMessage.getMessageNumber();
}
Also used : ServerMessage(org.apache.qpid.server.message.ServerMessage) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 14 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AbstractVirtualHost method executeTransaction.

@Override
public void executeTransaction(TransactionalOperation op) {
    final MessageStore store = getMessageStore();
    final LocalTransaction txn = new LocalTransaction(store);
    op.withinTransaction(new Transaction() {

        @Override
        public void dequeue(final QueueEntry messageInstance) {
            final ServerTransaction.Action deleteAction = new ServerTransaction.Action() {

                @Override
                public void postCommit() {
                    messageInstance.delete();
                }

                @Override
                public void onRollback() {
                }
            };
            boolean acquired = messageInstance.acquireOrSteal(new Runnable() {

                @Override
                public void run() {
                    ServerTransaction txn = new AutoCommitTransaction(store);
                    txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
                }
            });
            if (acquired) {
                txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
            }
        }

        @Override
        public void copy(QueueEntry entry, final Queue<?> queue) {
            final ServerMessage message = entry.getMessage();
            txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {

                @Override
                public void postCommit(MessageEnqueueRecord... records) {
                    queue.enqueue(message, null, records[0]);
                }

                @Override
                public void onRollback() {
                }
            });
        }

        @Override
        public void move(final QueueEntry entry, final Queue<?> queue) {
            final ServerMessage message = entry.getMessage();
            if (entry.acquire()) {
                txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {

                    @Override
                    public void postCommit(MessageEnqueueRecord... records) {
                        queue.enqueue(message, null, records[0]);
                    }

                    @Override
                    public void onRollback() {
                        entry.release();
                    }
                });
                txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {

                    @Override
                    public void postCommit() {
                        entry.delete();
                    }

                    @Override
                    public void onRollback() {
                    }
                });
            }
        }
    });
    txn.commit();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) PrivilegedAction(java.security.PrivilegedAction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) QueueEntry(org.apache.qpid.server.queue.QueueEntry) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 15 with MessageEnqueueRecord

use of org.apache.qpid.server.store.MessageEnqueueRecord in project qpid-broker-j by apache.

the class AbstractQueueTestBase method deleteEntry.

private void deleteEntry(final long messageNumber, final MessageEnqueueRecord record) throws InterruptedException {
    final CountDownLatch messageDeleteDetector = new CountDownLatch(1);
    final ServerMessage message = createMessage(messageNumber, 2, 3);
    final MessageReference reference = message.newReference();
    doAnswer((Answer<Void>) invocationOnMock -> {
        messageDeleteDetector.countDown();
        return null;
    }).when(reference).release();
    _queue.enqueue(message, null, record);
    _queue.visit(entry -> {
        _queue.deleteEntry(entry);
        return false;
    });
    assertTrue("Message reference is not released withing given timeout interval", messageDeleteDetector.await(2000L, TimeUnit.MILLISECONDS));
}
Also used : MessageReference(org.apache.qpid.server.message.MessageReference) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) LoggerFactory(org.slf4j.LoggerFactory) ArgumentMatchers.contains(org.mockito.ArgumentMatchers.contains) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) ExchangeDefaults(org.apache.qpid.server.exchange.ExchangeDefaults) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) After(org.junit.After) Assert.fail(org.junit.Assert.fail) DirectExchange(org.apache.qpid.server.exchange.DirectExchange) EnumSet(java.util.EnumSet) QueueNotificationListener(org.apache.qpid.server.model.QueueNotificationListener) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) Binding(org.apache.qpid.server.model.Binding) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) RoutingResult(org.apache.qpid.server.message.RoutingResult) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) MessageSource(org.apache.qpid.server.message.MessageSource) BrokerTestHelper(org.apache.qpid.server.model.BrokerTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) TestConsumerTarget(org.apache.qpid.server.consumer.TestConsumerTarget) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Queue(org.apache.qpid.server.model.Queue) OverflowPolicy(org.apache.qpid.server.model.OverflowPolicy) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) HashMap(java.util.HashMap) StateChangeListener(org.apache.qpid.server.util.StateChangeListener) ServerMessage(org.apache.qpid.server.message.ServerMessage) QueueEntryFilter(org.apache.qpid.server.queue.AbstractQueue.QueueEntryFilter) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) DirectExchangeImpl(org.apache.qpid.server.exchange.DirectExchangeImpl) MessageInstance(org.apache.qpid.server.message.MessageInstance) StoredMessage(org.apache.qpid.server.store.StoredMessage) Before(org.junit.Before) Logger(org.slf4j.Logger) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Action(org.apache.qpid.server.util.Action) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Exchange(org.apache.qpid.server.model.Exchange) Assert.assertNotNull(org.junit.Assert.assertNotNull) UnitTestBase(org.apache.qpid.test.utils.UnitTestBase) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ServerMessage(org.apache.qpid.server.message.ServerMessage) CountDownLatch(java.util.concurrent.CountDownLatch) MessageReference(org.apache.qpid.server.message.MessageReference)

Aggregations

MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)24 Transaction (org.apache.qpid.server.store.Transaction)11 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 MessageInstance (org.apache.qpid.server.message.MessageInstance)6 UUID (java.util.UUID)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)4 BaseQueue (org.apache.qpid.server.queue.BaseQueue)4 MessageStore (org.apache.qpid.server.store.MessageStore)4 StoredMessage (org.apache.qpid.server.store.StoredMessage)4 Collections (java.util.Collections)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)2 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2