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));
}
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())));
}
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));
}
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"));
}
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());
}
Aggregations