Search in sources :

Example 31 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class IdContextFactoryBuilderTest method createContextWithCustomIdGeneratorFactoryWhenProvided.

@Test
void createContextWithCustomIdGeneratorFactoryWhenProvided() throws IOException {
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    Config config = defaults();
    IdContextFactory contextFactory = IdContextFactoryBuilder.of(fs, jobScheduler, config, PageCacheTracer.NULL).withIdGenerationFactoryProvider(any -> idGeneratorFactory).build();
    DatabaseIdContext idContext = contextFactory.createIdContext(databaseIdRepository.getByName("database").get());
    IdGeneratorFactory bufferedGeneratorFactory = idContext.getIdGeneratorFactory();
    assertThat(idContext.getIdController()).isInstanceOf(BufferedIdController.class);
    assertThat(bufferedGeneratorFactory).isInstanceOf(BufferingIdGeneratorFactory.class);
    ((BufferingIdGeneratorFactory) bufferedGeneratorFactory).initialize(() -> mock(KernelTransactionsSnapshot.class));
    Path file = testDirectory.file("a");
    IdType idType = IdType.NODE;
    LongSupplier highIdSupplier = () -> 0;
    int maxId = 100;
    idGeneratorFactory.open(pageCache, file, idType, highIdSupplier, maxId, writable(), config, NULL, immutable.empty());
    verify(idGeneratorFactory).open(pageCache, file, idType, highIdSupplier, maxId, writable(), config, NULL, immutable.empty());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) Config.defaults(org.neo4j.configuration.Config.defaults) DatabaseIdFactory.from(org.neo4j.kernel.database.DatabaseIdFactory.from) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Function(java.util.function.Function) BufferedIdController(org.neo4j.internal.id.BufferedIdController) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) Inject(org.neo4j.test.extension.Inject) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Path(java.nio.file.Path) DatabaseIdRepository(org.neo4j.kernel.database.DatabaseIdRepository) PageCache(org.neo4j.io.pagecache.PageCache) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) UUID(java.util.UUID) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IdType(org.neo4j.internal.id.IdType) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Mockito.mock(org.mockito.Mockito.mock) Path(java.nio.file.Path) Config(org.neo4j.configuration.Config) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) LongSupplier(java.util.function.LongSupplier) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) IdType(org.neo4j.internal.id.IdType) Test(org.junit.jupiter.api.Test)

Example 32 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class IdContextFactoryBuilderTest method createContextWithFactoryWrapper.

@Test
void createContextWithFactoryWrapper() {
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    Function<IdGeneratorFactory, IdGeneratorFactory> factoryWrapper = ignored -> idGeneratorFactory;
    IdContextFactory contextFactory = IdContextFactoryBuilder.of(fs, jobScheduler, defaults(), PageCacheTracer.NULL).withFactoryWrapper(factoryWrapper).build();
    DatabaseIdContext idContext = contextFactory.createIdContext(databaseIdRepository.getByName("database").get());
    assertSame(idGeneratorFactory, idContext.getIdGeneratorFactory());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Sets.immutable(org.eclipse.collections.api.factory.Sets.immutable) LongSupplier(java.util.function.LongSupplier) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) Config.defaults(org.neo4j.configuration.Config.defaults) DatabaseIdFactory.from(org.neo4j.kernel.database.DatabaseIdFactory.from) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Function(java.util.function.Function) BufferedIdController(org.neo4j.internal.id.BufferedIdController) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) Inject(org.neo4j.test.extension.Inject) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Path(java.nio.file.Path) DatabaseIdRepository(org.neo4j.kernel.database.DatabaseIdRepository) PageCache(org.neo4j.io.pagecache.PageCache) PageCacheExtension(org.neo4j.test.extension.pagecache.PageCacheExtension) DatabaseReadOnlyChecker.writable(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) UUID(java.util.UUID) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IdType(org.neo4j.internal.id.IdType) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Mockito.mock(org.mockito.Mockito.mock) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) Test(org.junit.jupiter.api.Test)

Example 33 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldNotOpenStoreWithNodesOrRelationshipsInIt.

@Test
void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Throwable {
    Config config = Config.defaults();
    // GIVEN
    someDataInTheDatabase(config);
    // WHEN
    DirectoryNotEmptyException exception = assertThrows(DirectoryNotEmptyException.class, () -> {
        try (JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
            RecordFormats recordFormats = selectForConfig(Config.defaults(), NullLogProvider.getInstance());
            try (BatchingNeoStores store = batchingNeoStores(fileSystem, databaseLayout, recordFormats, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults(), jobScheduler, PageCacheTracer.NULL, INSTANCE)) {
                store.createNew();
            }
        }
    });
    assertThat(exception.getMessage()).contains("already contains");
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) Config(org.neo4j.configuration.Config) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 34 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldRespectDbConfig.

@Test
void shouldRespectDbConfig() throws Exception {
    // GIVEN
    int size = 10;
    Config config = Config.newBuilder().set(GraphDatabaseInternalSettings.array_block_size, size).set(GraphDatabaseInternalSettings.string_block_size, size).build();
    // WHEN
    RecordFormats recordFormats = LATEST_RECORD_FORMATS;
    int headerSize = recordFormats.dynamic().getRecordHeaderSize();
    try (JobScheduler jobScheduler = new ThreadPoolJobScheduler();
        BatchingNeoStores store = batchingNeoStores(fileSystem, databaseLayout, recordFormats, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, config, jobScheduler, PageCacheTracer.NULL, INSTANCE)) {
        store.createNew();
        // THEN
        assertEquals(size + headerSize, store.getPropertyStore().getArrayStore().getRecordSize());
        assertEquals(size + headerSize, store.getPropertyStore().getStringStore().getRecordSize());
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) Config(org.neo4j.configuration.Config) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 35 with JobScheduler

use of org.neo4j.scheduler.JobScheduler in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method corruptIndexes.

private List<Path> corruptIndexes(FileSystemAbstraction fs, DatabaseReadOnlyChecker readOnlyChecker, CorruptionInject corruptionInject, LayoutBootstrapper layoutBootstrapper, Path... targetFiles) throws Exception {
    List<Path> treeFiles = new ArrayList<>();
    try (JobScheduler jobScheduler = createInitialisedScheduler();
        GBPTreeBootstrapper bootstrapper = new GBPTreeBootstrapper(fs, jobScheduler, layoutBootstrapper, readOnlyChecker, NULL)) {
        for (Path file : targetFiles) {
            GBPTreeBootstrapper.Bootstrap bootstrap = bootstrapper.bootstrapTree(file, NO_FLUSH_ON_CLOSE);
            if (bootstrap.isTree()) {
                treeFiles.add(file);
                try (GBPTree<?, ?> gbpTree = bootstrap.getTree()) {
                    InspectingVisitor<?, ?> visitor = gbpTree.visit(new InspectingVisitor<>(), CursorContext.NULL);
                    corruptionInject.corrupt(gbpTree, visitor.get());
                }
            }
        }
    }
    return treeFiles;
}
Also used : Path(java.nio.file.Path) JobScheduler(org.neo4j.scheduler.JobScheduler) GBPTreeBootstrapper(org.neo4j.index.internal.gbptree.GBPTreeBootstrapper) ArrayList(java.util.ArrayList)

Aggregations

JobScheduler (org.neo4j.scheduler.JobScheduler)44 Test (org.junit.jupiter.api.Test)22 PageCache (org.neo4j.io.pagecache.PageCache)17 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)16 Config (org.neo4j.configuration.Config)15 Path (java.nio.file.Path)12 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)11 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)9 IOException (java.io.IOException)8 TokenHolders (org.neo4j.token.TokenHolders)7 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)6 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)5 IndexImporterFactoryImpl (org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl)5 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)5 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)4 DatabasePageCache (org.neo4j.dbms.database.DatabasePageCache)4 RecoveryCleanupWorkCollector (org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector)4 BatchImporter (org.neo4j.internal.batchimport.BatchImporter)4 Input (org.neo4j.internal.batchimport.input.Input)4 DefaultPageCacheTracer (org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer)4