rpuch commented on code in PR #2429:
URL: https://github.com/apache/ignite-3/pull/2429#discussion_r1299876150
##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/log4j2/TestLogChecker.java:
##########
@@ -35,7 +35,51 @@
import org.apache.logging.log4j.core.config.Property;
/**
- * Test log checker.
+ * This class is used to check log events/messages.
+ * <p>
+ * When it is needed to check log events/messages, the following steps should
be performed:
+ * </p>
+ * <pre><code>
+ * // Create a new instance of TestLogChecker for the given logger name
and specified predicate.
+ * TestLogChecker checker = new TestLogChecker(
+ * CustomClass.class.getName(),
+ * evt -> evt.getMessage().getFormattedMessage().matches(pattern)
&& evt.getLevel() == Level.ERROR);
+ *
+ * checker.start();
+ * try {
+ * // do something
+ * } finally {
+ * checker.stop();
+ * }
+ *
+ * assertThat(checker.isMatched(), is(true));
+ * </code></pre>
+ * <p>
+ * When it is needed to check log events/messages and perform some action,
just add a predicate and an action:
+ * </p>
+ * <pre><code>
+ * AtomicInteger messageCounter = new AtomicInteger();
+ * TestLogChecker checker = new TestLogChecker(
+ * CustomClass.class.getName(),
+ * evt -> evt.getMessage().getFormattedMessage().matches(pattern)
&& evt.getLevel() == Level.ERROR,
+ * // This action will be executed when the predicate is matched.
+ * () -> {
+ * messageCounter.incrementAndGet();
+ * });
+ *
+ * checker.start();
+ * try {
+ * // do something
+ * } finally {
+ * checker.stop();
+ * }
+ *
+ * assertThat(messageCounter.get(), is(42));
+ * </code></pre>
+ * <p>
+ * It is possible to add a new pair of of predicate and action using {@link
#addHandler(Predicate, Runnable)},
Review Comment:
> By the way, I don't like our approach of using logs to check something
like cluster initialization, snapshots, etc. It should be done via special
lifecycle events, callbacks, whatever... but using logs for this looks weird to
me.
I agree, this sometimes looks weird. But at times we need to know something
very specific, and we don't always have (and should not have, probably) such a
specific event. Also, logs can be considered an 'event recording' system, so
this approach does not look too innatural :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]