Skip to content

Commit

Permalink
Update availability logging messages,tests. Fix failing bolt test.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 24, 2018
1 parent ea07d72 commit 6be59a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Expand Up @@ -31,7 +31,6 @@
import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.availability.AvailabilityGuard;
import org.neo4j.kernel.availability.DatabaseAvailabilityGuard;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.query.QueryExecutionEngine;
Expand Down Expand Up @@ -124,14 +123,15 @@ private static TransactionStateMachineV1SPI createTxSpi( Supplier<TransactionIdS
}

private static TransactionStateMachineV1SPI createTxSpi( Supplier<TransactionIdStore> txIdStore, Duration txAwaitDuration,
AvailabilityGuard availabilityGuard, Clock clock )
DatabaseAvailabilityGuard availabilityGuard, Clock clock )
{
QueryExecutionEngine queryExecutionEngine = mock( QueryExecutionEngine.class );

DependencyResolver dependencyResolver = mock( DependencyResolver.class );
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge( availabilityGuard );
when( dependencyResolver.resolveDependency( ThreadToStatementContextBridge.class ) ).thenReturn( bridge );
when( dependencyResolver.resolveDependency( QueryExecutionEngine.class ) ).thenReturn( queryExecutionEngine );
when( dependencyResolver.resolveDependency( DatabaseAvailabilityGuard.class ) ).thenReturn( availabilityGuard );
when( dependencyResolver.provideDependency( TransactionIdStore.class ) ).thenReturn( txIdStore );

GraphDatabaseAPI db = mock( GraphDatabaseAPI.class );
Expand Down
Expand Up @@ -58,8 +58,8 @@ public void shouldWriteToInternalDiagnosticsLog() throws Exception
assertThat( internalLog.isFile(), is( true ) );
assertThat( internalLog.length(), greaterThan( 0L ) );

assertEquals( 1, countOccurrences( internalLog, "Database is now ready" ) );
assertEquals( 1, countOccurrences( internalLog, "Database is now unavailable" ) );
assertEquals( 1, countOccurrences( internalLog, "Database graph.db is ready." ) );
assertEquals( 2, countOccurrences( internalLog, "Database graph.db is unavailable." ) );
}

@Test
Expand Down
Expand Up @@ -37,8 +37,8 @@
*/
public class DatabaseAvailabilityGuard implements AvailabilityGuard
{
private static final String DATABASE_AVAILABLE_MSG = "Fulfilling of requirement makes database %s available: %s.";
private static final String DATABASE_UNAVAILABLE_MSG = "Requirement makes database %s unavailable: %s.";
private static final String DATABASE_AVAILABLE_MSG = "Fulfilling of requirement '%s' makes database %s available.";
private static final String DATABASE_UNAVAILABLE_MSG = "Requirement `%s` makes database %s unavailable.";

private final AtomicInteger requirementCount = new AtomicInteger( 0 );
private final Set<AvailabilityRequirement> blockingRequirements = new CopyOnWriteArraySet<>();
Expand Down Expand Up @@ -68,7 +68,7 @@ public void require( AvailabilityRequirement requirement )
{
if ( requirementCount.getAndIncrement() == 0 && !isShutdown.get() )
{
log.info( DATABASE_UNAVAILABLE_MSG, databaseName, requirement.description() );
log.info( DATABASE_UNAVAILABLE_MSG, requirement.description(), databaseName );
listeners.notify( AvailabilityListener::unavailable );
}
}
Expand All @@ -86,7 +86,7 @@ public void fulfill( AvailabilityRequirement requirement )
{
if ( requirementCount.getAndDecrement() == 1 && !isShutdown.get() )
{
log.info( DATABASE_AVAILABLE_MSG, databaseName, requirement.description() );
log.info( DATABASE_AVAILABLE_MSG, requirement.description(), databaseName );
listeners.notify( AvailabilityListener::available );
}
}
Expand Down Expand Up @@ -241,13 +241,13 @@ private static class LoggingAvailabilityListener implements AvailabilityListener
@Override
public void available()
{
log.info( "Database %s is now ready.", databaseName );
log.info( "Database %s is ready.", databaseName );
}

@Override
public void unavailable()
{
log.info( "Database %s is now unavailable.", databaseName );
log.info( "Database %s is unavailable.", databaseName );
}
}
}

0 comments on commit 6be59a6

Please sign in to comment.