private Config mockConfig( Map<String,String> rawConfig ) { Config config = Mockito.mock( Config.class ); when( config.getRaw() ).thenReturn( rawConfig ); when( config.get( strict_config_validation ) ) .thenReturn( Boolean.valueOf( rawConfig.get( strict_config_validation.name() ) ) ); return config; } }
Kernel( String desiredId ) { super( fileSystemRule.get(), pageCacheRule.getPageCache( fileSystemRule.get() ), new File( GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), Config.defaults( forced_kernel_id, desiredId), mock( DataSourceManager.class ) ); kernels.add( this ); }
@Test public void augmentAnotherConfig() { Config config = Config(); config.augment( MySettingsWithDefaults.hello, "Hi" ); Config anotherConfig = Config(); anotherConfig.augment( stringMap( MySettingsWithDefaults.boolSetting.name(), Settings.FALSE, MySettingsWithDefaults.hello.name(), "Bye" ) ); config.augment( anotherConfig ); assertThat( config.get( MySettingsWithDefaults.boolSetting ), equalTo( false ) ); assertThat( config.get( MySettingsWithDefaults.hello ), equalTo( "Bye" ) ); }
private static Config loadNeo4jConfig( Path homeDir, Path configDir, String databaseName, Config additionalConfig ) { Config config = Config.fromFile( configDir.resolve( Config.DEFAULT_CONFIG_FILE_NAME ) ) .withHome( homeDir ) .withConnectorsDisabled() .withNoThrowOnFileLoadFailure() .build(); config.augment( additionalConfig ); config.augment( GraphDatabaseSettings.active_database, databaseName ); return config; } }
@Test public void testPluginInitialization() { Config config = Config.defaults( ServerSettings.transaction_idle_timeout, "600" ); NeoServer neoServer = Mockito.mock( NeoServer.class, Mockito.RETURNS_DEEP_STUBS ); Mockito.when( neoServer.getConfig() ).thenReturn( config ); ExtensionInitializer extensionInitializer = new ExtensionInitializer( neoServer ); Collection<Injectable<?>> injectableProperties = extensionInitializer.initializePackages( Collections.singletonList( "org.neo4j.server.modules" ) ); assertTrue( injectableProperties.stream() .anyMatch( i -> ServerSettings .transaction_idle_timeout.name().equals( i.getValue() ) ) ); }
@Test public void shouldReportThirdPartyPackagesAtSpecifiedMount() throws Exception { // Given WebServer webServer = mock( WebServer.class ); CommunityNeoServer neoServer = mock( CommunityNeoServer.class ); when( neoServer.baseUri() ).thenReturn( new URI( "http://localhost:7575" ) ); when( neoServer.getWebServer() ).thenReturn( webServer ); Database database = mock( Database.class ); when( neoServer.getDatabase() ).thenReturn( database ); Config config = mock( Config.class ); List<ThirdPartyJaxRsPackage> jaxRsPackages = new ArrayList<>(); String path = "/third/party/package"; jaxRsPackages.add( new ThirdPartyJaxRsPackage( "org.example.neo4j", path ) ); when( config.get( ServerSettings.third_party_packages ) ).thenReturn( jaxRsPackages ); // When ThirdPartyJAXRSModule module = new ThirdPartyJAXRSModule( webServer, config, NullLogProvider.getInstance(), neoServer ); module.start(); // Then verify( webServer ).addJAXRSPackages( any( List.class ), anyString(), anyCollection() ); } }
@Test void executeQueryStartDefaultTransaction() { KernelTransaction kernelTransaction = mock( KernelTransaction.class ); InternalTransaction transaction = new TopLevelTransaction( kernelTransaction ); when( queryService.beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ) ) .thenReturn( transaction ); graphDatabaseFacade.execute( "create (n)" ); graphDatabaseFacade.execute( "create (n)", new HashMap<>() ); long timeout = Config.defaults().get( GraphDatabaseSettings.transaction_timeout ).toMillis(); verify( spi, times( 2 ) ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED, timeout ); } }
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 ) ); }
@Test public void noThrowWhenLatestVersionAndUpgradeIsNotAllowed() { when( tailScanner.getTailInformation() ).thenReturn( new OnlyVersionTailInformation( LogEntryVersion.CURRENT ) ); LogVersionUpgradeChecker.check( tailScanner, Config.defaults( GraphDatabaseSettings.allow_upgrade, "false") ); }
@Test public void shouldAdvertiseServicesWhenAsked() throws Exception { UriInfo uriInfo = mock( UriInfo.class ); URI uri = new URI( "http://example.org:7474/" ); when( uriInfo.getBaseUri() ).thenReturn( uri ); RootService svc = new RootService( new CommunityNeoServer( Config.defaults( stringMap( new HttpConnector( "http", Encryption.NONE ).type.name(), "HTTP", new HttpConnector( "http", Encryption.NONE ).enabled.name(), "true" ) ), GraphDatabaseDependencies.newDependencies().userLogProvider( NullLogProvider.getInstance() ) .monitors( new Monitors() ) ) ); EntityOutputFormat output = new EntityOutputFormat( new JsonFormat(), null, null ); Response serviceDefinition = svc.getServiceDefinition( uriInfo, output ); assertEquals( 200, serviceDefinition.getStatus() ); Map<String, Object> result = (Map<String, Object>) output.getResultAsMap().get( "services" ); assertThat( result.get( "console" ) .toString(), containsString( String.format( "%sserver/console", uri.toString() ) ) ); assertThat( result.get( "jmx" ) .toString(), containsString( String.format( "%sserver/jmx", uri.toString() ) ) ); } }
@Test public void shouldLogIfConfigFileCouldNotBeFound() { Log log = mock( Log.class ); File confFile = testDirectory.file( "test.conf" ); // Note: we don't create the file. Config config = Config.fromFile( confFile ).withNoThrowOnFileLoadFailure().build(); config.setLogger( log ); verify( log ).warn( "Config file [%s] does not exist.", confFile ); }
@Test void shouldReportStoreSizes() throws Throwable { UdcInformationCollector collector = new DefaultUdcInformationCollector( Config.defaults(), dataSourceManager, usageData ); when( fileSystem.getFileSize( Mockito.any() ) ).thenReturn( 152L ); Map<String, String> udcParams = collector.getUdcParams(); assertThat( udcParams.get( "storesize" ), is( "152" ) ); }
final GraphDatabaseFacade mockDb = mock( GraphDatabaseFacade.class ); Config config = Config.defaults(); GraphDatabaseFacadeFactory.Dependencies deps = GraphDatabaseDependencies.newDependencies().userLogProvider( NullLogProvider.getInstance() ); GraphFactory factory = new SimpleGraphFactory( mockDb ); LifecycleManagingDatabase db = new LifecycleManagingDatabase( config, factory, deps ) when( mockDb.execute( LifecycleManagingDatabase.CYPHER_WARMUP_QUERY ) ).thenThrow( new TransactionFailureException( "Boo" ) );
PageCache pageCache = pageCacheRule.getPageCache( fileSystemAbstraction ); Config config = Config.defaults( GraphDatabaseSettings.rebuild_idgenerators_fast, "true" ); DynamicStringStore stringPropertyStore = mock( DynamicStringStore.class ); NullLogProvider.getInstance(), stringPropertyStore, mock( PropertyKeyTokenStore.class ), mock( DynamicArrayStore.class ), RecordFormatSelector.defaultFormat() ); store.initialise( true );
@Test public void shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint() throws Exception { // given String defaultProvider = Config.defaults().get( default_schema_provider ); when( constraintIndexCreator.createUniquenessConstraintIndex( transaction, descriptor, defaultProvider ) ).thenReturn( 42L ); when( storageReader.constraintsGetForSchema( descriptor.schema() ) ).thenReturn( Collections.emptyIterator() ); // when operations.uniquePropertyConstraintCreate( descriptor ); // then order.verify( locks ).acquireExclusive( LockTracer.NONE, ResourceTypes.LABEL, descriptor.getLabelId() ); order.verify( txState ).constraintDoAdd( ConstraintDescriptorFactory.uniqueForSchema( descriptor ), 42L ); }
@Test public void shouldRegisterASingleUri() { // Given WebServer webServer = mock( WebServer.class ); Map<String, String> params = new HashMap<>(); String path = "/db/data"; params.put( ServerSettings.rest_api_path.name(), path ); Config config = Config.defaults( params ); // When RESTApiModule module = new RESTApiModule( webServer, config, () -> new UsageData( mock( JobScheduler.class ) ), NullLogProvider.getInstance() ); module.start(); // Then verify( webServer ).addJAXRSClasses( anyListOf( String.class ), anyString(), any() ); } }
Config config = Config.defaults( GraphDatabaseSettings.rebuild_idgenerators_fast, "false" ); File storeFile = testDirectory.file( "nodes" ); File idFile = testDirectory.file( "idNodes" ); DynamicArrayStore labelStore = mock( DynamicArrayStore.class ); NodeStore store = new NodeStore( storeFile, idFile, config, new DefaultIdGeneratorFactory( fs ), pageCacheRule.getPageCache( fs ), NullLogProvider.getInstance(), labelStore, RecordFormatSelector.defaultFormat() ); store.initialise( true );
@Test public void shouldNotLoadNoneWhiteListedFunction() throws Throwable { // Given Log log = spy(Log.class); procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), log, new ProcedureConfig( Config.defaults( GraphDatabaseSettings.procedure_whitelist, "WrongName" ) ) ); List<CallableUserFunction> method = compile( SingleReadOnlyFunction.class ); verify( log ).warn( "The function 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded." ); assertThat( method.size(), equalTo( 0 ) ); }
@Before public void setup() throws Throwable { config = Config.defaults(); users = CommunitySecurityModule.getUserRepository( config, NullLogProvider.getInstance(), fsRule.get() ); UserRepository initUserRepository = CommunitySecurityModule.getInitialUserRepository( config, NullLogProvider.getInstance(), fsRule.get() ); manager = new BasicAuthManager( users, mock( PasswordPolicy.class ), authStrategy, initUserRepository ); manager.init(); }