private void shutdownAnyRunning() { if ( dataSource != null ) { dataSource.stop(); } }
@Test public void flushOfThePageCacheHappensOnlyOnceDuringShutdown() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); verify( pageCache, never() ).flushAndForce( any( IOLimiter.class ) ); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@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 ); }
@Test public void flushOfThePageCacheOnShutdownHappensIfTheDbIsHealthy() throws Throwable { PageCache pageCache = spy( pageCacheRule.getPageCache( fs.get() ) ); NeoStoreDataSource ds = dsRule.getDataSource( dir.databaseLayout(), fs.get(), pageCache ); ds.start(); verify( pageCache, never() ).flushAndForce(); ds.stop(); ds.shutdown(); verify( pageCache ).flushAndForce( IOLimiter.UNLIMITED ); }
@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() ); } }
private void restartNeoDataSource( GraphDatabaseAPI slave ) throws Throwable { slave.getDependencyResolver().resolveDependency( DataSourceManager.class ).getDataSource().stop(); slave.getDependencyResolver().resolveDependency( DataSourceManager.class ).getDataSource().start(); } }
@Test public void testSetBlockSize() throws Exception { DatabaseLayout databaseLayout = dir.databaseLayout( "small_store" ); initializeStores( databaseLayout, stringMap( "unsupported.dbms.block_size.strings", "62", "unsupported.dbms.block_size.array_properties", "302" ) ); assertEquals( 62 + DynamicRecordFormat.RECORD_HEADER_SIZE, pStore.getStringStore().getRecordSize() ); assertEquals( 302 + DynamicRecordFormat.RECORD_HEADER_SIZE, pStore.getArrayStore().getRecordSize() ); ds.stop(); }
@Test public void shutdownWhileFinishingTransactionWithIndexUpdates() { createConstraint( database ); waitIndexesOnline( database ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( constraintIndexLabel ); node.setProperty( UNIQUE_PROPERTY_NAME, indexProvider.getAndIncrement() ); DependencyResolver dependencyResolver = database.getDependencyResolver(); NeoStoreDataSource dataSource = dependencyResolver.resolveDependency( NeoStoreDataSource.class ); LifeSupport dataSourceLife = dataSource.getLife(); TransactionCloseListener closeListener = new TransactionCloseListener( transaction ); dataSourceLife.addLifecycleListener( closeListener ); dataSource.stop(); assertTrue( "Transaction should be closed and no exception should be thrown.", closeListener.isTransactionClosed() ); } }
@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(); } } }
@Test public void testProps1() throws Exception { initializeStores( databaseLayout, stringMap() ); startTx(); long nodeId = nextId( Node.class ); transaction.nodeDoCreate( nodeId ); pStore.nextId(); StorageProperty prop = nodeAddProperty( nodeId, index( "nisse" ), 10 ); commitTx(); ds.stop(); initializeStores( databaseLayout, stringMap() ); startTx(); StorageProperty prop2 = nodeAddProperty( nodeId, prop.propertyKeyId(), 5 ); transaction.nodeDoRemoveProperty( nodeId, prop2.propertyKeyId() ); transaction.nodeDoDelete( nodeId ); commitTx(); ds.stop(); }
@Test public void testRels1() throws Exception { initializeStores( databaseLayout, stringMap() ); startTx(); int relType1 = (int) nextId( RelationshipType.class ); String typeName = "relationshiptype1"; transaction.relationshipTypeDoCreateForName( typeName, relType1 ); long[] nodeIds = new long[3]; for ( int i = 0; i < 3; i++ ) { nodeIds[i] = nextId( Node.class ); transaction.nodeDoCreate( nodeIds[i] ); nodeAddProperty( nodeIds[i], index( "nisse" ), 10 - i ); } for ( int i = 0; i < 2; i++ ) { transaction.relationshipDoCreate( nextId( Relationship.class ), relType1, nodeIds[i], nodeIds[i + 1] ); } commitTx(); startTx(); for ( int i = 0; i < 3; i += 2 ) { deleteRelationships( nodeIds[i] ); transaction.nodeDoDelete( nodeIds[i] ); } commitTx(); ds.stop(); }
ds.stop();
relDelete( rel5 ); commitTx(); ds.stop();