use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class NeoStoreOpenFailureTest method mustCloseAllStoresIfNeoStoresFailToOpen.
@Test
@DisabledForRoot
void mustCloseAllStoresIfNeoStoresFailToOpen() {
Config config = Config.defaults();
IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
LogProvider logProvider = NullLogProvider.getInstance();
RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
RecordFormatPropertyConfigurator.configureRecordFormat(formats, config);
boolean create = true;
StoreType[] storeTypes = StoreType.values();
ImmutableSet<OpenOption> openOptions = immutable.empty();
NeoStores neoStores = new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions);
Path schemaStore = neoStores.getSchemaStore().getStorageFile();
neoStores.close();
// Make the schema store inaccessible, to sabotage the next initialisation we'll do.
assumeTrue(schemaStore.toFile().setReadable(false));
assumeTrue(schemaStore.toFile().setWritable(false));
assertThrows(RuntimeException.class, () -> new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions));
// We verify that the successfully opened stores were closed again by the failed NeoStores open,
// by closing the page cache, which will throw if not all files have been unmapped.
pageCache.close();
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class NodeStoreTest method newNodeStore.
private NodeStore newNodeStore(FileSystemAbstraction fs, PageCache pageCache) {
IdGeneratorFactory idGeneratorFactory = spy(new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()) {
@Override
protected IndexedIdGenerator instantiate(FileSystemAbstraction fs, PageCache pageCache, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, Path fileName, LongSupplier highIdSupplier, long maxValue, IdType idType, DatabaseReadOnlyChecker readOnlyChecker, Config config, CursorContext cursorContext, String databaseName, ImmutableSet<OpenOption> openOptions) {
return spy(super.instantiate(fs, pageCache, recoveryCleanupWorkCollector, fileName, highIdSupplier, maxValue, idType, readOnlyChecker, config, cursorContext, databaseName, openOptions));
}
});
StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable());
neoStores = factory.openAllNeoStores(true);
nodeStore = neoStores.getNodeStore();
return nodeStore;
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class CommonAbstractStoreTest method shouldDeleteOnCloseIfOpenOptionsSaysSo.
@Test
void shouldDeleteOnCloseIfOpenOptionsSaysSo() throws IOException {
// GIVEN
Path nodeStore = databaseLayout.nodeStore();
Path idFile = databaseLayout.idFile(DatabaseFile.NODE_STORE).orElseThrow(() -> new IllegalStateException("Node store id file not found."));
TheStore store = new TheStore(nodeStore, databaseLayout.idNodeStore(), config, idType, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, NullLogProvider.getInstance(), recordFormat, immutable.with(DELETE_ON_CLOSE));
store.initialise(true, NULL);
store.start(NULL);
assertTrue(fs.fileExists(nodeStore));
assertTrue(fs.fileExists(idFile));
// WHEN
store.close();
// THEN
assertFalse(fs.fileExists(nodeStore));
assertFalse(fs.fileExists(idFile));
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class MetaDataStoreTest method newMetaDataStore.
private MetaDataStore newMetaDataStore(PageCacheTracer pageCacheTracer) {
LogProvider logProvider = NullLogProvider.getInstance();
StoreFactory storeFactory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCacheWithFakeOverflow, fs, logProvider, pageCacheTracer, writable());
return storeFactory.openNeoStores(true, StoreType.META_DATA).getMetaDataStore();
}
use of org.neo4j.internal.id.DefaultIdGeneratorFactory in project neo4j by neo4j.
the class PropertyStoreTest method shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord.
@Test
void shouldWriteOutTheDynamicChainBeforeUpdatingThePropertyRecord() throws IOException {
// given
try (PageCache pageCache = pageCacheExtension.getPageCache(fs)) {
Config config = Config.defaults();
DynamicStringStore stringPropertyStore = mock(DynamicStringStore.class);
try (var store = new PropertyStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, NullLogProvider.getInstance(), stringPropertyStore, mock(PropertyKeyTokenStore.class), mock(DynamicArrayStore.class), RecordFormatSelector.defaultFormat(), writable(), databaseLayout.getDatabaseName(), immutable.empty())) {
store.initialise(true, NULL);
store.start(NULL);
final long propertyRecordId = store.nextId(NULL);
PropertyRecord record = new PropertyRecord(propertyRecordId);
record.setInUse(true);
DynamicRecord dynamicRecord = dynamicRecord();
PropertyBlock propertyBlock = propertyBlockWith(dynamicRecord);
record.setPropertyBlock(propertyBlock);
doAnswer(invocation -> {
PropertyRecord recordBeforeWrite = store.getRecord(propertyRecordId, store.newRecord(), FORCE, NULL);
assertFalse(recordBeforeWrite.inUse());
return null;
}).when(stringPropertyStore).updateRecord(eq(dynamicRecord), any());
// when
store.updateRecord(record, NULL);
// then verify that our mocked method above, with the assert, was actually called
verify(stringPropertyStore).updateRecord(eq(dynamicRecord), any(), any());
}
}
}
Aggregations