@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 public void shouldGenerateDatabasePanicEvents() { // GIVEN DatabasePanicEventGenerator generator = mock( DatabasePanicEventGenerator.class ); DatabaseHealth databaseHealth = new DatabaseHealth( generator, NullLogProvider.getInstance().getLog( DatabaseHealth.class ) ); databaseHealth.healed(); // WHEN Exception cause = new Exception( "My own fault" ); databaseHealth.panic( cause ); databaseHealth.panic( cause ); // THEN verify( generator, times( 1 ) ).generateEvent( TX_MANAGER_NOT_OK, cause ); }
@Test public void shouldRollbackTransactionAndTellRegistryToForgetItsHandle() { // given TransitionalPeriodTransactionMessContainer kernel = mockKernel(); TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction( explicit, AUTH_DISABLED, -1 ); TransactionRegistry registry = mock( TransactionRegistry.class ); when( registry.begin( any( TransactionHandle.class ) ) ).thenReturn( 1337L ); GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); TransactionHandle handle = new TransactionHandle( kernel, mock( QueryExecutionEngine.class ), queryService, registry, uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance() ); ExecutionResultSerializer output = mock( ExecutionResultSerializer.class ); // when handle.rollback( output ); // then InOrder transactionOrder = inOrder( transactionContext, registry ); transactionOrder.verify( transactionContext ).rollback(); transactionOrder.verify( registry ).forget( 1337L ); InOrder outputOrder = inOrder( output ); outputOrder.verify( output ).errors( argThat( hasNoErrors() ) ); outputOrder.verify( output ).finish(); verifyNoMoreInteractions( output ); }
@Test public void shouldHandleExecutionEngineThrowingUndeclaredCheckedExceptions() throws Exception { // given QueryExecutionEngine executionEngine = mock( QueryExecutionEngine.class ); when( executionEngine.executeQuery( eq( "match (n) return n" ), eq( NO_PARAMS ), any( TransactionalContext.class ) ) ).thenAnswer( invocationOnMock -> { throw new Exception( "BOO" ); } ); TransactionRegistry registry = mock( TransactionRegistry.class ); when( registry.begin( any( TransactionHandle.class ) ) ).thenReturn( 1337L ); GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); TransactionHandle handle = new TransactionHandle( mockKernel(), executionEngine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance() ); ExecutionResultSerializer output = mock( ExecutionResultSerializer.class ); // when Statement statement = new Statement( "match (n) return n", map(), false, (ResultDataContent[]) null ); handle.commit( statements( statement ), output, mock( HttpServletRequest.class ) ); // then verify( registry ).forget( 1337L ); InOrder outputOrder = inOrder( output ); outputOrder.verify( output ).statementResult( isNull(), eq( false ), isNull() ); outputOrder.verify( output ).errors( argThat( hasErrors( Status.Statement.ExecutionFailed ) ) ); outputOrder.verify( output ).finish(); verifyNoMoreInteractions( output ); }
@Test public void shouldFlipToFailedUsingFailedIndexProxyFactory() throws Exception { // Given FailedIndexProxyFactory failureDelegateFactory = mock( FailedIndexProxyFactory.class ); IndexPopulator populator = spy( indexPopulator( false ) ); IndexPopulationJob job = newIndexPopulationJob( failureDelegateFactory, populator, new FlippableIndexProxy(), indexStoreView, NullLogProvider.getInstance(), EntityType.NODE, indexDescriptor( FIRST, name, false ) ); IllegalStateException failure = new IllegalStateException( "not successful" ); doThrow( failure ).when( populator ).close( true ); // When job.run(); // Then verify( failureDelegateFactory ).create( any( Throwable.class ) ); }
@Test @SuppressWarnings( "unchecked" ) public void deadlockExceptionHasCorrectStatus() throws Exception { // given QueryExecutionEngine executionEngine = mock( QueryExecutionEngine.class ); when( executionEngine.executeQuery( anyString(), any( MapValue.class ), isNull() ) ) .thenThrow( new DeadlockDetectedException( "deadlock" ) ); GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); TransactionHandle handle = new TransactionHandle( mockKernel(), executionEngine, queryService, mock( TransactionRegistry.class ), uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance() ); ExecutionResultSerializer output = mock( ExecutionResultSerializer.class ); // when handle.execute( statements( new Statement( "query", map(), false, (ResultDataContent[]) null ) ), output, mock( HttpServletRequest.class ) ); // then verify( output ).errors( argThat( hasErrors( Status.Transaction.DeadlockDetected ) ) ); }
@Test public void startTransactionWithRequestedTimeout() { QueryExecutionEngine executionEngine = mock( QueryExecutionEngine.class ); GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); ExecutionResultSerializer output = mock( ExecutionResultSerializer.class ); TransitionalPeriodTransactionMessContainer txManagerFacade = mockKernel(); TransactionHandle handle = new TransactionHandle( txManagerFacade, executionEngine, queryService, mock( TransactionRegistry.class ), uriScheme, true, AUTH_DISABLED, 100, NullLogProvider.getInstance() ); handle.commit( statements( new Statement( "query", map(), false, (ResultDataContent[]) null ) ), output, mock( HttpServletRequest.class ) ); verify( txManagerFacade ).newTransaction( Type.implicit, AUTH_DISABLED, 100 ); }
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" ) );
private static SocketTransport newSocketTransport( NetworkConnectionTracker connectionTracker, TransportThrottleGroup throttleGroup ) { return new SocketTransport( "bolt", new ListenSocketAddress( "localhost", 7687 ), null, false, NullLogProvider.getInstance(), throttleGroup, mock( BoltProtocolFactory.class ), connectionTracker ); } }
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 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() ); } }
@Test public void shouldApplyBatchesInParallel() throws Exception { // given setProperty( BATCH_SIZE_NAME, 2 ); EntityUpdates[] updates = new EntityUpdates[9]; for ( int i = 0; i < updates.length; i++ ) { updates[i] = nodeUpdates( i, propertyId, String.valueOf( i ), labelId ); } IndexStoreView storeView = newStoreView( updates ); ExecutorService executor = sameThreadExecutor(); BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator( storeView, executor, NullLogProvider.getInstance(), mock( SchemaState.class ) ); addPopulator( batchingPopulator, index1 ); // when batchingPopulator.indexAllEntities().run(); // then verify( executor, atLeast( 5 ) ).execute( any( Runnable.class ) ); }
@Before public void setUp() { fs = mock( FileSystemAbstraction.class ); logFiles = mock( LogFiles.class ); doAnswer( inv -> new File( String.valueOf( inv.getArguments()[0] ) ) ) .when( logFiles ).getLogFileForVersion( anyLong() ); logProvider = NullLogProvider.getInstance(); clock = mock( Clock.class ); factory = mock( LogPruneStrategyFactory.class ); }
private TransactionHandle getTransactionHandle( TransitionalPeriodTransactionMessContainer kernel, QueryExecutionEngine executionEngine, TransactionRegistry registry ) { GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class ); return new TransactionHandle( kernel, executionEngine, queryService, registry, uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance() ); }
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 shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception { // given long txId = 1; DatabaseLayout databaseLayout = directory.databaseLayout(); File neoStore = databaseLayout.metadataStore(); neoStore.createNewFile(); Config config = mock( Config.class ); LogService logService = new SimpleLogService( NullLogProvider.getInstance(), NullLogProvider.getInstance() ); // when // ... transaction info not in neo store assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_ID ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_CHECKSUM ) ); assertEquals( FIELD_NOT_PRESENT, getRecord( pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP ) ); // ... and with migrator StoreMigrator migrator = new StoreMigrator( fileSystemRule.get(), pageCache, config, logService, jobScheduler ); TransactionId actual = migrator.extractTransactionIdInformation( neoStore, txId ); // then assertEquals( txId, actual.transactionId() ); assertEquals( TransactionIdStore.BASE_TX_CHECKSUM, actual.checksum() ); assertEquals( TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP, actual.commitTimestamp() ); }
@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(); }
@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 shouldRemoveIndexCountsWhenTheIndexItselfIsDropped() throws IOException { // given String userDescription = "description"; FailedIndexProxy index = new FailedIndexProxy( forSchema( forLabel( 1, 2 ), IndexProviderDescriptor.UNDECIDED ).withId( 1 ).withoutCapabilities(), userDescription, indexPopulator, indexPopulationFailure, indexCountsRemover, NullLogProvider.getInstance() ); // when index.drop(); // then verify( indexPopulator ).drop(); verify( indexCountsRemover ).remove(); verifyNoMoreInteractions( indexPopulator, indexCountsRemover ); }
LogProvider logProvider = NullLogProvider.getInstance(); StoreFactory storeFactory = new StoreFactory( testDirectory.databaseLayout(), Config.defaults(), new DefaultIdGeneratorFactory( fs.get() ), pageCache.getPageCache( fs.get() ), fs.get(), logProvider, EmptyVersionContextSupplier.EMPTY ); try ( NeoStores stores = storeFactory.openNeoStores( true, StoreType.RELATIONSHIP_GROUP ) ) RecordStore<RelationshipGroupRecord> store = spy( stores.getRelationshipGroupStore() ); InOrder verification = inOrder( store ); verification.verify( store ).getRecord( eq( group2.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group4.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store ).getRecord( eq( group10.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) ); verification.verify( store, never() ) .getRecord( eq( group23.getId() ), any( RelationshipGroupRecord.class ), any( RecordLoad.class ) );