Search in sources :

Example 1 with AssertableLogProvider

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

the class NeoStoreDataSourceTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsInOldestLog.

@Test
public void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInOldestLog() throws Exception {
    // GIVEN
    long logVersion = 2, prevLogLastTxId = 45;
    NeoStoreDataSource dataSource = neoStoreDataSourceWithLogFilesContainingLowestTxId(logWithTransactions(logVersion, prevLogLastTxId));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Logger logger = logProvider.getLog(getClass()).infoLogger();
    // WHEN
    Diagnostics.TRANSACTION_RANGE.dump(dataSource, logger);
    // THEN
    logProvider.assertContainsMessageContaining("transaction " + (prevLogLastTxId + 1));
    logProvider.assertContainsMessageContaining("version " + logVersion);
}
Also used : Logger(org.neo4j.logging.Logger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 2 with AssertableLogProvider

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

the class NeoStoreDataSourceTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsInSecondOldestLog.

@Test
public void shouldLogCorrectTransactionLogDiagnosticsForTransactionsInSecondOldestLog() throws Exception {
    // GIVEN
    long logVersion = 2, prevLogLastTxId = 45;
    NeoStoreDataSource dataSource = neoStoreDataSourceWithLogFilesContainingLowestTxId(logWithTransactionsInNextToOldestLog(logVersion, prevLogLastTxId));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Logger logger = logProvider.getLog(getClass()).infoLogger();
    // WHEN
    Diagnostics.TRANSACTION_RANGE.dump(dataSource, logger);
    // THEN
    logProvider.assertContainsMessageContaining("transaction " + (prevLogLastTxId + 1));
    logProvider.assertContainsMessageContaining("version " + (logVersion + 1));
}
Also used : Logger(org.neo4j.logging.Logger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 3 with AssertableLogProvider

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

the class NeoStoreDataSourceTest method shouldLogCorrectTransactionLogDiagnosticsForNoTransactionLogs.

@Test
public void shouldLogCorrectTransactionLogDiagnosticsForNoTransactionLogs() throws Exception {
    // GIVEN
    NeoStoreDataSource dataSource = neoStoreDataSourceWithLogFilesContainingLowestTxId(noLogs());
    AssertableLogProvider logProvider = new AssertableLogProvider();
    Logger logger = logProvider.getLog(getClass()).infoLogger();
    // WHEN
    Diagnostics.TRANSACTION_RANGE.dump(dataSource, logger);
    // THEN
    logProvider.assertContainsMessageContaining("No transactions");
}
Also used : Logger(org.neo4j.logging.Logger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 4 with AssertableLogProvider

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

the class SlaveLocksClientTest method setUp.

@Before
public void setUp() throws Exception {
    master = mock(Master.class);
    availabilityGuard = new AvailabilityGuard(Clocks.fakeClock(), getInstance());
    lockManager = new CommunityLockManger(Config.defaults(), Clocks.systemClock());
    local = spy(lockManager.newClient());
    logProvider = new AssertableLogProvider();
    LockResult lockResultOk = new LockResult(LockStatus.OK_LOCKED);
    TransactionStreamResponse<LockResult> responseOk = new TransactionStreamResponse<>(lockResultOk, null, TransactionStream.EMPTY, ResourceReleaser.NO_OP);
    whenMasterAcquireShared().thenReturn(responseOk);
    whenMasterAcquireExclusive().thenReturn(responseOk);
    client = new SlaveLocksClient(master, local, lockManager, mock(RequestContextFactory.class), availabilityGuard, logProvider);
}
Also used : Master(org.neo4j.kernel.ha.com.master.Master) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) CommunityLockManger(org.neo4j.kernel.impl.locking.community.CommunityLockManger) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Before(org.junit.Before)

Example 5 with AssertableLogProvider

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

the class HighAvailabilityModeSwitcherTest method shouldTakeNoActionIfSwitchingToSlaveForItselfAsMaster.

@Test
public void shouldTakeNoActionIfSwitchingToSlaveForItselfAsMaster() throws Throwable {
    // Given
    // A HAMS
    SwitchToSlaveCopyThenBranch switchToSlave = mock(SwitchToSlaveCopyThenBranch.class);
    AssertableLogProvider logProvider = new AssertableLogProvider();
    SimpleLogService logService = new SimpleLogService(NullLogProvider.getInstance(), logProvider);
    HighAvailabilityModeSwitcher toTest = new HighAvailabilityModeSwitcher(switchToSlave, mock(SwitchToMaster.class), mock(Election.class), mock(ClusterMemberAvailability.class), mock(ClusterClient.class), storeSupplierMock(), new InstanceId(2), new ComponentSwitcherContainer(), neoStoreDataSourceSupplierMock(), logService);
    // That is properly started
    toTest.init();
    toTest.start();
    /*
         * This is the URI at which we are registered as server - includes our own id, but we don't necessarily listen
         * there
         */
    URI serverHaUri = URI.create("ha://server2?serverId=2");
    toTest.listeningAt(serverHaUri);
    // When
    // The HAMS tries to switch to slave for a master that is itself
    toTest.masterIsAvailable(new HighAvailabilityMemberChangeEvent(PENDING, TO_SLAVE, new InstanceId(2), serverHaUri));
    // Then
    // No switching to slave must happen
    verifyZeroInteractions(switchToSlave);
    // And an error must be logged
    logProvider.assertAtLeastOnce(inLog(HighAvailabilityModeSwitcher.class).error("I (ha://server2?serverId=2) tried to switch to " + "slave for myself as master (ha://server2?serverId=2)"));
}
Also used : ClusterClient(org.neo4j.cluster.client.ClusterClient) SwitchToSlaveCopyThenBranch(org.neo4j.kernel.ha.cluster.SwitchToSlaveCopyThenBranch) SimpleLogService(org.neo4j.kernel.impl.logging.SimpleLogService) InstanceId(org.neo4j.cluster.InstanceId) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) ClusterMemberAvailability(org.neo4j.cluster.member.ClusterMemberAvailability) SwitchToMaster(org.neo4j.kernel.ha.cluster.SwitchToMaster) Election(org.neo4j.cluster.protocol.election.Election) URI(java.net.URI) 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