use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method shouldVisitLogFile.
@Test
void shouldVisitLogFile() throws Exception {
// GIVEN
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var transactionLogWriter = logFile.getTransactionLogWriter();
var writer = transactionLogWriter.getChannel();
LogPosition position = transactionLogWriter.getCurrentPosition();
for (int i = 0; i < 5; i++) {
writer.put((byte) i);
}
logFile.flush();
// WHEN/THEN
final AtomicBoolean called = new AtomicBoolean();
logFile.accept(channel -> {
for (int i = 0; i < 5; i++) {
assertEquals((byte) i, channel.get());
}
called.set(true);
return true;
}, position);
assertTrue(called.get());
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method shouldForceLogChannel.
@Test
void shouldForceLogChannel() throws Throwable {
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var capturingChannel = wrappingFileSystem.getCapturingChannel();
var flushesBefore = capturingChannel.getFlushCounter().get();
var writesBefore = capturingChannel.getWriteAllCounter().get();
logFile.forceAfterAppend(LogAppendEvent.NULL);
assertEquals(1, capturingChannel.getFlushCounter().get() - flushesBefore);
assertEquals(1, capturingChannel.getWriteAllCounter().get() - writesBefore);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method shouldWaitForOngoingForceToCompleteBeforeForcingAgain.
@Test
void shouldWaitForOngoingForceToCompleteBeforeForcingAgain() throws Throwable {
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var capturingChannel = wrappingFileSystem.getCapturingChannel();
ReentrantLock writeAllLock = capturingChannel.getWriteAllLock();
var flushesBefore = capturingChannel.getFlushCounter().get();
var writesBefore = capturingChannel.getWriteAllCounter().get();
writeAllLock.lock();
int executors = 10;
var executorService = Executors.newFixedThreadPool(executors);
try {
var future = executorService.submit(() -> logFile.forceAfterAppend(LogAppendEvent.NULL));
while (!writeAllLock.hasQueuedThreads()) {
parkNanos(100);
}
writeAllLock.unlock();
var future2 = executorService.submit(() -> logFile.forceAfterAppend(LogAppendEvent.NULL));
Futures.getAll(List.of(future, future2));
} finally {
if (writeAllLock.isLocked()) {
writeAllLock.unlock();
}
executorService.shutdownNow();
}
assertThat(capturingChannel.getWriteAllCounter().get() - writesBefore).isEqualTo(2);
assertThat(capturingChannel.getFlushCounter().get() - flushesBefore).isEqualTo(2);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method closeChannelThrowExceptionOnAttemptToAppendTransactionLogRecords.
@Test
void closeChannelThrowExceptionOnAttemptToAppendTransactionLogRecords() throws IOException {
LogFiles logFiles = buildLogFiles();
life.start();
life.add(logFiles);
LogFile logFile = logFiles.getLogFile();
var channel = logFile.getTransactionLogWriter().getChannel();
life.shutdown();
assertThrows(Throwable.class, () -> channel.put((byte) 7));
assertThrows(Throwable.class, () -> channel.putInt(7));
assertThrows(Throwable.class, () -> channel.putLong(7));
assertThrows(Throwable.class, () -> channel.putDouble(7));
assertThrows(Throwable.class, () -> channel.putFloat(7));
assertThrows(Throwable.class, () -> channel.putShort((short) 7));
assertThrows(Throwable.class, () -> channel.put(new byte[] { 1, 2, 3 }, 3));
assertThrows(IllegalStateException.class, logFile::flush);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class TransactionLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.
@Test
void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
// GIVEN
LogFiles logFiles = buildLogFiles();
// WHEN
life.start();
life.add(logFiles);
life.shutdown();
// THEN
Path file = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseLayout.getTransactionLogsDirectory(), fileSystem).withLogEntryReader(logEntryReader()).build().getLogFile().getLogFileForVersion(1L);
LogHeader header = readLogHeader(fileSystem, file, INSTANCE);
assertEquals(1L, header.getLogVersion());
assertEquals(2L, header.getLastCommittedTxId());
}
Aggregations