Search in sources :

Example 21 with Transaction

use of org.apache.qpid.server.store.Transaction 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 22 with Transaction

use of org.apache.qpid.server.store.Transaction 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)

Aggregations

Transaction (org.apache.qpid.server.store.Transaction)22 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)13 Test (org.junit.Test)9 MessageStore (org.apache.qpid.server.store.MessageStore)8 UUID (java.util.UUID)6 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)4 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)4 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)4 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)4 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)3 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)3 StoredMessage (org.apache.qpid.server.store.StoredMessage)3 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)2 MessageInstance (org.apache.qpid.server.message.MessageInstance)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 BaseQueue (org.apache.qpid.server.queue.BaseQueue)2 MessageDurability (org.apache.qpid.server.store.MessageDurability)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2