Search in sources :

Example 1 with DEFAULT_DATABASE_NAME

use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.

the class ImportCommandTest method assertTokenIndexesCreated.

private void assertTokenIndexesCreated() {
    DatabaseManagementService dbms = dbmsService();
    try (var tx = dbms.database(DEFAULT_DATABASE_NAME).beginTx()) {
        var indexes = stream(tx.schema().getIndexes().spliterator(), false).collect(toList());
        assertThat(indexes.stream().filter(index -> index.getIndexType() == LOOKUP).count()).isEqualTo(2);
        assertTrue(indexes.stream().anyMatch(IndexDefinition::isNodeIndex));
        assertTrue(indexes.stream().anyMatch(IndexDefinition::isRelationshipIndex));
    } finally {
        dbms.shutdown();
    }
}
Also used : Arrays(java.util.Arrays) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Direction(org.neo4j.graphdb.Direction) Config(org.neo4j.configuration.Config) InputException(org.neo4j.internal.batchimport.input.InputException) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Path(java.nio.file.Path) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) Set(java.util.Set) RelationshipType.withName(org.neo4j.graphdb.RelationshipType.withName) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) ExecutionContext(org.neo4j.cli.ExecutionContext) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StreamSupport.stream(java.util.stream.StreamSupport.stream) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MissingParameterException(picocli.CommandLine.MissingParameterException) RelationshipType(org.neo4j.graphdb.RelationshipType) SuppressOutput(org.neo4j.test.rule.SuppressOutput) LOOKUP(org.neo4j.graphdb.schema.IndexType.LOOKUP) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ParameterException(picocli.CommandLine.ParameterException) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) String.join(java.lang.String.join) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Exceptions.withMessage(org.neo4j.internal.helpers.Exceptions.withMessage) COMMAS(org.neo4j.csv.reader.Configuration.COMMAS) Files(java.nio.file.Files) Iterators(org.neo4j.internal.helpers.collection.Iterators) MapUtil.store(org.neo4j.internal.helpers.collection.MapUtil.store) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) IOException(java.io.IOException) Label.label(org.neo4j.graphdb.Label.label) AfterEach(org.junit.jupiter.api.AfterEach) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IllegalMultilineFieldException(org.neo4j.csv.reader.IllegalMultilineFieldException) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Validator(org.neo4j.common.Validator) Exceptions.contains(org.neo4j.internal.helpers.Exceptions.contains) RandomExtension(org.neo4j.test.extension.RandomExtension) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.count(org.neo4j.internal.helpers.collection.Iterators.count) IntPredicate(java.util.function.IntPredicate) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) Iterables.single(org.neo4j.internal.helpers.collection.Iterables.single) Transaction(org.neo4j.graphdb.Transaction) Resources(org.junit.jupiter.api.parallel.Resources) GraphDatabaseInternalSettings.databases_root_path(org.neo4j.configuration.GraphDatabaseInternalSettings.databases_root_path) CommandLine(picocli.CommandLine) GraphDatabaseSettings.default_database(org.neo4j.configuration.GraphDatabaseSettings.default_database) Type(org.neo4j.internal.batchimport.input.csv.Type) Predicate(java.util.function.Predicate) TestDirectory(org.neo4j.test.rule.TestDirectory) UUID(java.util.UUID) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Label(org.neo4j.graphdb.Label) System.lineSeparator(java.lang.System.lineSeparator) MapUtil.stringMap(org.neo4j.internal.helpers.collection.MapUtil.stringMap) System.currentTimeMillis(java.lang.System.currentTimeMillis) GraphDatabaseSettings.transaction_logs_root_path(org.neo4j.configuration.GraphDatabaseSettings.transaction_logs_root_path) HashMap(java.util.HashMap) SuppressOutputExtension(org.neo4j.test.extension.SuppressOutputExtension) FileUtils.writeToFile(org.neo4j.io.fs.FileUtils.writeToFile) GraphDatabaseSettings.preallocate_logical_logs(org.neo4j.configuration.GraphDatabaseSettings.preallocate_logical_logs) HashSet(java.util.HashSet) Configuration(org.neo4j.csv.reader.Configuration) Charset(java.nio.charset.Charset) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Iterables(org.neo4j.internal.helpers.collection.Iterables) DuplicateInputIdException(org.neo4j.internal.batchimport.cache.idmapping.string.DuplicateInputIdException) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) PrintStream(java.io.PrintStream) Validators(org.neo4j.kernel.impl.util.Validators) Iterator(java.util.Iterator) PrefetchingIterator(org.neo4j.internal.helpers.collection.PrefetchingIterator) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) GraphDatabaseSettings.store_internal_log_path(org.neo4j.configuration.GraphDatabaseSettings.store_internal_log_path) Collectors.toList(java.util.stream.Collectors.toList) Relationship(org.neo4j.graphdb.Relationship) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) GraphDatabaseSettings.neo4j_home(org.neo4j.configuration.GraphDatabaseSettings.neo4j_home) Collections(java.util.Collections) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 2 with DEFAULT_DATABASE_NAME

use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.

the class IndexStatisticsStoreTest method shouldNotStartWithoutFileIfReadOnly.

@Test
void shouldNotStartWithoutFileIfReadOnly() {
    final IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(pageCache, testDirectory.file("non-existing"), immediate(), readOnly(), DEFAULT_DATABASE_NAME, PageCacheTracer.NULL);
    final Exception e = assertThrows(Exception.class, indexStatisticsStore::init);
    assertTrue(Exceptions.contains(e, t -> t instanceof ReadOnlyDbException));
    assertTrue(Exceptions.contains(e, t -> t instanceof TreeFileNotFoundException));
    assertTrue(Exceptions.contains(e, t -> t instanceof IllegalStateException));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) RandomExtension(org.neo4j.test.extension.RandomExtension) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TreeFileNotFoundException(org.neo4j.index.internal.gbptree.TreeFileNotFoundException) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ReadOnlyDbException(org.neo4j.kernel.api.exceptions.ReadOnlyDbException) Inject(org.neo4j.test.extension.Inject) RandomRule(org.neo4j.test.rule.RandomRule) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Exceptions(org.neo4j.internal.helpers.Exceptions) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) PageCache(org.neo4j.io.pagecache.PageCache) IndexSample(org.neo4j.kernel.api.index.IndexSample) ReporterFactories.noopReporterFactory(org.neo4j.annotations.documented.ReporterFactories.noopReporterFactory) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) EphemeralPageCacheExtension(org.neo4j.test.extension.pagecache.EphemeralPageCacheExtension) Test(org.junit.jupiter.api.Test) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Race.throwing(org.neo4j.test.Race.throwing) Race(org.neo4j.test.Race) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ReadOnlyDbException(org.neo4j.kernel.api.exceptions.ReadOnlyDbException) TreeFileNotFoundException(org.neo4j.index.internal.gbptree.TreeFileNotFoundException) TreeFileNotFoundException(org.neo4j.index.internal.gbptree.TreeFileNotFoundException) ReadOnlyDbException(org.neo4j.kernel.api.exceptions.ReadOnlyDbException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with DEFAULT_DATABASE_NAME

use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.

the class BatchingNeoStoresTest method someDataInTheDatabase.

private void someDataInTheDatabase(Config config) throws Exception {
    NullLog nullLog = NullLog.getInstance();
    try (JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
        PageCache pageCache = new ConfiguringPageCacheFactory(fileSystem, Config.defaults(), PageCacheTracer.NULL, nullLog, scheduler, Clocks.nanoClock(), new MemoryPools()).getOrCreatePageCache();
        Lifespan life = new Lifespan()) {
        // TODO this little dance with TokenHolders is really annoying and must be solved with a better abstraction
        DeferredInitializedTokenCreator propertyKeyTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.propertyKeyDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator labelTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.labelDoCreateForName(name, internal, id);
            }
        };
        DeferredInitializedTokenCreator relationshipTypeTokenCreator = new DeferredInitializedTokenCreator() {

            @Override
            void create(String name, boolean internal, int id) {
                txState.relationshipTypeDoCreateForName(name, internal, id);
            }
        };
        TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(propertyKeyTokenCreator, TokenHolder.TYPE_PROPERTY_KEY), new DelegatingTokenHolder(labelTokenCreator, TokenHolder.TYPE_LABEL), new DelegatingTokenHolder(relationshipTypeTokenCreator, TokenHolder.TYPE_RELATIONSHIP_TYPE));
        IndexConfigCompleter indexConfigCompleter = index -> index;
        RecoveryCleanupWorkCollector recoveryCleanupWorkCollector = immediate();
        RecordStorageEngine storageEngine = life.add(new RecordStorageEngine(databaseLayout, Config.defaults(), pageCache, fileSystem, NullLogProvider.getInstance(), tokenHolders, new DatabaseSchemaState(NullLogProvider.getInstance()), new StandardConstraintSemantics(), indexConfigCompleter, LockService.NO_LOCK_SERVICE, new DatabaseHealth(PanicEventGenerator.NO_OP, nullLog), new DefaultIdGeneratorFactory(fileSystem, immediate(), DEFAULT_DATABASE_NAME), new DefaultIdController(), recoveryCleanupWorkCollector, PageCacheTracer.NULL, true, INSTANCE, writable(), CommandLockVerification.Factory.IGNORE, LockVerificationMonitor.Factory.IGNORE));
        // Create the relationship type token
        TxState txState = new TxState();
        NeoStores neoStores = storageEngine.testAccessNeoStores();
        CommandCreationContext commandCreationContext = storageEngine.newCommandCreationContext(INSTANCE);
        commandCreationContext.initialize(NULL);
        propertyKeyTokenCreator.initialize(neoStores.getPropertyKeyTokenStore(), txState);
        labelTokenCreator.initialize(neoStores.getLabelTokenStore(), txState);
        relationshipTypeTokenCreator.initialize(neoStores.getRelationshipTypeTokenStore(), txState);
        int relTypeId = tokenHolders.relationshipTypeTokens().getOrCreateId(RELTYPE.name());
        apply(txState, commandCreationContext, storageEngine);
        // Finally, we're initialized and ready to create two nodes and a relationship
        txState = new TxState();
        long node1 = commandCreationContext.reserveNode();
        long node2 = commandCreationContext.reserveNode();
        txState.nodeDoCreate(node1);
        txState.nodeDoCreate(node2);
        txState.relationshipDoCreate(commandCreationContext.reserveRelationship(), relTypeId, node1, node2);
        apply(txState, commandCreationContext, storageEngine);
        neoStores.flush(NULL);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DefaultIdController(org.neo4j.internal.id.DefaultIdController) NullLogService(org.neo4j.logging.internal.NullLogService) Predicates(org.neo4j.function.Predicates) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenCreator(org.neo4j.token.TokenCreator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) LockVerificationMonitor(org.neo4j.internal.recordstorage.LockVerificationMonitor) NullLogProvider(org.neo4j.logging.NullLogProvider) ANY_LABEL(org.neo4j.token.api.TokenConstants.ANY_LABEL) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) JobSchedulerFactory(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory) NullLog(org.neo4j.logging.NullLog) Input(org.neo4j.internal.batchimport.input.Input) PageCache(org.neo4j.io.pagecache.PageCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) LockService(org.neo4j.lock.LockService) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) Test(org.junit.jupiter.api.Test) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Stream(java.util.stream.Stream) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) RelationshipType(org.neo4j.graphdb.RelationshipType) ANONYMOUS(org.neo4j.internal.kernel.api.security.AuthSubject.ANONYMOUS) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) EMPTY(org.neo4j.internal.batchimport.AdditionalInitialIds.EMPTY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BASE_TX_ID(org.neo4j.storageengine.api.TransactionIdStore.BASE_TX_ID) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) ArrayList(java.util.ArrayList) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Values(org.neo4j.values.storable.Values) TokenHolder(org.neo4j.token.api.TokenHolder) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) MemoryPools(org.neo4j.memory.MemoryPools) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD(org.neo4j.internal.batchimport.store.BatchingNeoStores.DOUBLE_RELATIONSHIP_RECORD_UNIT_THRESHOLD) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) LockTracer(org.neo4j.lock.LockTracer) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) Configuration(org.neo4j.internal.batchimport.Configuration) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PanicEventGenerator(org.neo4j.monitoring.PanicEventGenerator) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CommandLockVerification(org.neo4j.internal.recordstorage.CommandLockVerification) TokenStore(org.neo4j.kernel.impl.store.TokenStore) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) LATEST_RECORD_FORMATS(org.neo4j.kernel.impl.store.format.standard.Standard.LATEST_RECORD_FORMATS) ResourceLocker(org.neo4j.lock.ResourceLocker) CountsAccessor(org.neo4j.counts.CountsAccessor) RecoveryCleanupWorkCollector.immediate(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.immediate) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) TokenHolders(org.neo4j.token.TokenHolders) CountsBuilder(org.neo4j.internal.counts.CountsBuilder) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Clocks(org.neo4j.time.Clocks) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) NullLog(org.neo4j.logging.NullLog) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) DefaultIdController(org.neo4j.internal.id.DefaultIdController) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) MemoryPools(org.neo4j.memory.MemoryPools) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) TxState(org.neo4j.kernel.impl.api.state.TxState) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) BatchingNeoStores.batchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores.batchingNeoStores) TokenHolders(org.neo4j.token.TokenHolders) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PageCache(org.neo4j.io.pagecache.PageCache)

Example 4 with DEFAULT_DATABASE_NAME

use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.

the class GBPTreeTest method readHeaderMustWorkWithOpenIndex.

@Test
void readHeaderMustWorkWithOpenIndex() throws Exception {
    // GIVEN
    byte[] headerBytes = new byte[12];
    random.nextBytes(headerBytes);
    Consumer<PageCursor> headerWriter = pc -> pc.putBytes(headerBytes);
    // WHEN
    try (PageCache pageCache = createPageCache(defaultPageSize);
        GBPTree<MutableLong, MutableLong> ignore = index(pageCache).with(headerWriter).build()) {
        byte[] readHeader = new byte[headerBytes.length];
        AtomicInteger length = new AtomicInteger();
        Header.Reader headerReader = headerData -> {
            length.set(headerData.limit());
            headerData.get(readHeader);
        };
        GBPTree.readHeader(pageCache, indexFile, headerReader, DEFAULT_DATABASE_NAME, NULL);
        // THEN
        assertEquals(headerBytes.length, length.get());
        assertArrayEquals(headerBytes, readHeader);
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SimpleLongLayout.longLayout(org.neo4j.index.internal.gbptree.SimpleLongLayout.longLayout) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) PageCursor(org.neo4j.io.pagecache.PageCursor) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) RandomExtension(org.neo4j.test.extension.RandomExtension) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) Config(org.neo4j.configuration.Config) PageSwapper(org.neo4j.io.pagecache.PageSwapper) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PF_SHARED_WRITE_LOCK(org.neo4j.io.pagecache.PagedFile.PF_SHARED_WRITE_LOCK) ByteBuffer(java.nio.ByteBuffer) PageCacheSupportExtension(org.neo4j.test.extension.pagecache.PageCacheSupportExtension) DefaultPageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.DefaultPageCursorTracer) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) Future(java.util.concurrent.Future) StoreChannel(org.neo4j.io.fs.StoreChannel) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RandomRule(org.neo4j.test.rule.RandomRule) MutableLong(org.apache.commons.lang3.mutable.MutableLong) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) TestDirectoryExtension(org.neo4j.test.extension.testdirectory.TestDirectoryExtension) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) ThrowingRunnable.throwing(org.neo4j.index.internal.gbptree.ThrowingRunnable.throwing) Monitor(org.neo4j.index.internal.gbptree.GBPTree.Monitor) StandardOpenOption(java.nio.file.StandardOpenOption) FileIsNotMappedException(org.neo4j.io.pagecache.impl.FileIsNotMappedException) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) PinEvent(org.neo4j.io.pagecache.tracing.PinEvent) Sets.immutable(org.eclipse.collections.impl.factory.Sets.immutable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Queue(java.util.Queue) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) PagedFile(org.neo4j.io.pagecache.PagedFile) DELETE_ON_CLOSE(java.nio.file.StandardOpenOption.DELETE_ON_CLOSE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) NO_HEADER_READER(org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_READER) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) Inject(org.neo4j.test.extension.Inject) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) BiConsumer(java.util.function.BiConsumer) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) ByteBuffers(org.neo4j.io.memory.ByteBuffers) Math.toIntExact(java.lang.Math.toIntExact) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) ByteUnit(org.neo4j.io.ByteUnit) Barrier(org.neo4j.test.Barrier) OpenOption(java.nio.file.OpenOption) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AfterEach(org.junit.jupiter.api.AfterEach) PageCacheConfig.config(org.neo4j.test.rule.PageCacheConfig.config) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) CREATE(java.nio.file.StandardOpenOption.CREATE) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) DelegatingPagedFile(org.neo4j.io.pagecache.DelegatingPagedFile) FileUtils.blockSize(org.neo4j.io.fs.FileUtils.blockSize) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PageCacheConfig(org.neo4j.test.rule.PageCacheConfig) MutableLong(org.apache.commons.lang3.mutable.MutableLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.jupiter.api.Test)

Example 5 with DEFAULT_DATABASE_NAME

use of org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME in project neo4j by neo4j.

the class NumberArrayTest method arrays.

public static Collection<NumberArrayTestData> arrays() {
    PageCache pageCache = fixture.pageCache;
    Path dir = fixture.directory;
    NullLog log = NullLog.getInstance();
    Collection<NumberArrayTestData> list = new ArrayList<>();
    Map<String, NumberArrayFactory> factories = new HashMap<>();
    factories.put("HEAP", NumberArrayFactories.HEAP);
    factories.put("OFF_HEAP", NumberArrayFactories.OFF_HEAP);
    factories.put("AUTO_WITHOUT_PAGECACHE", NumberArrayFactories.AUTO_WITHOUT_PAGECACHE);
    factories.put("CHUNKED_FIXED_SIZE", NumberArrayFactories.CHUNKED_FIXED_SIZE);
    factories.put("autoWithPageCacheFallback", NumberArrayFactories.auto(pageCache, NULL, dir, true, NO_MONITOR, log, DEFAULT_DATABASE_NAME));
    factories.put("PageCachedNumberArrayFactory", new PageCachedNumberArrayFactory(pageCache, NULL, dir, log, DEFAULT_DATABASE_NAME));
    for (Map.Entry<String, NumberArrayFactory> entry : factories.entrySet()) {
        String name = entry.getKey() + " => ";
        NumberArrayFactory factory = entry.getValue();
        list.add(arrayData(name + "IntArray", factory.newIntArray(INDEXES, -1, INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.set(index, (Integer) value), IntArray::get));
        list.add(arrayData(name + "DynamicIntArray", factory.newDynamicIntArray(CHUNK_SIZE, -1, INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.set(index, (Integer) value), IntArray::get));
        list.add(arrayData(name + "LongArray", factory.newLongArray(INDEXES, -1, INSTANCE), random -> random.nextLong(1_000_000_000), (array, index, value) -> array.set(index, (Long) value), LongArray::get));
        list.add(arrayData(name + "DynamicLongArray", factory.newDynamicLongArray(CHUNK_SIZE, -1, INSTANCE), random -> random.nextLong(1_000_000_000), (array, index, value) -> array.set(index, (Long) value), LongArray::get));
        list.add(arrayData(name + "ByteArray5", factory.newByteArray(INDEXES, defaultByteArray(5), INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.setInt(index, 1, (Integer) value), (array, index) -> array.getInt(index, 1)));
        list.add(arrayData(name + "DynamicByteArray5", factory.newDynamicByteArray(CHUNK_SIZE, defaultByteArray(5), INSTANCE), random -> random.nextInt(1_000_000_000), (array, index, value) -> array.setInt(index, 1, (Integer) value), (array, index) -> array.getInt(index, 1)));
        Function<RandomRule, Object> valueGenerator = random -> new long[] { random.nextLong(), random.nextInt(), (short) random.nextInt(), (byte) random.nextInt() };
        Writer<ByteArray> writer = (array, index, value) -> {
            long[] values = (long[]) value;
            array.setLong(index, 0, values[0]);
            array.setInt(index, 8, (int) values[1]);
            array.setShort(index, 12, (short) values[2]);
            array.setByte(index, 14, (byte) values[3]);
        };
        Reader<ByteArray> reader = (array, index) -> new long[] { array.getLong(index, 0), array.getInt(index, 8), array.getShort(index, 12), array.getByte(index, 14) };
        list.add(arrayData(name + "ByteArray15", factory.newByteArray(INDEXES, defaultByteArray(15), INSTANCE), valueGenerator, writer, reader));
        list.add(arrayData(name + "DynamicByteArray15", factory.newDynamicByteArray(CHUNK_SIZE, defaultByteArray(15), INSTANCE), valueGenerator, writer, reader));
    }
    return list;
}
Also used : Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Arrays(java.util.Arrays) TestFactory(org.junit.jupiter.api.TestFactory) Collection(java.util.Collection) IOException(java.io.IOException) HashMap(java.util.HashMap) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) Function(java.util.function.Function) NO_MONITOR(org.neo4j.internal.batchimport.cache.NumberArrayFactories.NO_MONITOR) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Integer.max(java.lang.Integer.max) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Stream(java.util.stream.Stream) BeforeAll(org.junit.jupiter.api.BeforeAll) RandomRule(org.neo4j.test.rule.RandomRule) Map(java.util.Map) DynamicTest(org.junit.jupiter.api.DynamicTest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NullLog(org.neo4j.logging.NullLog) Path(java.nio.file.Path) ThrowingConsumer(org.junit.jupiter.api.function.ThrowingConsumer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RandomRule(org.neo4j.test.rule.RandomRule) NullLog(org.neo4j.logging.NullLog) HashMap(java.util.HashMap) Map(java.util.Map) PageCache(org.neo4j.io.pagecache.PageCache)

Aggregations

Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 DEFAULT_DATABASE_NAME (org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME)13 Test (org.junit.jupiter.api.Test)12 IOException (java.io.IOException)11 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)11 Inject (org.neo4j.test.extension.Inject)11 Path (java.nio.file.Path)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 PageCache (org.neo4j.io.pagecache.PageCache)9 RandomRule (org.neo4j.test.rule.RandomRule)9 TestDirectory (org.neo4j.test.rule.TestDirectory)9 ArrayList (java.util.ArrayList)8 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)8 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)8 Config (org.neo4j.configuration.Config)8 RandomExtension (org.neo4j.test.extension.RandomExtension)8 List (java.util.List)7 Set (java.util.Set)7 AfterEach (org.junit.jupiter.api.AfterEach)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7