Search in sources :

Example 21 with MessageEnqueueRecord

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

the class LocalTransactionTest 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 TransactionLogResource queue = createQueue(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() {
                return hasRecord ? mock(MessageEnqueueRecord.class) : 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) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 22 with MessageEnqueueRecord

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

the class JDBCMessageStoreTest method enqueueMessages.

private List<MessageEnqueueRecord> enqueueMessages(final MessageStore store, final TransactionLogResource resource, final int numberOfMessages) {
    final Transaction transaction = store.newTransaction();
    final String name = resource.getName();
    final List<MessageEnqueueRecord> records = LongStream.rangeClosed(1, numberOfMessages).boxed().map(i -> {
        final InternalMessage m = addTestMessage(store, name, i + "");
        return transaction.enqueueMessage(resource, m);
    }).collect(Collectors.toList());
    transaction.commitTran();
    return records;
}
Also used : Connection(java.sql.Connection) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) MessageStore(org.apache.qpid.server.store.MessageStore) SQLException(java.sql.SQLException) After(org.junit.After) MessageStoreTestCase(org.apache.qpid.server.store.MessageStoreTestCase) StoredMessage(org.apache.qpid.server.store.StoredMessage) Before(org.junit.Before) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) LongStream(java.util.stream.LongStream) Transaction(org.apache.qpid.server.store.Transaction) IN_CLAUSE_MAX_SIZE(org.apache.qpid.server.store.jdbc.AbstractJDBCMessageStore.IN_CLAUSE_MAX_SIZE) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TestJdbcUtils.getTableNames(org.apache.qpid.server.store.jdbc.TestJdbcUtils.getTableNames) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) List(java.util.List) TestJdbcUtils.assertTablesExistence(org.apache.qpid.server.store.jdbc.TestJdbcUtils.assertTablesExistence) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) VirtualHost(org.apache.qpid.server.model.VirtualHost) MessageDurability(org.apache.qpid.server.store.MessageDurability) JDBCVirtualHost(org.apache.qpid.server.virtualhost.jdbc.JDBCVirtualHost) Mockito.any(org.mockito.Mockito.any) Collections(java.util.Collections) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 23 with MessageEnqueueRecord

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

the class JDBCMessageStoreTest method testEnqueueTransactionCommitAsync.

@Test
public void testEnqueueTransactionCommitAsync() throws Exception {
    final String queueName = getTestName();
    final UUID transactionalLogId = UUID.randomUUID();
    final MessageStore store = getStore();
    final TransactionLogResource transactionalLog = mockTransactionLogResource(transactionalLogId, queueName);
    final InternalMessage message = addTestMessage(store, queueName, "test");
    final Transaction transaction = store.newTransaction();
    final MessageEnqueueRecord record = transaction.enqueueMessage(transactionalLog, message);
    assertNotNull("Message enqueue record should not be null", record);
    assertEquals("Unexpected queue id", transactionalLogId, record.getQueueId());
    assertEquals("Unexpected message number", message.getMessageNumber(), record.getMessageNumber());
    final ListenableFuture<Void> future = transaction.commitTranAsync(null);
    future.get(1000, TimeUnit.MILLISECONDS);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) Test(org.junit.Test)

Example 24 with MessageEnqueueRecord

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

the class JDBCMessageStoreTest method testDequeueTransactionCommitAsync.

@Test
public void testDequeueTransactionCommitAsync() throws Exception {
    final String queueName = getTestName();
    final UUID transactionalLogId = UUID.randomUUID();
    final MessageStore store = getStore();
    final TransactionLogResource transactionalLog = mockTransactionLogResource(transactionalLogId, queueName);
    final InternalMessage message = addTestMessage(store, queueName, "test2");
    final Transaction enqueueTransaction = store.newTransaction();
    MessageEnqueueRecord record = enqueueTransaction.enqueueMessage(transactionalLog, message);
    enqueueTransaction.commitTran();
    final Transaction dequeueTransaction = store.newTransaction();
    dequeueTransaction.dequeueMessage(record);
    final ListenableFuture<Void> future = dequeueTransaction.commitTranAsync(null);
    future.get(1000, TimeUnit.MILLISECONDS);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Transaction(org.apache.qpid.server.store.Transaction) UUID(java.util.UUID) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) Test(org.junit.Test)

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