From 0d1b88057a8e0da6e46738f7e05b12781746807b Mon Sep 17 00:00:00 2001 From: Paul Horn Date: Mon, 15 Jul 2024 12:33:32 +0200 Subject: [PATCH] Match expected logs case-insensitively --- .../java/org/neo4j/gds/compat/TestLog.java | 3 +++ .../java/org/neo4j/gds/compat/TestLogImpl.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLog.java b/compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLog.java index 1eed1eae90b..b6f800d5fd6 100644 --- a/compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLog.java +++ b/compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLog.java @@ -19,6 +19,7 @@ */ package org.neo4j.gds.compat; +import org.intellij.lang.annotations.Language; import org.neo4j.gds.annotation.SuppressForbidden; import org.neo4j.logging.Log; @@ -32,6 +33,8 @@ public interface TestLog extends Log { void assertContainsMessage(String level, String fragment); + void assertMessageMatches(String level, @Language("RegExp") String pattern); + boolean containsMessage(String level, String fragment); boolean hasMessages(String level); diff --git a/compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLogImpl.java b/compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLogImpl.java index ca9f23c3bf5..da544cc1895 100644 --- a/compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLogImpl.java +++ b/compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/TestLogImpl.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; +import java.util.regex.Pattern; public class TestLogImpl implements TestLog { @@ -50,6 +51,23 @@ public void assertContainsMessage(String level, String fragment) { } } + @Override + public void assertMessageMatches(String level, String pattern) { + var compiled = Pattern.compile(pattern); + var messageList = messages.getOrDefault(level, new ConcurrentLinkedQueue<>()); + if (messageList.stream().noneMatch(compiled.asPredicate())) { + throw new RuntimeException( + String.format( + Locale.US, + "Expected log output to match `%s` for log level `%s`%nLog messages:%n%s", + pattern, + level, + String.join("\n", messageList) + ) + ); + } + } + @Override public boolean containsMessage(String level, String fragment) { ConcurrentLinkedQueue messageList = messages.getOrDefault(level, new ConcurrentLinkedQueue<>());