Search in sources :

Example 6 with OnePhaseCommit

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

the class LegacyLogEntryReaderTest method shouldReadTheEntries.

@Test
public void shouldReadTheEntries() throws IOException {
    // given
    final LogEntry start = new LogEntryStart(0, 1, 2, 3, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    NodeRecord record = new NodeRecord(42);
    final LogEntry command = new LogEntryCommand(new Command.NodeCommand(record, record));
    final LogEntry commit = new OnePhaseCommit(42, 43);
    final LogEntryReader<ReadableLogChannel> logEntryReader = mock(LogEntryReader.class);
    when(logEntryReader.readLogEntry(any(ReadableLogChannel.class))).thenReturn(new IdentifiableLogEntry(start, 1), new IdentifiableLogEntry(command, 1), new IdentifiableLogEntry(commit, 1), null);
    final LegacyLogEntryReader reader = new LegacyLogEntryReader(fs, from -> logEntryReader);
    // when
    final IOCursor<LogEntry> cursor = reader.openReadableChannel(input).other();
    // then
    assertTrue(cursor.next());
    assertEquals(start, cursor.get());
    assertTrue(cursor.next());
    assertEquals(command, cursor.get());
    assertTrue(cursor.next());
    assertEquals(commit, cursor.get());
    assertFalse(cursor.next());
    cursor.close();
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) Test(org.junit.Test)

Example 7 with OnePhaseCommit

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

the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInSeveralCommitsToTheFile.

@Test
public void shouldWriteAllTheEntryInSeveralCommitsToTheFile() throws IOException {
    // given
    final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
    final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
    final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
    final LogEntryStart start1 = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    final LogEntryCommand command1 = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
    final LogEntryCommit commit1 = new OnePhaseCommit(42L, 43L);
    final LogEntryStart start2 = new LogEntryStart(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    final LogEntryCommand command2 = new LogEntryCommand(new Command.RelationshipCommand(relRecord, relRecord));
    final LogEntryCommit commit2 = new OnePhaseCommit(84L, 85L);
    // when
    IOCursor<LogEntry> cursor = mockCursor(start1, command1, commit1, start2, command2, commit2);
    writer.writeAllLogEntries(channel, cursor);
    // then
    verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
    final TransactionRepresentation expected1 = new PhysicalTransactionRepresentation(Arrays.asList(command1.getXaCommand()));
    verify(logEntryWriter, times(1)).serialize(eq(expected1));
    verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
    verify(logEntryWriter, times(1)).writeStartEntry(9, 8, 7L, 6L, EMPTY_ADDITIONAL_ARRAY);
    final TransactionRepresentation expected2 = new PhysicalTransactionRepresentation(Arrays.asList(command2.getXaCommand()));
    verify(logEntryWriter, times(1)).serialize(eq(expected2));
    verify(logEntryWriter, times(1)).writeCommitEntry(84L, 85L);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Aggregations

LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)7 OnePhaseCommit (org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit)7 Test (org.junit.Test)6 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)4 Command (org.neo4j.kernel.impl.transaction.command.Command)4 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)4 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)4 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)3 PhysicalTransactionRepresentation (org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)3 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)3 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)3 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)2 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)2 File (java.io.File)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 InOrder (org.mockito.InOrder)1