Search in sources :

Example 21 with LogEntryStart

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart in project neo4j by neo4j.

the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.

@Test
void shouldAppendCommittedTransactions() throws Exception {
    // GIVEN
    when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
    long nextTxId = 15;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
    when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(nextTxId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
    TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, databaseHealth));
    // WHEN
    final byte[] additionalHeader = new byte[] { 1, 2, 5 };
    final long timeStarted = 12345;
    long latestCommittedTxWhenStarted = nextTxId - 5;
    long timeCommitted = timeStarted + 10;
    PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleTestCommand());
    transactionRepresentation.setHeader(additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1, ANONYMOUS);
    LogEntryStart start = new LogEntryStart(0L, latestCommittedTxWhenStarted, 0, null, LogPosition.UNSPECIFIED);
    LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L, BASE_TX_CHECKSUM);
    CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
    appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId(), NULL), logAppendEvent);
    // THEN
    LogEntryReader logEntryReader = logEntryReader();
    try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
        reader.next();
        TransactionRepresentation result = reader.get().getTransactionRepresentation();
        assertArrayEquals(additionalHeader, result.additionalHeader());
        assertEquals(timeStarted, result.getTimeStarted());
        assertEquals(timeCommitted, result.getTimeCommitted());
        assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
    }
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) TransactionId(org.neo4j.storageengine.api.TransactionId) DbmsLogEntryWriterFactory(org.neo4j.kernel.database.DbmsLogEntryWriterFactory) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) Test(org.junit.jupiter.api.Test)

Aggregations

LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)21 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)12 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)8 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)7 Test (org.junit.Test)5 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)5 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)5 Test (org.junit.jupiter.api.Test)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)4 Command (org.neo4j.kernel.impl.transaction.command.Command)4 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)4 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)4 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)4 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)3