public GraphDatabaseService newImpermanentDatabase( File storeDir ) { File absoluteDirectory = storeDir.getAbsoluteFile(); GraphDatabaseBuilder databaseBuilder = newImpermanentDatabaseBuilder( absoluteDirectory ); databaseBuilder.setConfig( GraphDatabaseSettings.active_database, absoluteDirectory.getName() ); databaseBuilder.setConfig( GraphDatabaseSettings.databases_root_path, absoluteDirectory.getParentFile().getAbsolutePath() ); return databaseBuilder.newGraphDatabase(); }
public static DbRepresentation of( File storeDir, boolean includeIndexes, Config config ) { GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ); builder.setConfig( config.getRaw() ); GraphDatabaseService db = builder.newGraphDatabase(); try { return of( db, includeIndexes ); } finally { db.shutdown(); } }
@Override protected GraphDatabaseService createGraphDatabase() { return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder() .setConfig( GraphDatabaseSettings.dense_node_threshold, String.valueOf( RELATIONSHIPS_COUNT ) ) .newGraphDatabase(); }
@Test public void shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase() { @SuppressWarnings( "deprecation" ) final GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase(); long lastCommittedTransactionId = getLastTxId( db ); db.shutdown(); rebuildCounts( lastCommittedTransactionId ); checkEmptyCountStore(); }
@Test public void shouldUnMapThePrestateFileWhenTimingOutOnRotationAndAllowForShutdownInTheFailedRotationState() throws Throwable { // Given dbBuilder.newGraphDatabase().shutdown(); CountsTracker store = createCountsTracker( pageCache, Config.defaults( GraphDatabaseSettings.counts_store_rotation_timeout, "100ms" ) ); try ( Lifespan lifespan = new Lifespan( store ) ) { try ( CountsAccessor.Updater updater = store.apply( 2 ).get() ) { updater.incrementNodeCount( 0, 1 ); } try { // when store.rotate( 3 ); fail( "should have thrown" ); } catch ( RotationTimeoutException ex ) { // good } } // and also no exceptions closing the page cache pageCache.close(); }
@Test public void shouldCreateACountStoreWhenDBContainsDenseNodes() setConfig( GraphDatabaseSettings.dense_node_threshold, "2" ).newGraphDatabase(); try ( Transaction tx = db.beginTx() )
@Override public void setup( File storeDir, Consumer<GraphDatabaseService> create ) { GraphDatabaseBuilder graphDatabaseBuilder = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder( storeDir ); settings.forEach( graphDatabaseBuilder::setConfig ); db = graphDatabaseBuilder.newGraphDatabase(); create.accept( db ); }
private void startDb() { if ( db != null ) { db.shutdown(); } db = factory.newImpermanentDatabaseBuilder() .setConfig( default_schema_provider, provider.getProviderDescriptor().name() ).newGraphDatabase(); }
private void makeSureIdsGetsReused( String fileName, Object value, int iterations ) { File storeDir = new File( "target/var/idreuse" ); File file = new File( storeDir, fileName ); GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem( fs.get() ). newImpermanentDatabaseBuilder( storeDir ). newGraphDatabase(); for ( int i = 0; i < 5; i++ ) { setAndRemoveSomeProperties( db, value ); } db.shutdown(); long sizeBefore = file.length(); db = new TestGraphDatabaseFactory().setFileSystem( fs.get() ).newImpermanentDatabase( storeDir ); for ( int i = 0; i < iterations; i++ ) { setAndRemoveSomeProperties( db, value ); } db.shutdown(); assertEquals( sizeBefore, file.length() ); }
private static void startStopDatabase( File storeDir ) { GraphDatabaseService databaseService = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( GraphDatabaseSettings.allow_upgrade, "true" ).newGraphDatabase(); databaseService.shutdown(); } }
@Test public void skipPopulationWhenNodeAndRelationshipStoresAreEmpty() { GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase(); long lastCommittedTransactionId = getLastTxId( db ); db.shutdown(); InvocationTrackingProgressReporter progressReporter = new InvocationTrackingProgressReporter(); rebuildCounts( lastCommittedTransactionId, progressReporter ); checkEmptyCountStore(); assertTrue( progressReporter.isCompleteInvoked() ); assertFalse( progressReporter.isStartInvoked() ); }
@Test( timeout = 60_000 ) public void possibleToShutdownDbWhenItIsNotHealthyAndNotAllTransactionsAreApplied() throws Exception .newGraphDatabase(); db.shutdown();
private GraphDatabaseService createGraphDatabaseService() { return new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( workingDatabaseLayout.databaseDirectory() ) .setConfig( GraphDatabaseSettings.allow_upgrade, "true" ) .newGraphDatabase(); } }
private GraphDatabaseAPI startDbNoRecoveryOfCorruptedLogs() { return (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabaseBuilder( storeDir ) .setConfig( GraphDatabaseSettings.fail_on_corrupted_log_files, Settings.FALSE ) .newGraphDatabase(); }
private GraphDatabaseAPI newDb() { return (GraphDatabaseAPI) new TestGraphDatabaseFactory() .newImpermanentDatabaseBuilder() .newGraphDatabase(); } }
@Test void failToDowngradeFormatWheUpgradeAllowed() { GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( record_format, StandardV3_2.NAME ) .setConfig( allow_upgrade, Settings.TRUE ).newGraphDatabase() ); assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() ); }
private void createGraphDbAndKillIt() { final GraphDatabaseService db = new TestGraphDatabaseFactory() .setFileSystem( fs ) .newImpermanentDatabaseBuilder( storeDirectory.databaseDir() ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { db.createNode( label( "FOO" ) ); db.createNode( label( "BAR" ) ); tx.success(); } db.shutdown(); }
@Test public void shouldBeAbleToStartAndShutdownMultipleTimesTheDBWithoutCommittingTransactions() throws Throwable { // given GraphDatabaseBuilder graphDatabaseBuilder = builder.setConfig( GraphDatabaseSettings .check_point_interval_time, "300m" ) .setConfig( GraphDatabaseSettings.check_point_interval_tx, "10000" ) .setConfig( GraphDatabaseSettings.logical_log_rotation_threshold, "1g" ); // when graphDatabaseBuilder.newGraphDatabase().shutdown(); graphDatabaseBuilder.newGraphDatabase().shutdown(); // then - 2 check points have been written in the log List<CheckPoint> checkPoints = new CheckPointCollector( testDirectory.databaseDir(), fs ).find( 0 ); assertEquals( 2, checkPoints.size() ); }
@Test public void rotationShouldNotCauseUnmappedFileProblem() throws IOException { // GIVEN GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase(); DependencyResolver resolver = db.getDependencyResolver(); RecordStorageEngine storageEngine = resolver.resolveDependency( RecordStorageEngine.class ); CountsTracker countStore = storageEngine.testAccessNeoStores().getCounts(); AtomicBoolean workerContinueFlag = new AtomicBoolean( true ); AtomicLong lookupsCounter = new AtomicLong(); int rotations = 100; for ( int i = 0; i < 5; i++ ) { threadingRule.execute( countStoreLookup( workerContinueFlag, lookupsCounter ), countStore ); } long startTxId = countStore.txId(); for ( int i = 1; (i < rotations) || (lookupsCounter.get() == 0); i++ ) { try ( Transaction tx = db.beginTx() ) { db.createNode( B ); tx.success(); } checkPoint( db ); } workerContinueFlag.set( false ); assertEquals( "Should perform at least 100 rotations.", rotations, Math.min( rotations, countStore.txId() - startTxId) ); assertTrue( "Should perform more then 0 lookups without exceptions.", lookupsCounter.get() > 0 ); db.shutdown(); }
@Test( timeout = 60_000 ) public void recoveryShouldFixPartiallyAppliedSchemaIndexUpdates() GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create( fileSystemRule.get(), adversary ) .newEmbeddedDatabaseBuilder( databaseDir ) .newGraphDatabase(); try db.shutdown(); db = startDatabase( databaseDirectory ); db.shutdown();