private void assertNoWarning() { logProvider.assertNoLoggingOccurred(); }
@Test public void retrieveCustomTransactionTimeout() { when( request.getHeader( MAX_EXECUTION_TIME_HEADER ) ).thenReturn( "100" ); Log log = logProvider.getLog( HttpServletRequest.class ); long transactionTimeout = getTransactionTimeout( request, log ); assertEquals( "Transaction timeout should be retrieved.", 100, transactionTimeout ); logProvider.assertNoLoggingOccurred(); }
@Test public void startTransactionWithCustomTimeout() { when( request.getHeader( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER ) ) .thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED, CUSTOM_TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS ); logProvider.assertNoLoggingOccurred(); }
@Test public void startDefaultTransactionIfTimeoutIsNegative() { when( request.getHeader( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER ) ) .thenReturn( "-2" ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); logProvider.assertNoLoggingOccurred(); }
@Test public void defaultValueWhenCustomTransactionTimeoutNotSpecified() { Log log = logProvider.getLog( HttpServletRequest.class ); long transactionTimeout = getTransactionTimeout( request, log ); assertEquals( "Transaction timeout not specified.", 0, transactionTimeout ); logProvider.assertNoLoggingOccurred(); }
@Test public void shouldNotLogQueries() { // when database.execute( "CREATE (n:Reference) CREATE (foo {test:'me'}) RETURN n" ); database.execute( "MATCH (n) RETURN n" ); // then inLog( org.neo4j.cypher.internal.ExecutionEngine.class ); logProvider.assertNoLoggingOccurred(); } }
@Test public void noMessagesWhenThereIsNoIndexes() { IndexMapReference indexMapReference = new IndexMapReference(); IndexingService indexingService = createIndexServiceWithCustomIndexMap( indexMapReference ); indexingService.start(); internalLogProvider.assertNoLoggingOccurred(); }
@Test public void testNoMigration() { assertThat( migrator.apply( stringMap( "foo", "bar" ), NullLog.getInstance() ), equalTo( stringMap( "foo", "bar" ) ) ); logProvider.assertNoLoggingOccurred(); }
@Test public void startDefaultTransaction() { CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider ); cypherExecutor.start(); cypherExecutor.createTransactionContext( QUERY, VirtualValues.emptyMap(), request ); verify( databaseQueryService ).beginTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); logProvider.assertNoLoggingOccurred(); }
@Test public void noNotificationForTransactionLogs() { AssertableLogProvider internalLogProvider = new AssertableLogProvider( false ); DefaultFileDeletionEventListener listener = buildListener( internalLogProvider ); listener.fileDeleted( TransactionLogFiles.DEFAULT_NAME + ".0" ); listener.fileDeleted( TransactionLogFiles.DEFAULT_NAME + ".1" ); internalLogProvider.assertNoLoggingOccurred(); }
@Test public void onlyDatabaseErrorsAreLogged() { AssertableLogProvider userLog = new AssertableLogProvider(); AssertableLogProvider internalLog = new AssertableLogProvider(); ErrorReporter reporter = newErrorReporter( userLog, internalLog ); for ( Status.Classification classification : Status.Classification.values() ) { if ( classification != Status.Classification.DatabaseError ) { Status.Code code = newStatusCode( classification ); Neo4jError error = Neo4jError.from( () -> code, "Database error" ); reporter.report( error ); userLog.assertNoLoggingOccurred(); internalLog.assertNoLoggingOccurred(); } } }
@Test public void shouldGenerateTransactionId() { // given AssertableLogProvider logProvider = new AssertableLogProvider(); TransactionHandleRegistry registry = new TransactionHandleRegistry( Clocks.fakeClock(), 0, logProvider ); TransactionHandle handle = mock( TransactionHandle.class ); // when long id1 = registry.begin( handle ); long id2 = registry.begin( handle ); // then assertNotEquals( id1, id2 ); logProvider.assertNoLoggingOccurred(); }
@Test public void skipMigrationOfTransactionTimeoutIfNotPresent() { Map<String,String> migratedProperties = migrator.apply( stringMap( "dbms.rest.transaction.idle_timeout", "120s" ), getLog() ); assertEquals( "Nothing to migrate", migratedProperties, stringMap( "dbms.rest.transaction.idle_timeout", "120s" )); logProvider.assertNoLoggingOccurred(); }
@Test public void skipMigrationOfIndexSamplingBufferSizeIfNotPresent() { Map<String,String> resultConfig = migrator.apply( stringMap( "dbms.index_sampling.sample_size_limit", "8388600" ), getLog() ); assertEquals( "Nothing to migrate should be the same", resultConfig, stringMap( "dbms.index_sampling.sample_size_limit", "8388600" )); logProvider.assertNoLoggingOccurred(); }
@Test public void skipMigrationOfExecutionTimeLimitIfNotPresent() { Map<String,String> migratedProperties = migrator.apply( stringMap( "dbms.transaction.timeout", "120s" ), getLog() ); assertEquals( "Nothing to migrate", migratedProperties, stringMap( "dbms.transaction.timeout", "120s" )); logProvider.assertNoLoggingOccurred(); }
@Test public void skipMigrationOfTransactionEndTimeoutIfNotPresent() { Map<String,String> migratedProperties = migrator.apply( stringMap( "dbms.shutdown_transaction_end_timeout", "12s" ), getLog() ); assertEquals( "Nothing to migrate", migratedProperties, stringMap( "dbms.shutdown_transaction_end_timeout", "12s" )); logProvider.assertNoLoggingOccurred(); }
@Test public void shouldStoreSuspendedTransaction() throws Exception { // Given AssertableLogProvider logProvider = new AssertableLogProvider(); TransactionHandleRegistry registry = new TransactionHandleRegistry( Clocks.fakeClock(), 0, logProvider ); TransactionHandle handle = mock( TransactionHandle.class ); long id = registry.begin( handle ); // When registry.release( id, handle ); TransactionHandle acquiredHandle = registry.acquire( id ); // Then assertSame( handle, acquiredHandle ); logProvider.assertNoLoggingOccurred(); }
@Test public void acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId() throws Exception { // Given AssertableLogProvider logProvider = new AssertableLogProvider(); TransactionHandleRegistry registry = new TransactionHandleRegistry( Clocks.fakeClock(), 0, logProvider ); long madeUpTransactionId = 1337; // When try { registry.acquire( madeUpTransactionId ); fail( "Should have thrown exception" ); } catch ( InvalidTransactionId e ) { // expected } // then logProvider.assertNoLoggingOccurred(); }
@Test public void skipMigrationOfEnableNativeSchemaIndexIfNotPresent() { Map<String,String> migratedProperties = migrator.apply( stringMap( "dbms.index.default_schema_provider", NATIVE10.providerName() ), getLog() ); assertEquals( "Nothing to migrate", migratedProperties, stringMap( "dbms.index.default_schema_provider", NATIVE10.providerName() ) ); logProvider.assertNoLoggingOccurred(); }
@ParameterizedTest @MethodSource( "parameters" ) void shouldLogAsynchronously( Invocation invocation, Level level, Style style ) { // given AssertableLogProvider logging = new AssertableLogProvider(); Log log = logging.getLog( getClass() ); DeferredSender events = new DeferredSender(); AsyncLog asyncLog = new AsyncLog( events, log ); // when log( invocation.decorate( asyncLog ), level, style ); // then logging.assertNoLoggingOccurred(); // when events.process(); // then MatcherBuilder matcherBuilder = new MatcherBuilder( inLog( getClass() ) ); log( matcherBuilder, level, style ); logging.assertExactly( matcherBuilder.matcher() ); }