Refine search
@Test void shouldNotSupportMultipleProvidersWithSameDescriptor() { // given IndexProviderDescriptor descriptor = new IndexProviderDescriptor( "provider", "1.2" ); IndexProvider provider1 = mock( IndexProvider.class ); when( provider1.getProviderDescriptor() ).thenReturn( descriptor ); IndexProvider provider2 = mock( IndexProvider.class ); when( provider2.getProviderDescriptor() ).thenReturn( descriptor ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( provider1 ); dependencies.satisfyDependency( provider2 ); // when assertThrows( IllegalArgumentException.class, () -> createDefaultProviderMap( dependencies, descriptor ).init() ); }
@BeforeEach void setUp() { Dependencies dependencies = new Dependencies(); dependencies.satisfyDependencies( new StubIdGeneratorFactory() ); dependencies.satisfyDependencies( fileSystem ); when( dataSource.getDependencyResolver() ).thenReturn( dependencies ); when( dataSource.getDatabaseLayout() ).thenReturn( DatabaseLayout.of( new File( "database" ) ) ); when( dataSource.getStoreId() ).thenReturn( StoreId.DEFAULT ); dataSourceManager.start(); dataSourceManager.register( dataSource ); }
dependencies = new Dependencies(); dependencies.satisfyDependency( databaseInfo ); clock = dependencies.satisfyDependency( createClock() ); life = dependencies.satisfyDependency( createLife() ); config.augmentDefaults( GraphDatabaseSettings.neo4j_home, storeLayout.storeDirectory().getPath() ); this.config = dependencies.satisfyDependency( config ); fileSystem = dependencies.satisfyDependency( createFileSystemAbstraction() ); life.add( new FileSystemLifecycleAdapter( fileSystem ) ); dependencies.satisfyDependency( monitors ); jobScheduler = life.add( dependencies.satisfyDependency( createJobScheduler() ) ); startDeferredExecutors(jobScheduler, externalDependencies.deferredExecutors()); dependencies.satisfyDependency( recoveryCleanupWorkCollector ); dependencies.satisfyDependency( life.add( usageData ) ); logging = dependencies.satisfyDependency( createLogService( externalDependencies.userLogProvider() ) ); .satisfyDependency( new StoreLockerLifecycleAdapter( createStoreLocker() ) ) ); String desiredImplementationName = config.get( GraphDatabaseSettings.tracer ); tracers = dependencies.satisfyDependency( new Tracers( desiredImplementationName, logging.getInternalLog( Tracers.class ), monitors, jobScheduler, clock ) ); dependencies.satisfyDependency( tracers.pageCacheTracer );
private static DependencyResolver buildIndexDependencies( IndexProvider... providers ) { Dependencies dependencies = new Dependencies(); dependencies.satisfyDependencies( (Object[]) providers ); return dependencies; }
private static <T> T dependency( Dependencies dependencies, Class<T> type, Function<DependencyResolver,T> defaultSupplier ) { try { return dependencies.resolveDependency( type ); } catch ( IllegalArgumentException | UnsatisfiedDependencyException e ) { return dependencies.satisfyDependency( defaultSupplier.apply( dependencies ) ); } }
@Test public void givenSatisfiedTypeInParentAndDependenciesWhenResolveWithTypeInDependenciesThenInstanceReturned() { // Given Dependencies parent = new Dependencies( ); Dependencies dependencies = new Dependencies( parent ); Collection foo = new ArrayList( ); dependencies.satisfyDependency( foo ); parent.satisfyDependency( new ArrayList()); // When Collection instance = dependencies.resolveDependency( Collection.class ); // Then assertThat(instance, equalTo(foo)); }
@Test public void flushOfThePageCacheOnShutdownDoesNotHappenIfTheDbIsUnhealthy() throws Throwable { DatabaseHealth health = mock( DatabaseHealth.class ); when( health.isHealthy() ).thenReturn( false ); PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( health ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache, dependencies ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache, never() ).flushAndForce( IOLimiter.UNLIMITED ); }
static Instances kernelTransactionWithInternals( LoginContext loginContext ) { TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] ); TransactionHeaderInformationFactory headerInformationFactory = mock( TransactionHeaderInformationFactory.class ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); StorageEngine storageEngine = mock( StorageEngine.class ); StorageReader storageReader = mock( StorageReader.class ); when( storageEngine.newReader() ).thenReturn( storageReader ); KernelTransactionImplementation transaction = new KernelTransactionImplementation( Config.defaults(), mock( StatementOperationParts.class ), mock( SchemaWriteGuard.class ), new TransactionHooks(), mock( ConstraintIndexCreator.class ), new Procedures(), headerInformationFactory, mock( TransactionRepresentationCommitProcess.class ), mock( TransactionMonitor.class ), mock( AuxiliaryTransactionStateManager.class ), mock( Pool.class ), Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ), EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock( SchemaState.class ), mock( IndexingService.class ), mockedTokenHolders(), new Dependencies() ); StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); transaction.initialize( 0, 0, statementLocks, KernelTransaction.Type.implicit, loginContext.authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 1L ); return new Instances( transaction ); }
@Test public void shouldPickTheOneAndOnlyQueryEngineAvailable() { // Given QueryEngineProvider provider = mock( QueryEngineProvider.class ); when( provider.enginePriority() ).thenReturn( 1 ); Dependencies deps = new Dependencies(); GraphDatabaseAPI graphAPI = mock( GraphDatabaseAPI.class ); QueryExecutionEngine executionEngine = mock( QueryExecutionEngine.class ); when( provider.createEngine( any(), any() ) ).thenReturn( executionEngine ); // When Iterable<QueryEngineProvider> providers = Iterables.asIterable( provider ); QueryExecutionEngine engine = QueryEngineProvider.initialize( deps, graphAPI, providers ); // Then assertSame( executionEngine, engine ); } }
@Before public void setUp() throws InvalidTransactionTypeKernelException txState = Mockito.spy( new TxState() ); when( transaction.getReasonIfTerminated() ).thenReturn( Optional.empty() ); when( transaction.statementLocks() ).thenReturn( new SimpleStatementLocks( locks ) ); when( transaction.dataWrite() ).thenReturn( write ); when( transaction.isOpen() ).thenReturn( true ); when( engine.newReader() ).thenReturn( storageReader ); allStoreHolder = new AllStoreHolder( storageReader, transaction, cursors, mock( ExplicitIndexStore.class ), mock( Procedures.class ), mock( SchemaState.class ), new Dependencies() ); constraintIndexCreator = mock( ConstraintIndexCreator.class ); operations = new Operations( allStoreHolder, mock( IndexTxStateUpdater.class ),storageReader, transaction, new KernelToken( storageReader, transaction, mockedTokenHolders() ), cursors, autoindexing, constraintIndexCreator, mock( ConstraintSemantics.class ), mock( IndexingProvidersService.class ), Config.defaults() ); operations.initialize();
@Test public void shouldConsultUnsatisfiedDependencyHandlerOnMissingDependencies() { // GIVEN KernelContext context = mock( KernelContext.class ); KernelExtensionFailureStrategy handler = mock( KernelExtensionFailureStrategy.class ); Dependencies dependencies = new Dependencies(); // that hasn't got anything. TestingExtensionFactory extensionFactory = new TestingExtensionFactory(); GlobalKernelExtensions extensions = new GlobalKernelExtensions( context, iterable( extensionFactory ), dependencies, handler ); // WHEN LifeSupport life = new LifeSupport(); life.add( extensions ); try { life.start(); // THEN verify( handler ).handle( eq( extensionFactory ), any( UnsatisfiedDependencyException.class ) ); } finally { life.shutdown(); } }
@Test public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception { // Given FileSystemAbstraction fs = this.fs.get(); PageCache pageCache = pageCacheRule.getPageCache( fs ); DatabaseHealth databaseHealth = mock( DatabaseHealth.class ); when( databaseHealth.isHealthy() ).thenReturn( true ); IOException ex = new IOException( "boom!" ); doThrow( ex ).when( databaseHealth ) .assertHealthy( IOException.class ); // <- this is a trick to simulate a failure during checkpointing Dependencies dependencies = new Dependencies(); dependencies.satisfyDependencies( databaseHealth ); NeoStoreDataSource dataSource = dsRule.getDataSource( dir.databaseLayout(), fs, pageCache, dependencies ); dataSource.start(); try { // When dataSource.stop(); fail( "it should have thrown" ); } catch ( LifecycleException e ) { // Then assertEquals( ex, e.getCause() ); } }
Dependencies dependencies = new Dependencies(); Config config = Config.defaults( default_schema_provider, indexProvider.getProviderDescriptor().name() ); DataSourceManager dataSourceManager = new DataSourceManager( config ); GraphDatabaseAPI db = mock( GraphDatabaseAPI.class ); NeoStoreDataSource dataSource = mock( NeoStoreDataSource.class ); dependencies.satisfyDependency( indexProvider ); dependencies.satisfyDependency( indexProvider2 ); dependencies.satisfyDependency( fs ); dependencies.satisfyDependencies( dataSourceManager ); dependencies.satisfyDependency( logFiles ); dependencies.satisfyDependency( explicitIndexProviderLookup ); dependencies.satisfyDependency( indexProviderMap ); dependencies.satisfyDependency( labelScanStore ); when( db.getDependencyResolver() ).thenReturn( dependencies ); when( dataSource.getDependencyResolver() ).thenReturn( dependencies ); when( dataSource.getDatabaseLayout() ).thenReturn( testDirectory.databaseLayout() );
private RecordStorageEngine get( FileSystemAbstraction fs, PageCache pageCache, IndexProvider indexProvider, DatabaseHealth databaseHealth, DatabaseLayout databaseLayout, Function<BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer, Monitors monitors, LockService lockService ) { IdGeneratorFactory idGeneratorFactory = new EphemeralIdGenerator.Factory(); ExplicitIndexProvider explicitIndexProviderLookup = mock( ExplicitIndexProvider.class ); when( explicitIndexProviderLookup.allIndexProviders() ).thenReturn( Iterables.empty() ); IndexConfigStore indexConfigStore = new IndexConfigStore( databaseLayout, fs ); JobScheduler scheduler = life.add( createScheduler() ); Config config = Config.defaults( GraphDatabaseSettings.default_schema_provider, indexProvider.getProviderDescriptor().name() ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( indexProvider ); BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory( idGeneratorFactory, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider() ); DefaultIndexProviderMap indexProviderMap = new DefaultIndexProviderMap( dependencies, config ); NullLogProvider nullLogProvider = NullLogProvider.getInstance(); life.add( indexProviderMap ); return life.add( new ExtendedRecordStorageEngine( databaseLayout, config, pageCache, fs, nullLogProvider, nullLogProvider, mockedTokenHolders(), mock( SchemaState.class ), new StandardConstraintSemantics(), scheduler, mock( TokenNameLookup.class ), lockService, indexProviderMap, IndexingService.NO_MONITOR, databaseHealth, explicitIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(), idGeneratorFactory, new BufferedIdController( bufferingIdGeneratorFactory, scheduler ), transactionApplierTransformer, monitors, RecoveryCleanupWorkCollector.immediate(), OperationalMode.single ) ); }
public KernelTransactionImplementation newNotInitializedTransaction() { return new KernelTransactionImplementation( Config.defaults(), statementOperations, schemaWriteGuard, hooks, null, null, headerInformationFactory, commitProcess, transactionMonitor, auxTxStateManager, txPool, clock, new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), TransactionTracer.NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ), EmptyVersionContextSupplier.EMPTY, () -> collectionsFactory, new StandardConstraintSemantics(), mock( SchemaState.class ), mock( IndexingService.class ), mockedTokenHolders(), new Dependencies() ); }
@Test public void logModuleSetUpError() { Config config = Config.defaults(); IdGeneratorFactory idGeneratorFactory = mock( IdGeneratorFactory.class ); Throwable openStoresError = new RuntimeException( "Can't set up modules" ); doThrow( openStoresError ).when( idGeneratorFactory ).create( any( File.class ), anyLong(), anyBoolean() ); CommunityIdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider(); AssertableLogProvider logProvider = new AssertableLogProvider(); SimpleLogService logService = new SimpleLogService( logProvider, logProvider ); PageCache pageCache = pageCacheRule.getPageCache( fs.get() ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependencies( idGeneratorFactory, idTypeConfigurationProvider, config, logService ); NeoStoreDataSource dataSource = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache, dependencies ); try { dataSource.start(); fail( "Exception expected" ); } catch ( Exception e ) { assertEquals( openStoresError, e ); } logProvider.assertAtLeastOnce( inLog( NeoStoreDataSource.class ).warn( equalTo( "Exception occurred while setting up store modules. Attempting to close things down." ), equalTo( openStoresError ) ) ); }
private static TestKernelTransactions createTestTransactions( StorageEngine storageEngine, TransactionCommitProcess commitProcess, TransactionIdStore transactionIdStore, Tracers tracers, StatementLocksFactory statementLocksFactory, StatementOperationParts statementOperations, SystemNanoClock clock, AvailabilityGuard databaseAvailabilityGuard ) { return new TestKernelTransactions( statementLocksFactory, null, statementOperations, null, DEFAULT, commitProcess, mock( AuxiliaryTransactionStateManager.class ), new TransactionHooks(), mock( TransactionMonitor.class ), databaseAvailabilityGuard, tracers, storageEngine, new Procedures(), transactionIdStore, clock, new CanWrite(), AutoIndexing.UNSUPPORTED, EmptyVersionContextSupplier.EMPTY, mockedTokenHolders(), new Dependencies() ); }
@Test public void databaseHealthShouldBeHealedOnStart() throws Throwable { NeoStoreDataSource theDataSource = null; try { DatabaseHealth databaseHealth = new DatabaseHealth( mock( DatabasePanicEventGenerator.class ), NullLogProvider.getInstance().getLog( DatabaseHealth.class ) ); Dependencies dependencies = new Dependencies(); dependencies.satisfyDependency( databaseHealth ); theDataSource = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCacheRule.getPageCache( fs.get() ), dependencies ); databaseHealth.panic( new Throwable() ); theDataSource.start(); databaseHealth.assertHealthy( Throwable.class ); } finally { if ( theDataSource != null ) { theDataSource.stop(); theDataSource.shutdown(); } } }
final JobScheduler jobScheduler = platformModule.jobScheduler; LogProvider logProvider = logging.getInternalLogProvider(); LogProvider userLogProvider = logging.getUserLogProvider(); final Supplier<DatabaseHealth> databaseHealthSupplier = dependencies.provideDependency( DatabaseHealth.class ); new LoggingInbound<>( raftServer, messageLogger, identityModule.myself() ); long inactivityTimeoutMillis = config.get( CoreEdgeClusterSettings.catch_up_client_inactivity_timeout ); CatchUpClient catchUpClient = life.add( new CatchUpClient( clusteringModule.topologyService(), logProvider, Clocks.systemClock(), inactivityTimeoutMillis, monitors ) ); platformModule.kernelExtensions.listFactories(), platformModule.pageCache ); if ( config.get( OnlineBackupSettings.online_backup_enabled ) ) logProvider, downloader, commandApplicationProcess ); dependencies.satisfyDependency( coreState ); life.add( new PruningScheduler( coreState, jobScheduler, platformModule.dependencies.provideDependency( TransactionIdStore.class ), platformModule.dependencies.provideDependency( LogicalTransactionStore.class ), localDatabase::dataSource, localDatabase::isAvailable, coreState, config, platformModule.monitors, new CheckpointerSupplier( platformModule.dependencies ) );
Map<String, String> params = getDefaultParams(); params.putAll( stringParams ); this.config = Config.defaults( params ); this.fileSystem = fileSystem; life = new LifeSupport(); this.databaseLayout = DatabaseLayout.of( databaseDirectory ); this.jobScheduler = JobSchedulerFactory.createInitialisedScheduler(); life.add( jobScheduler ); EmptyVersionContextSupplier.EMPTY, jobScheduler ); PageCache pageCache = pageCacheFactory.getOrCreatePageCache(); life.add( new PageCacheLifecycle( pageCache ) ); config.augment( logs_directory, databaseDirectory.getCanonicalPath() ); File internalLog = config.get( store_internal_log_path ); logService = life.add( StoreLogService.withInternalLog( internalLog).build( fileSystem ) ); Dependencies deps = new Dependencies(); Monitors monitors = new Monitors(); deps.satisfyDependencies( fileSystem, config, logService, storeIndexStoreView, pageCache, monitors, RecoveryCleanupWorkCollector.immediate() ); DatabaseKernelExtensions extensions = life.add( new DatabaseKernelExtensions(