use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class ReaderLogVersionBridgeTest method shouldReturnOldChannelWhenThereIsNoNextChannel.
@Test
void shouldReturnOldChannelWhenThereIsNoNextChannel() throws IOException {
// given
final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge(logFiles.getLogFile());
when(channel.getVersion()).thenReturn(version);
when(fs.read(any(Path.class))).thenThrow(new NoSuchFileException("mock"));
// when
final LogVersionedStoreChannel result = bridge.next(channel, false);
// then
assertEquals(channel, result);
verify(channel, never()).close();
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class CorruptedLogsTruncator method isRecoveredLogCorrupted.
private boolean isRecoveredLogCorrupted(long recoveredTransactionLogVersion, long recoveredTransactionOffset) throws IOException {
try {
LogFile logFile = logFiles.getLogFile();
if (Files.size(logFile.getLogFileForVersion(recoveredTransactionLogVersion)) > recoveredTransactionOffset) {
try (PhysicalLogVersionedStoreChannel channel = logFile.openForVersion(recoveredTransactionLogVersion);
var scopedBuffer = new NativeScopedBuffer(safeCastLongToInt(kibiBytes(64)), memoryTracker)) {
channel.position(recoveredTransactionOffset);
ByteBuffer byteBuffer = scopedBuffer.getBuffer();
while (channel.read(byteBuffer) >= 0) {
byteBuffer.flip();
while (byteBuffer.hasRemaining()) {
if (byteBuffer.get() != 0) {
return true;
}
}
byteBuffer.clear();
}
}
}
return false;
} catch (NoSuchFileException ignored) {
return false;
}
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class LoadCommandTest method shouldGiveAClearMessageIfTheArchiveDoesntExist.
@Test
void shouldGiveAClearMessageIfTheArchiveDoesntExist() throws IOException, IncorrectFormat {
doThrow(new NoSuchFileException(archive.toString())).when(loader).load(any(), any());
CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo", archive));
assertEquals("Archive does not exist: " + archive, commandFailed.getMessage());
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationFailingWithFileNotFoundException.
@Test
void shouldRequestIndexPopulationFailingWithFileNotFoundException() {
// Given
long faultyIndexId = 1;
NoSuchFileException error = new NoSuchFileException("/some/path/somewhere");
LuceneIndexProvider provider = newFaultyIndexProvider(faultyIndexId, error);
// When
IndexDescriptor descriptor = forSchema(forLabel(1, 1), provider.getProviderDescriptor()).withName("index_" + faultyIndexId).materialise(faultyIndexId);
InternalIndexState initialState = provider.getInitialState(descriptor, NULL);
// Then
assertThat(initialState).isEqualTo(InternalIndexState.POPULATING);
assertThat(logProvider).containsException(error);
}
use of java.nio.file.NoSuchFileException in project neo4j by neo4j.
the class NeoStores method verifyRecordFormat.
private void verifyRecordFormat(StoreType[] storeTypes, CursorContext cursorContext) {
String expectedStoreVersion = recordFormats.storeVersion();
long existingFormat;
if (!fileSystem.fileExists(layout.metadataStore())) {
// If the meta data store doesn't even exist then look no further, there's nothing to verify
return;
}
if (contains(storeTypes, StoreType.META_DATA)) {
// We're going to open this store anyway so might as well do it here, like we open the others
MetaDataStore metaDataStore = (MetaDataStore) getOrOpenStore(StoreType.META_DATA, cursorContext);
existingFormat = metaDataStore.getRecord(STORE_VERSION.id(), metaDataStore.newRecord(), RecordLoad.CHECK, cursorContext).getValue();
} else {
// if we have createIfNotExists set, but don't have the meta data store in the list of stores to open
try {
existingFormat = MetaDataStore.getRecord(pageCache, layout.metadataStore(), STORE_VERSION, layout.getDatabaseName(), cursorContext);
} catch (NoSuchFileException e) {
// Weird that the file isn't here after we passed the exists check above. Regardless, treat this the same way as above.
return;
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
if (existingFormat != MetaDataRecordFormat.FIELD_NOT_PRESENT) {
String actualStoreVersion = versionLongToString(existingFormat);
RecordFormats actualStoreFormat = RecordFormatSelector.selectForVersion(actualStoreVersion);
if (!isCompatibleFormats(actualStoreFormat)) {
throw new UnexpectedStoreVersionException(actualStoreVersion, expectedStoreVersion);
}
}
}
Aggregations