Search in sources :

Example 61 with AssertableLogProvider

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

the class SettingMigratorsTest method transactionCypherMaxAllocations.

@Test
void transactionCypherMaxAllocations() throws IOException {
    Path confFile = testDirectory.createFile("test.conf");
    Files.write(confFile, List.of("cypher.query_max_allocations=6g"));
    Config config = Config.newBuilder().fromFile(confFile).build();
    var logProvider = new AssertableLogProvider();
    config.setLogger(logProvider.getLog(Config.class));
    assertThat(logProvider).forClass(Config.class).forLevel(WARN).containsMessageWithArguments("The setting cypher.query_max_allocations is removed and replaced by %s.", memory_transaction_max_size.name());
    assertEquals(BYTES.parse("6g"), config.get(memory_transaction_max_size));
}
Also used : Path(java.nio.file.Path) SslPolicyConfig(org.neo4j.configuration.ssl.SslPolicyConfig) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 62 with AssertableLogProvider

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

the class ProcedureJarLoaderTest method shouldLogHelpfullyWhenPluginJarIsCorrupt.

@Test
void shouldLogHelpfullyWhenPluginJarIsCorrupt() throws Exception {
    // given
    URL theJar = createJarFor(ClassWithOneProcedure.class, ClassWithAnotherProcedure.class, ClassWithNoProcedureAtAll.class);
    corruptJar(theJar);
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    ProcedureJarLoader jarloader = new ProcedureJarLoader(procedureCompiler(), logProvider.getLog(ProcedureJarLoader.class));
    // when
    assertThatThrownBy(() -> jarloader.loadProceduresFromDir(parentDir(theJar))).isInstanceOf(ZipException.class).hasMessageContaining(String.format("Some jar procedure files (%s) are invalid, see log for details.", Path.of(theJar.toURI()).getFileName().toString()));
    assertThat(logProvider).containsMessages(format("Plugin jar file: %s corrupted.", Path.of(theJar.toURI())));
}
Also used : ZipException(java.util.zip.ZipException) URL(java.net.URL) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 63 with AssertableLogProvider

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

the class ProcedureJarLoaderTest method shouldWorkOnPathsWithSpaces.

@Test
void shouldWorkOnPathsWithSpaces() throws Exception {
    // given
    Path fileWithSpacesInName = testDirectory.createFile(new Random().nextInt() + "  some spaces in the filename" + ".jar");
    URL theJar = new JarBuilder().createJarFor(fileWithSpacesInName, ClassWithOneProcedure.class);
    corruptJar(theJar);
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    ProcedureJarLoader jarloader = new ProcedureJarLoader(procedureCompiler(), logProvider.getLog(ProcedureJarLoader.class));
    // when
    assertThrows(ZipException.class, () -> jarloader.loadProceduresFromDir(parentDir(theJar)));
    assertThat(logProvider).containsMessages(format("Plugin jar file: %s corrupted.", fileWithSpacesInName));
}
Also used : Path(java.nio.file.Path) Random(java.util.Random) JarBuilder(org.neo4j.test.jar.JarBuilder) URL(java.net.URL) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 64 with AssertableLogProvider

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

the class ProcedureJarLoaderTest method shouldLogHelpfullyWhenJarContainsClassTriggeringVerifyError.

@Test
void shouldLogHelpfullyWhenJarContainsClassTriggeringVerifyError() throws Exception {
    String className = "BrokenProcedureClass";
    // generate a class that is broken and would not normally compile
    DynamicType.Unloaded<Object> unloaded = new ByteBuddy().with(new NamingStrategy.AbstractBase() {

        @Override
        protected String name(TypeDescription superClass) {
            return className;
        }
    }).subclass(Object.class).defineMethod("get", String.class).intercept(// String is not assignable from int -- this triggers a VerifyError when the class is loaded
    MethodCall.invoke(Integer.class.getMethod("valueOf", int.class)).with(42).withAssigner((source, target, typing) -> StackManipulation.Trivial.INSTANCE, Assigner.Typing.STATIC)).make();
    URL jar = unloaded.toJar(testDirectory.createFile(new Random().nextInt() + ".jar").toFile()).toURI().toURL();
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    ProcedureJarLoader jarloader = new ProcedureJarLoader(procedureCompiler(), logProvider.getLog(ProcedureJarLoader.class));
    jarloader.loadProceduresFromDir(parentDir(jar));
    assertThat(logProvider).containsMessages(format("Failed to load `%s` from plugin jar `%s`: %s", className, jar.getFile(), "Bad return type"));
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) ByteBuddy(net.bytebuddy.ByteBuddy) URL(java.net.URL) NTInteger(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTInteger) NamingStrategy(net.bytebuddy.NamingStrategy) Random(java.util.Random) TypeDescription(net.bytebuddy.description.type.TypeDescription) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 65 with AssertableLogProvider

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

the class SingleInstanceGetRoutingTableProcedureTest method whenServerRoutingEnabledShouldUseClientProvidedHostAndDefaultPortAsAdvertisedAddress.

@Test
void whenServerRoutingEnabledShouldUseClientProvidedHostAndDefaultPortAsAdvertisedAddress() throws Exception {
    // given
    var advertisedBoldPort = 8776;
    var advertisedBoltAddress = new SocketAddress("neo4j.com", advertisedBoldPort);
    var clientProvidedHost = "my.neo4j-service.com";
    var config = newConfig(Config.defaults(SERVER_DEFAULTS), Duration.ofSeconds(100), advertisedBoltAddress);
    config.set(GraphDatabaseSettings.routing_default_router, GraphDatabaseSettings.RoutingMode.SERVER);
    var portRegister = mock(ConnectorPortRegister.class);
    when(portRegister.getLocalAddress(BoltConnector.NAME)).thenReturn(new HostnamePort("neo4j.com", advertisedBoldPort));
    var databaseManager = databaseManagerMock(config, true);
    var logProvider = new AssertableLogProvider();
    var procedure = newProcedure(databaseManager, portRegister, config, logProvider);
    var expectedAddress = new SocketAddress(clientProvidedHost, 7687);
    // when
    RoutingResult result = invoke(procedure, clientProvidedHost);
    // then
    assertEquals(singletonList(expectedAddress), result.readEndpoints());
    assertEquals(expectedWriters(expectedAddress), result.writeEndpoints());
    assertEquals(singletonList(expectedAddress), result.routeEndpoints());
}
Also used : HostnamePort(org.neo4j.internal.helpers.HostnamePort) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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