Search in sources :

Example 1 with BufferingIdGeneratorFactory

use of org.neo4j.internal.id.BufferingIdGeneratorFactory in project neo4j by neo4j.

the class IdContextFactory method createBufferingIdContext.

private DatabaseIdContext createBufferingIdContext(Function<NamedDatabaseId, ? extends IdGeneratorFactory> idGeneratorFactoryProvider, JobScheduler jobScheduler, PageCacheTracer cacheTracer, NamedDatabaseId namedDatabaseId) {
    IdGeneratorFactory idGeneratorFactory = idGeneratorFactoryProvider.apply(namedDatabaseId);
    BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(idGeneratorFactory);
    BufferedIdController bufferingController = createBufferedIdController(bufferingIdGeneratorFactory, jobScheduler, cacheTracer, namedDatabaseId.name());
    return createIdContext(bufferingIdGeneratorFactory, bufferingController);
}
Also used : BufferedIdController(org.neo4j.internal.id.BufferedIdController) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) BufferingIdGeneratorFactory(org.neo4j.internal.id.BufferingIdGeneratorFactory)

Example 2 with BufferingIdGeneratorFactory

use of org.neo4j.internal.id.BufferingIdGeneratorFactory 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)

Aggregations

BufferedIdController (org.neo4j.internal.id.BufferedIdController)2 BufferingIdGeneratorFactory (org.neo4j.internal.id.BufferingIdGeneratorFactory)2 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 LongSupplier (java.util.function.LongSupplier)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Sets.immutable (org.eclipse.collections.api.factory.Sets.immutable)1 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Test (org.junit.jupiter.api.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Config (org.neo4j.configuration.Config)1 Config.defaults (org.neo4j.configuration.Config.defaults)1 DatabaseReadOnlyChecker.writable (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker.writable)1 IdGenerator (org.neo4j.internal.id.IdGenerator)1 IdType (org.neo4j.internal.id.IdType)1