use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldReadOlderLogs.
@Test
public void shouldReadOlderLogs() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
// WHEN
life.start();
try {
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
writer.getCurrentPosition(positionMarker);
LogPosition position1 = positionMarker.newPosition();
int intValue = 45;
long longValue = 4854587;
byte[] someBytes = someBytes(40);
writer.putInt(intValue);
writer.putLong(longValue);
writer.put(someBytes, someBytes.length);
writer.prepareForFlush().flush();
writer.getCurrentPosition(positionMarker);
LogPosition position2 = positionMarker.newPosition();
long longValue2 = 123456789L;
writer.putLong(longValue2);
writer.put(someBytes, someBytes.length);
writer.prepareForFlush().flush();
// THEN
try (ReadableClosableChannel reader = logFile.getReader(position1)) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
try (ReadableClosableChannel reader = logFile.getReader(position2)) {
assertEquals(longValue2, reader.getLong());
assertArrayEquals(someBytes, readBytes(reader, 40));
}
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldVisitLogFile.
@Test
public void shouldVisitLogFile() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 50, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
life.start();
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker mark = new LogPositionMarker();
writer.getCurrentPosition(mark);
for (int i = 0; i < 5; i++) {
writer.put((byte) i);
}
writer.prepareForFlush();
// WHEN/THEN
final AtomicBoolean called = new AtomicBoolean();
logFile.accept((position, channel) -> {
for (int i = 0; i < 5; i++) {
assertEquals((byte) i, channel.get());
}
called.set(true);
return true;
}, mark.newPosition());
assertTrue(called.get());
life.shutdown();
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class LatestCheckPointFinderTest method logFile.
private LogCreator logFile(Entry... entries) {
return (logVersion, positions) -> {
try {
AtomicLong lastTxId = new AtomicLong();
Supplier<Long> lastTxIdSupplier = () -> lastTxId.get();
LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository(logVersion);
LifeSupport life = new LifeSupport();
life.start();
PhysicalLogFile logFile = life.add(new PhysicalLogFile(fsRule.get(), logFiles, mebiBytes(1), lastTxIdSupplier, logVersionRepository, NO_MONITOR, new LogHeaderCache(10)));
try {
FlushablePositionAwareChannel writeChannel = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
LogEntryWriter writer = new LogEntryWriter(writeChannel);
for (Entry entry : entries) {
LogPosition currentPosition = writeChannel.getCurrentPosition(positionMarker).newPosition();
positions.put(entry, currentPosition);
if (entry instanceof StartEntry) {
writer.writeStartEntry(0, 0, 0, 0, new byte[0]);
} else if (entry instanceof CommitEntry) {
CommitEntry commitEntry = (CommitEntry) entry;
writer.writeCommitEntry(commitEntry.txId, 0);
lastTxId.set(commitEntry.txId);
} else if (entry instanceof CheckPointEntry) {
CheckPointEntry checkPointEntry = (CheckPointEntry) entry;
Entry target = checkPointEntry.withPositionOfEntry;
LogPosition logPosition = target != null ? positions.get(target) : currentPosition;
assert logPosition != null : "No registered log position for " + target;
writer.writeCheckPointEntry(logPosition);
} else if (entry instanceof PositionEntry) {
// Don't write anything, this entry is just for registering a position so that
// another CheckPointEntry can refer to it
} else {
throw new IllegalArgumentException("Unknown entry " + entry);
}
}
} finally {
life.shutdown();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class LabelScanStoreTest method start.
private void start(List<NodeLabelUpdate> existingData, boolean usePersistentStore, boolean readOnly) {
life = new LifeSupport();
monitor = new TrackingMonitor();
store = createLabelScanStore(fileSystemRule.get(), dir, existingData, usePersistentStore, readOnly, monitor);
life.add(store);
life.start();
assertTrue(monitor.initCalled);
}
use of org.neo4j.kernel.lifecycle.LifeSupport in project neo4j by neo4j.
the class KernelTransactionsTest method newKernelTransactions.
private static KernelTransactions newKernelTransactions(Locks locks, StorageEngine storageEngine, TransactionCommitProcess commitProcess, boolean testKernelTransactions) throws Throwable {
LifeSupport life = new LifeSupport();
life.start();
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(0, 0, 0));
Tracers tracers = new Tracers("null", NullLog.getInstance(), new Monitors(), mock(JobScheduler.class));
StatementLocksFactory statementLocksFactory = new SimpleStatementLocksFactory(locks);
StatementOperationContainer statementOperationsContianer = new StatementOperationContainer(null, null);
KernelTransactions transactions;
if (testKernelTransactions) {
transactions = createTestTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
} else {
transactions = createTransactions(storageEngine, commitProcess, transactionIdStore, tracers, statementLocksFactory, statementOperationsContianer, clock, availabilityGuard);
}
transactions.start();
return transactions;
}
Aggregations