@Test public void shouldBeAbleToRecoverBrokenStoreWithLogsInSeparateRelativeLocation() throws Exception { File customTransactionLogsLocation = new File( storeDir, "tx-logs" ); Config config = Config.defaults( logical_logs_location, customTransactionLogsLocation.getName() ); recoverBrokenStoreWithConfig( config ); }
@Test public void shouldAdjustURLToWithinImportDirectory() throws Exception { final URL url = new File( "/bar/baz.csv" ).toURI().toURL(); final Config config = Config.defaults( GraphDatabaseSettings.load_csv_file_url_root, "/var/lib/neo4j/import" ); URL accessURL = URLAccessRules.fileAccess().validate( config, url ); URL expected = new File( "/var/lib/neo4j/import/bar/baz.csv" ).toURI().toURL(); assertEquals( expected, accessURL ); } }
@Test public void shouldStopCleanlyEvenWhenItHasntBeenStarted() { new Jetty9WebServer( NullLogProvider.getInstance(), Config.defaults(), NetworkConnectionTracker.NO_OP ).stop(); }
@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 void shouldReadMultipleSettings() { // given ConfiguredSpaceFillingCurveSettingsCache globalSettings = new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ); Map<CoordinateReferenceSystem,SpaceFillingCurveSettings> expectedSpecificSettings = new HashMap<>(); rememberSettings( globalSettings, expectedSpecificSettings, WGS84, WGS84_3D, Cartesian ); IndexSpecificSpaceFillingCurveSettingsCache specificSettings = new IndexSpecificSpaceFillingCurveSettingsCache( globalSettings, expectedSpecificSettings ); SpaceFillingCurveSettingsWriter writer = new SpaceFillingCurveSettingsWriter( specificSettings ); byte[] bytes = new byte[PageCache.PAGE_SIZE]; writer.accept( new ByteArrayPageCursor( bytes ) ); Map<CoordinateReferenceSystem,SpaceFillingCurveSettings> readExpectedSettings = new HashMap<>(); SpaceFillingCurveSettingsReader reader = new SpaceFillingCurveSettingsReader( readExpectedSettings ); // when reader.read( ByteBuffer.wrap( bytes ) ); // then assertEquals( expectedSpecificSettings, readExpectedSettings ); }
private void extractTransactionalInformationFromLogs( String path, File customLogLocation, DatabaseLayout databaseLayout, File storeDir ) throws IOException { LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); File neoStore = databaseLayout.metadataStore(); GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( logical_logs_location, path ).newGraphDatabase(); for ( int i = 0; i < 10; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); transaction.success(); } } database.shutdown(); MetaDataStore.setRecord( pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT ); Config config = Config.defaults( logical_logs_location, path ); StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); LogPosition logPosition = migrator.extractTransactionLogPosition( neoStore, databaseLayout, 100 ); File[] logFiles = customLogLocation.listFiles(); assertNotNull( logFiles ); assertEquals( 0, logPosition.getLogVersion() ); assertEquals( logFiles[0].length(), logPosition.getByteOffset() ); }
private ConsistencyCheckService.Result checkConsistency() throws ConsistencyCheckIncompleteException { Config config = Config.defaults(); ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService( new Date() ); ConsistencyFlags checkConsistencyConfig = new ConsistencyFlags( config ); return consistencyCheckService.runFullConsistencyCheck( testDirectory.databaseLayout(), config, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), true, checkConsistencyConfig ); }
@Test public void shouldAdvertiseBoltIfExplicitlyConfigured() throws Exception { DiscoverableURIs uris = communityDiscoverableURIs( Config.defaults( ServerSettings.bolt_discoverable_address, "bolt://banana.com:1234" ), null ); assertEquals( "bolt://banana.com:1234", toMap(uris).get("bolt") ); }
@Test public void shouldReturnNullPolicyIfNullRequested() { // given SslPolicyLoader sslPolicyLoader = SslPolicyLoader.create( Config.defaults(), NullLogProvider.getInstance() ); // when SslPolicy sslPolicy = sslPolicyLoader.getPolicy( null ); // then assertNull( sslPolicy ); }
@Test public void shouldHaveConfigurableJettyThreadPoolSize() throws Exception { Jetty9WebServer server = new Jetty9WebServer( NullLogProvider.getInstance(), Config.defaults(), NetworkConnectionTracker.NO_OP ); int numCores = 1; int configuredMaxThreads = 12; // 12 is the new min max Threads value, for one core int acceptorThreads = 1; // In this configuration, 1 thread will become an acceptor... int selectorThreads = 1; // ... and 1 thread will become a selector... int jobThreads = configuredMaxThreads - acceptorThreads - selectorThreads; // ... and the rest are job threads server.setMaxThreads( numCores ); server.setHttpAddress( new ListenSocketAddress( "localhost", 0 ) ); try { server.start(); QueuedThreadPool threadPool = (QueuedThreadPool) server.getJetty().getThreadPool(); threadPool.start(); CountDownLatch startLatch = new CountDownLatch( jobThreads ); CountDownLatch endLatch = loadThreadPool( threadPool, configuredMaxThreads + 1, startLatch ); startLatch.await(); // Wait for threadPool to create threads int threads = threadPool.getThreads(); assertEquals( "Wrong number of threads in pool", configuredMaxThreads, threads ); endLatch.countDown(); } finally { server.stop(); } }
private StoreUpgrader newUpgrader( UpgradableDatabase upgradableDatabase, PageCache pageCache, MigrationProgressMonitor progressMonitor, SchemaIndexMigrator indexMigrator, StoreMigrator migrator ) { Config allowUpgrade = Config.defaults( GraphDatabaseSettings.allow_upgrade, "true" ); StoreUpgrader upgrader = new StoreUpgrader( upgradableDatabase, progressMonitor, allowUpgrade, fs, pageCache, NullLogProvider.getInstance() ); upgrader.addParticipant( indexMigrator ); upgrader.addParticipant( migrator ); return upgrader; }
@Test public void shouldOverrideBigPageCacheMemorySettingContainingUnit() { // GIVEN Config dbConfig = Config.defaults( pagecache_memory, "2g" ); Configuration config = new Configuration.Overridden( dbConfig ); // WHEN long memory = config.pageCacheMemory(); // THEN assertEquals( MAX_PAGE_CACHE_MEMORY, memory ); }
@Test public void shouldBeAbleToUsePortZero() throws Exception { // Given webServer = new Jetty9WebServer( NullLogProvider.getInstance(), Config.defaults(), NetworkConnectionTracker.NO_OP ); webServer.setHttpAddress( new ListenSocketAddress( "localhost", 0 ) ); // When webServer.start(); // Then no exception }
private StoreFactory factory( Integer customThreshold, PageCache pageCache ) { Map<String, String> customConfig = new HashMap<>(); if ( customThreshold != null ) { customConfig.put( GraphDatabaseSettings.dense_node_threshold.name(), "" + customThreshold ); } return new StoreFactory( testDir.databaseLayout(), Config.defaults( customConfig ), new DefaultIdGeneratorFactory( fs ), pageCache, fs, NullLogProvider.getInstance(), EmptyVersionContextSupplier.EMPTY ); }
@Test public void shouldAbleToAccessRegisteredPropertyByName() { Config config = Config.defaults(); ConfigAdapter wrappingConfiguration = new ConfigAdapter( config ); assertEquals( Duration.ofSeconds( 60 ), wrappingConfiguration.getProperty( ServerSettings.transaction_idle_timeout.name() ) ); }
@Test public void createRegularCommitProcess() { CommunityCommitProcessFactory factory = new CommunityCommitProcessFactory(); TransactionCommitProcess commitProcess = factory.create( mock( TransactionAppender.class ), mock( StorageEngine.class ), Config.defaults() ); assertThat( commitProcess, instanceOf( TransactionRepresentationCommitProcess.class ) ); } }
@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() ); } }
@Before public void setUp() { config = Config.defaults(); clock = Clocks.fakeClock(); logPruning = LogPruning.NO_PRUNING; logProvider = NullLogProvider.getInstance(); intervalTx = config.get( GraphDatabaseSettings.check_point_interval_tx ); intervalTime = config.get( GraphDatabaseSettings.check_point_interval_time ); triggerConsumer = new LinkedBlockingQueue<>(); triggered = triggerConsumer::offer; notTriggered = s -> fail( "Should not have triggered: " + s ); }