Search in sources :

Example 36 with AssertableLogProvider

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

the class FileRoleRepositoryTest method shouldFailOnReadingInvalidEntries.

@Test
public void shouldFailOnReadingInvalidEntries() throws Throwable {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    fs.mkdirs(roleFile.getParentFile());
    // First line is correctly formatted, second line has an extra field
    FileRepositorySerializer.writeToFile(fs, roleFile, UTF8.encode("neo4j:admin\n" + "admin:admin:\n"));
    // When
    roleRepository = new FileRoleRepository(fs, roleFile, logProvider);
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage(startsWith("Failed to read role file '"));
    try {
        roleRepository.start();
    }// Then
     catch (IllegalStateException e) {
        assertThat(roleRepository.numberOfRoles(), equalTo(0));
        logProvider.assertExactly(AssertableLogProvider.inLog(FileRoleRepository.class).error("Failed to read role file \"%s\" (%s)", roleFile.getAbsolutePath(), "wrong number of line fields [line 2]"));
        throw e;
    }
}
Also used : AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 37 with AssertableLogProvider

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

the class MultiRealmAuthManagerTest method setUp.

@Before
public void setUp() throws Throwable {
    config = Config.defaults();
    users = CommunitySecurityModule.getUserRepository(config, NullLogProvider.getInstance(), fsRule.get());
    authStrategy = mock(AuthenticationStrategy.class);
    logProvider = new AssertableLogProvider();
    manager = createAuthManager(true);
    userManager = manager.getUserManager();
}
Also used : AuthenticationStrategy(org.neo4j.server.security.auth.AuthenticationStrategy) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Before(org.junit.Before)

Example 38 with AssertableLogProvider

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

the class AsyncLogTest method shouldLogAsynchronously.

@Test
public void shouldLogAsynchronously() throws Exception {
    // 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));
    // then
    logging.assertNoLoggingOccurred();
    // when
    events.process();
    // then
    MatcherBuilder matcherBuilder = new MatcherBuilder(inLog(getClass()));
    log(matcherBuilder);
    logging.assertExactly(matcherBuilder.matcher());
}
Also used : Log(org.neo4j.logging.Log) AssertableLogProvider.inLog(org.neo4j.logging.AssertableLogProvider.inLog) AbstractLog(org.neo4j.logging.AbstractLog) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 39 with AssertableLogProvider

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

the class UserFunctionIT method shouldLogLikeThereIsNoTomorrow.

@Test
public void shouldLogLikeThereIsNoTomorrow() throws Throwable {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    db.shutdown();
    db = new TestGraphDatabaseFactory().setInternalLogProvider(logProvider).setUserLogProvider(logProvider).newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.plugin_dir, plugins.getRoot().getAbsolutePath()).newGraphDatabase();
    // When
    try (Transaction ignore = db.beginTx()) {
        Result res = db.execute("RETURN org.neo4j.procedure.logAround()");
        while (res.hasNext()) {
            res.next();
        }
    }
    // Then
    AssertableLogProvider.LogMatcherBuilder match = inLog(Procedures.class);
    logProvider.assertAtLeastOnce(match.debug("1"), match.info("2"), match.warn("3"), match.error("4"));
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 40 with AssertableLogProvider

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

the class NeoServerPortConflictDocIT method shouldComplainIfServerPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException, InterruptedException {
    ListenSocketAddress contestedAddress = new ListenSocketAddress("localhost", 9999);
    try (ServerSocket ignored = new ServerSocket(contestedAddress.getPort(), 0, InetAddress.getByName(contestedAddress.getHostname()))) {
        AssertableLogProvider logProvider = new AssertableLogProvider();
        CommunityNeoServer server = CommunityServerBuilder.server(logProvider).onAddress(contestedAddress).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
        try {
            server.start();
            fail("Should have reported failure to start");
        } catch (ServerStartupException e) {
            assertThat(e.getMessage(), containsString("Starting Neo4j failed"));
        }
        logProvider.assertAtLeastOnce(AssertableLogProvider.inLog(containsString("CommunityNeoServer")).error("Failed to start Neo4j on %s: %s", contestedAddress, format("Address %s is already in use, cannot bind to it.", contestedAddress)));
        server.stop();
    }
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) ServerStartupException(org.neo4j.server.ServerStartupException) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) 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