private String serialize( Iterator<LogCall> events ) { return serialize( events, LogCall::toString ); }
public String serialize() { return serialize( logCalls.iterator(), LogCall::toLogLikeString ); }
@Override public void describeTo( Description description ) { description.appendText( " expected log message: '" ).appendText( CREATION_FINISHED ) .appendText( "', but not found. Messages was: '" ).appendText( logProvider.serialize() ).appendText( "." ); } }
public void assertNoLoggingOccurred() { if ( logCalls.size() != 0 ) { fail( format( "Expected no log messages at all, but got:\n%s", serialize( logCalls.iterator() ) ) ); } }
public void assertContainsLogCallContaining( String partOfMessage ) { if ( !containsLogCallContaining( partOfMessage ) ) { fail( format( "Expected at least one log statement containing '%s', but none found. Actual log calls were:\n%s", partOfMessage, serialize( logCalls.iterator() ) ) ); } }
public void assertNoLogCallContaining( String partOfMessage ) { if ( containsLogCallContaining( partOfMessage ) ) { fail( format( "Expected no log statement containing '%s', but at least one found. Actual log calls were:\n%s", partOfMessage, serialize( logCalls.iterator() ) ) ); } }
public void assertContainsMessageContaining( String partOfMessage ) { synchronized ( logCalls ) { if ( containsMessage( partOfMessage ) ) { return; } fail( format( "Expected at least one log statement containing '%s', but none found. Actual log calls were:\n%s", partOfMessage, serialize( logCalls.iterator() ) ) ); } }
public void assertNoMessagesContaining( String partOfMessage ) { synchronized ( logCalls ) { if ( containsMessage( partOfMessage ) ) { fail( format( "Expected at least one log statement containing '%s', but none found. Actual log calls were:\n%s", partOfMessage, serialize( logCalls.iterator() ) ) ); } } }
public void assertLogStringContains( String partOfMessage ) { synchronized ( logCalls ) { for ( LogCall logCall : logCalls ) { if ( logCall.toLogLikeString().contains( partOfMessage ) ) { return; } } } fail( format( "Expected at least one log strings containing '%s', but none found. Actual log calls were:\n%s", partOfMessage, serialize( logCalls.iterator() ) ) ); }
/** * Note: Does not care about ordering. */ public void assertAtLeastOnce( LogMatcher... expected ) { Set<LogMatcher> expectedMatchers = Iterators.asSet( expected ); synchronized ( logCalls ) { expectedMatchers.removeIf( this::containsMatchingLogCall ); if ( expectedMatchers.size() > 0 ) { fail( format( "These log calls were expected, but never occurred:\n%s\nActual log calls were:\n%s", describe( expectedMatchers.iterator() ), serialize( logCalls.iterator() ) ) ); } } }
public void assertExactly( LogMatcher... expected ) { Iterator<LogMatcher> expectedIterator = asList( expected ).iterator(); synchronized ( logCalls ) { Iterator<LogCall> callsIterator = logCalls.iterator(); while ( expectedIterator.hasNext() ) { if ( callsIterator.hasNext() ) { LogMatcher logMatcher = expectedIterator.next(); LogCall logCall = callsIterator.next(); if ( !logMatcher.matches( logCall ) ) { fail( format( "Log call did not match expectation\n Expected: %s\n Call was: %s", logMatcher, logCall ) ); } } else { fail( format( "Got fewer log calls than expected. The missing log calls were:\n%s", describe( expectedIterator ) ) ); } } if ( callsIterator.hasNext() ) { fail( format( "Got more log calls than expected. The remaining log calls were:\n%s", serialize( callsIterator ) ) ); } } }
public void assertContainsMessageMatching( Matcher<String> messageMatcher ) { synchronized ( logCalls ) { for ( LogCall logCall : logCalls ) { if ( messageMatcher.matches( logCall.message ) ) { return; } } StringDescription description = new StringDescription(); description.appendDescriptionOf( messageMatcher ); fail( format( "Expected at least one log statement with message as %s, but none found. Actual log calls were:\n%s", description.toString(), serialize( logCalls.iterator() ) ) ); } }
description.appendDescriptionOf( messageMatcher ); fail( format( "Expected exactly one log statement with message as %s, but multiple found. Actual log calls were:%n%s", description.toString(), serialize( logCalls.iterator() ) ) ); fail( format( "Expected at least one log statement with message as %s, but none found. Actual log calls were:\n%s", description.toString(), serialize( logCalls.iterator() ) ) );
@Test public void shouldFailIfWrongCredentials() throws Throwable { // When connection.connect( address ) .send( util.defaultAcceptedVersions() ) .send( util.chunk( new InitMessage( "TestClient/1.1", map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) ); // Then assertThat( connection, util.eventuallyReceivesSelectedProtocolVersion() ); assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized, "The client is unauthorized due to authentication failure." ) ) ); assertThat( connection, eventuallyDisconnects() ); assertEventually( ignore -> "Matching log call not found in\n" + logProvider.serialize(), this::authFailureLoggedToUserLog, is( true ), 30, SECONDS ); }
public static void assertConsistentStore( DatabaseLayout databaseLayout ) throws ConsistencyCheckIncompleteException { Config configuration = Config.defaults( GraphDatabaseSettings.pagecache_memory, "8m" ); AssertableLogProvider logger = new AssertableLogProvider(); ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck( databaseLayout, configuration, ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), false ); assertTrue( "Consistency check for " + databaseLayout + " found inconsistencies:\n\n" + logger.serialize(), result.isSuccessful() ); } }