Search in sources :

Example 21 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class NeoServerShutdownLoggingIT method setupServer.

@Before
public void setupServer() throws IOException {
    logProvider = new AssertableLogProvider();
    server = ServerHelper.createNonPersistentServer(logProvider);
    ServerHelper.cleanTheDatabase(server);
}
Also used : AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Before(org.junit.Before)

Example 22 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class TruncateLogCommandTest method applyTo.

@Test
public void applyTo() throws Exception {
    //Test that truncate commands correctly remove entries from the cache.
    //given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log log = logProvider.getLog(getClass());
    long fromIndex = 2L;
    TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
    InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
    inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
    inFlightMap.put(1L, new RaftLogEntry(1L, valueOf(1)));
    inFlightMap.put(2L, new RaftLogEntry(2L, valueOf(2)));
    inFlightMap.put(3L, new RaftLogEntry(3L, valueOf(3)));
    //when
    truncateLogCommand.applyTo(inFlightMap, log);
    //then
    assertNotNull(inFlightMap.get(0L));
    assertNotNull(inFlightMap.get(1L));
    assertNull(inFlightMap.get(2L));
    assertNull(inFlightMap.get(3L));
    logProvider.assertAtLeastOnce(inLog(getClass()).debug("Start truncating in-flight-map from index %d. Current map:%n%s", fromIndex, inFlightMap));
}
Also used : Log(org.neo4j.logging.Log) AssertableLogProvider.inLog(org.neo4j.logging.AssertableLogProvider.inLog) NullLog(org.neo4j.logging.NullLog) InFlightMap(org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 23 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class HeartbeatStateTest method shouldLogFirstHeartbeatAfterTimeout.

@Test
public void shouldLogFirstHeartbeatAfterTimeout() throws Throwable {
    // given
    InstanceId instanceId = new InstanceId(1), otherInstance = new InstanceId(2);
    ClusterConfiguration configuration = new ClusterConfiguration("whatever", NullLogProvider.getInstance(), "cluster://1", "cluster://2");
    configuration.getMembers().put(otherInstance, URI.create("cluster://2"));
    AssertableLogProvider internalLog = new AssertableLogProvider(true);
    TimeoutStrategy timeoutStrategy = mock(TimeoutStrategy.class);
    Timeouts timeouts = new Timeouts(timeoutStrategy);
    Config config = mock(Config.class);
    when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
    MultiPaxosContext context = new MultiPaxosContext(instanceId, iterable(new ElectionRole("coordinator")), configuration, mock(Executor.class), internalLog, mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), timeouts, mock(ElectionCredentialsProvider.class), config);
    StateMachines stateMachines = new StateMachines(internalLog, mock(StateMachines.Monitor.class), mock(MessageSource.class), mock(MessageSender.class), timeouts, mock(DelayedDirectExecutor.class), command -> command.run(), instanceId);
    stateMachines.addStateMachine(new StateMachine(context.getHeartbeatContext(), HeartbeatMessage.class, HeartbeatState.start, internalLog));
    timeouts.tick(0);
    when(timeoutStrategy.timeoutFor(any(Message.class))).thenReturn(5L);
    // when
    stateMachines.process(Message.internal(HeartbeatMessage.join));
    stateMachines.process(Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.CREATED_BY, otherInstance.toString()));
    for (int i = 1; i <= 15; i++) {
        timeouts.tick(i);
    }
    // then
    verify(timeoutStrategy, times(3)).timeoutTriggered(argThat(new MessageArgumentMatcher<>().onMessageType(HeartbeatMessage.timed_out)));
    internalLog.assertExactly(inLog(HeartbeatState.class).debug("Received timed out for server 2"), inLog(HeartbeatContext.class).info("1(me) is now suspecting 2"), inLog(HeartbeatState.class).debug("Received timed out for server 2"), inLog(HeartbeatState.class).debug("Received timed out for server 2"));
    internalLog.clear();
    // when
    stateMachines.process(Message.internal(HeartbeatMessage.i_am_alive, new HeartbeatMessage.IAmAliveState(otherInstance)).setHeader(Message.CREATED_BY, otherInstance.toString()));
    // then
    internalLog.assertExactly(inLog(HeartbeatState.class).debug("Received i_am_alive[2] after missing 3 (15ms)"));
}
Also used : LearnerMessage(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.LearnerMessage) Message(org.neo4j.cluster.com.message.Message) InstanceId(org.neo4j.cluster.InstanceId) Timeouts(org.neo4j.cluster.timeout.Timeouts) Config(org.neo4j.kernel.configuration.Config) MessageSender(org.neo4j.cluster.com.message.MessageSender) StateMachine(org.neo4j.cluster.statemachine.StateMachine) StateMachines(org.neo4j.cluster.StateMachines) TimeoutStrategy(org.neo4j.cluster.timeout.TimeoutStrategy) MessageSource(org.neo4j.cluster.com.message.MessageSource) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) Executor(java.util.concurrent.Executor) DelayedDirectExecutor(org.neo4j.cluster.DelayedDirectExecutor) ElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ElectionCredentialsProvider) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ObjectInputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory) ObjectOutputStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory) AcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 24 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ConfiguringPageCacheFactoryTest method mustUseAndLogConfiguredPageSwapper.

@Test
public void mustUseAndLogConfiguredPageSwapper() throws Exception {
    // Given
    Config config = Config.embeddedDefaults(stringMap(pagecache_memory.name(), "8m", pagecache_swapper.name(), TEST_PAGESWAPPER_NAME));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Log log = logProvider.getLog(PageCache.class);
    // When
    new ConfiguringPageCacheFactory(fsRule.get(), config, PageCacheTracer.NULL, PageCursorTracerSupplier.NULL, log);
    // Then
    assertThat(PageSwapperFactoryForTesting.countCreatedPageSwapperFactories(), is(1));
    assertThat(PageSwapperFactoryForTesting.countConfiguredPageSwapperFactories(), is(1));
    logProvider.assertContainsMessageContaining(TEST_PAGESWAPPER_NAME);
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 25 with AssertableLogProvider

use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.

the class ServerStartupErrorsTest method shouldDescribeUpgradeFailureInAFriendlyWay.

@Test
public void shouldDescribeUpgradeFailureInAFriendlyWay() {
    // given
    AssertableLogProvider logging = new AssertableLogProvider();
    LifecycleException error = new LifecycleException(new Object(), STARTING, STARTED, new RuntimeException("Error starting org.neo4j.kernel.ha.factory.EnterpriseFacadeFactory", new LifecycleException(new Object(), STARTING, STARTED, new LifecycleException(new Object(), STARTING, STARTED, new UpgradeNotAllowedByConfigurationException()))));
    // when
    translateToServerStartupError(error).describeTo(logging.getLog("console"));
    // then
    logging.assertExactly(inLog("console").error("Neo4j cannot be started, because the database files require upgrading and upgrades are " + "disabled in configuration. Please set '%s' to 'true' in your configuration file and try " + "again.", "dbms.allow_format_migration"));
}
Also used : UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)202 Test (org.junit.jupiter.api.Test)98 Test (org.junit.Test)63 Path (java.nio.file.Path)29 Log (org.neo4j.logging.Log)24 FakeClock (org.neo4j.time.FakeClock)20 SslPolicyConfig (org.neo4j.configuration.ssl.SslPolicyConfig)14 IOException (java.io.IOException)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 DynamicTest (org.junit.jupiter.api.DynamicTest)12 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)12 SocketAddress (org.neo4j.configuration.helpers.SocketAddress)11 NullLog (org.neo4j.logging.NullLog)11 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ServerSocket (java.net.ServerSocket)8 Before (org.junit.Before)8