Search in sources :

Example 16 with AssertableLogProvider

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

the class StartClientIT method shouldNotStartBolt.

@Test
public void shouldNotStartBolt() throws IOException {
    // Given
    AssertableLogProvider log = new AssertableLogProvider();
    // When
    new StartClient(System.out, System.err) {

        @Override
        protected GraphDatabaseShellServer getGraphDatabaseShellServer(File path, boolean readOnly, String configFile) throws RemoteException {
            return new GraphDatabaseShellServer(new TestGraphDatabaseFactory().setUserLogProvider(log), path, readOnly, configFile);
        }
    }.start(new String[] { "-c", "RETURN 1;", "-path", db.getStoreDir(), "-config", getClass().getResource("/config-with-bolt-connector.conf").getFile() }, mock(CtrlCHandler.class));
    // Then
    log.assertNone(inLog(startsWith(WorkerFactory.class.getPackage().getName())).any());
}
Also used : GraphDatabaseShellServer(org.neo4j.shell.kernel.GraphDatabaseShellServer) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemoteException(java.rmi.RemoteException) File(java.io.File) WorkerFactory(org.neo4j.bolt.v1.runtime.WorkerFactory) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 17 with AssertableLogProvider

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

the class ConnectionInfoIT method hzTest.

@Test
public void hzTest() throws Throwable {
    // given
    testSocket = bindPort("0.0.0.0", 4243);
    //when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
    Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
    try {
        coreTopologyService.init();
        coreTopologyService.start();
    }//then
     catch (Throwable throwable) {
    //expected
    }
    logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
    userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) MemberId(org.neo4j.causalclustering.identity.MemberId) HttpConnector(org.neo4j.kernel.configuration.HttpConnector) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 18 with AssertableLogProvider

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

the class ConnectionInfoIT method catchupServerMessage.

@Test
public void catchupServerMessage() throws Throwable {
    // given
    testSocket = bindPort("localhost", 4242);
    // when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    CoreState coreState = mock(CoreState.class);
    Config config = Config.defaults().with(singletonMap(transaction_listen_address.name(), ":" + testSocket.getLocalPort()));
    CatchupServer catchupServer = new CatchupServer(logProvider, userLogProvider, mockSupplier(), mockSupplier(), mockSupplier(), mockSupplier(), mock(BooleanSupplier.class), coreState, config, new Monitors(), mockSupplier(), mock(FileSystemAbstraction.class), mock(PageCache.class), new StoreCopyCheckPointMutex());
    //then
    try {
        catchupServer.start();
    } catch (Throwable throwable) {
    //expected.
    }
    logProvider.assertContainsMessageContaining("Address is already bound for setting");
    userLogProvider.assertContainsMessageContaining("Address is already bound for setting");
}
Also used : CatchupServer(org.neo4j.causalclustering.catchup.CatchupServer) CoreState(org.neo4j.causalclustering.core.state.CoreState) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Monitors(org.neo4j.kernel.monitoring.Monitors) StoreCopyCheckPointMutex(org.neo4j.kernel.impl.transaction.log.checkpoint.StoreCopyCheckPointMutex) BooleanSupplier(java.util.function.BooleanSupplier) PageCache(org.neo4j.io.pagecache.PageCache) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 19 with AssertableLogProvider

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

the class NeoServerPortConflictIT method shouldComplainIfServerHTTPSPortIsAlreadyTaken.

@Test
public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException, InterruptedException {
    ListenSocketAddress unContestedAddress = new ListenSocketAddress("localhost", 8888);
    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(unContestedAddress).onHttpsAddress(contestedAddress).withHttpsEnabled().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", unContestedAddress, format("At least one of the addresses %s or %s is already in use, cannot bind to it.", unContestedAddress, contestedAddress)));
        server.stop();
    }
}
Also used : ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocket(java.net.ServerSocket) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 20 with AssertableLogProvider

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

the class NeoServerPortConflictIT 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 : 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