Search in sources :

Example 11 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class NumberArrayPageCacheTestSupport method prepareDirectoryAndPageCache.

static Fixture prepareDirectoryAndPageCache(Class<?> testClass) throws IOException {
    DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
    TestDirectory testDirectory = TestDirectory.testDirectory(testClass, fileSystem);
    Path dir = testDirectory.prepareDirectoryForTest("test");
    ThreadPoolJobScheduler scheduler = new ThreadPoolJobScheduler();
    PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, scheduler, PageCacheTracer.NULL);
    return new Fixture(pageCache, fileSystem, dir, scheduler);
}
Also used : Path(java.nio.file.Path) TestDirectory(org.neo4j.test.rule.TestDirectory) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PageCache(org.neo4j.io.pagecache.PageCache)

Example 12 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class GBPTreeBootstrapperTest method shouldBootstrapTreeOfDifferentPageSizes.

@ParameterizedTest
@MethodSource("testSetupStream")
void shouldBootstrapTreeOfDifferentPageSizes(TestSetup testSetup) throws Exception {
    setupTest(testSetup);
    ZipUtils.unzipResource(getClass(), zipName, storeFile);
    LayoutBootstrapper layoutBootstrapper = (indexFile, pageCache, meta) -> layout;
    try (JobScheduler scheduler = new ThreadPoolJobScheduler();
        GBPTreeBootstrapper bootstrapper = new GBPTreeBootstrapper(fs, scheduler, layoutBootstrapper, readOnly(), PageCacheTracer.NULL)) {
        GBPTreeBootstrapper.Bootstrap bootstrap = bootstrapper.bootstrapTree(storeFile);
        assertTrue(bootstrap.isTree());
        try (GBPTree<?, ?> tree = bootstrap.getTree()) {
            assertTrue(tree.consistencyCheck(CursorContext.NULL));
        }
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) SimpleLongLayout.longLayout(org.neo4j.index.internal.gbptree.SimpleLongLayout.longLayout) DatabaseReadOnlyChecker.readOnly(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.readOnly) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ZipUtils(org.neo4j.io.compress.ZipUtils) Disabled(org.junit.jupiter.api.Disabled) Inject(org.neo4j.test.extension.Inject) MutableLong(org.apache.commons.lang3.mutable.MutableLong) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) JobScheduler(org.neo4j.scheduler.JobScheduler) TestDirectoryExtension(org.neo4j.test.extension.testdirectory.TestDirectoryExtension) Path(java.nio.file.Path) MethodSource(org.junit.jupiter.params.provider.MethodSource) PageCache(org.neo4j.io.pagecache.PageCache) ByteUnit(org.neo4j.io.ByteUnit) StandalonePageCacheFactory(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method populatorMarkedAsFailed.

@Test
void populatorMarkedAsFailed() throws Exception {
    Update update1 = nodeUpdate(1, propertyId, "aaa", labelId);
    Update update2 = nodeUpdate(1, propertyId, "bbb", labelId);
    IndexStoreView storeView = newStoreView(update1, update2);
    RuntimeException batchFlushError = new RuntimeException("Batch failed");
    IndexPopulator populator;
    ExecutorService executor = Executors.newSingleThreadExecutor();
    ThreadPoolJobScheduler jobScheduler = new ThreadPoolJobScheduler(executor);
    try {
        MultipleIndexPopulator batchingPopulator = new MultipleIndexPopulator(storeView, NullLogProvider.getInstance(), EntityType.NODE, mock(SchemaState.class), jobScheduler, tokens, NULL, INSTANCE, "", AUTH_DISABLED, Config.defaults(GraphDatabaseInternalSettings.index_population_batch_max_byte_size, 1L));
        populator = addPopulator(batchingPopulator, index1);
        List<IndexEntryUpdate<IndexDescriptor>> expected = forUpdates(index1, update1, update2);
        doThrow(batchFlushError).when(populator).add(eq(expected), any());
        batchingPopulator.createStoreScan(NULL).run(NO_EXTERNAL_UPDATES);
    } finally {
        jobScheduler.shutdown();
        executor.awaitTermination(1, TimeUnit.MINUTES);
    }
    verify(populator).markAsFailed(failure(batchFlushError).asString());
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) SchemaState(org.neo4j.internal.schema.SchemaState) ExecutorService(java.util.concurrent.ExecutorService) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 14 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class MultipleIndexPopulationStressIT method createRandomData.

private void createRandomData(long nodeCount, long relCount) throws Exception {
    Config config = Config.defaults(neo4j_home, directory.homePath());
    RecordFormats recordFormats = RecordFormatSelector.selectForConfig(config, NullLogProvider.getInstance());
    try (RandomDataInput input = new RandomDataInput(nodeCount, relCount);
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        DatabaseLayout layout = Neo4jLayout.of(directory.homePath()).databaseLayout(DEFAULT_DATABASE_NAME);
        IndexImporterFactory indexImporterFactory = new IndexImporterFactoryImpl(config);
        BatchImporter importer = new ParallelBatchImporter(layout, fileSystemAbstraction, PageCacheTracer.NULL, DEFAULT, NullLogService.getInstance(), ExecutionMonitor.INVISIBLE, EMPTY, config, recordFormats, NO_MONITOR, jobScheduler, Collector.EMPTY, TransactionLogInitializer.getLogFilesInitializer(), indexImporterFactory, INSTANCE);
        importer.doImport(input);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) ParallelBatchImporter(org.neo4j.internal.batchimport.ParallelBatchImporter) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) BatchImporter(org.neo4j.internal.batchimport.BatchImporter) ParallelBatchImporter(org.neo4j.internal.batchimport.ParallelBatchImporter) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) IndexImporterFactory(org.neo4j.internal.batchimport.IndexImporterFactory) IndexImporterFactoryImpl(org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler)

Example 15 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class NodeImporterTest method tracePageCacheAccessOnNodeImport.

@Test
void tracePageCacheAccessOnNodeImport() throws IOException {
    JobScheduler scheduler = new ThreadPoolJobScheduler();
    try (Lifespan life = new Lifespan(scheduler);
        BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache(fs, pageCache, NULL, layout, Standard.LATEST_RECORD_FORMATS, Configuration.DEFAULT, NullLogService.getInstance(), AdditionalInitialIds.EMPTY, Config.defaults(), INSTANCE)) {
        stores.createNew();
        int numberOfLabels = 50;
        long nodeId = 0;
        var cacheTracer = new DefaultPageCacheTracer();
        try (NodeImporter importer = new NodeImporter(stores, IdMappers.actual(), new DataImporter.Monitor(), cacheTracer, INSTANCE)) {
            importer.id(nodeId);
            String[] labels = new String[numberOfLabels];
            for (int i = 0; i < labels.length; i++) {
                labels[i] = "Label" + i;
            }
            importer.labels(labels);
            importer.property("a", randomAscii(10));
            importer.property("b", randomAscii(100));
            importer.property("c", randomAscii(1000));
            importer.endOfEntity();
        }
        NodeStore nodeStore = stores.getNodeStore();
        NodeRecord record = nodeStore.getRecord(nodeId, nodeStore.newRecord(), RecordLoad.NORMAL, CursorContext.NULL);
        long[] labels = NodeLabelsField.parseLabelsField(record).get(nodeStore, CursorContext.NULL);
        assertEquals(numberOfLabels, labels.length);
        assertThat(cacheTracer.faults()).isEqualTo(2);
        assertThat(cacheTracer.pins()).isEqualTo(13);
        assertThat(cacheTracer.unpins()).isEqualTo(13);
        assertThat(cacheTracer.hits()).isEqualTo(11);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) BatchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Aggregations

ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)26 JobScheduler (org.neo4j.scheduler.JobScheduler)15 Test (org.junit.jupiter.api.Test)14 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 PageCache (org.neo4j.io.pagecache.PageCache)9 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)8 Path (java.nio.file.Path)7 Config (org.neo4j.configuration.Config)7 IOException (java.io.IOException)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 Transaction (org.neo4j.graphdb.Transaction)4 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)4 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)4 SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)4 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)4 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Input (org.neo4j.internal.batchimport.input.Input)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)3