You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2023/11/21 09:28:35 UTC
(logging-log4j2) branch jee-deletion updated (5fb8be0b98 -> 577723fb8f)
This is an automated email from the ASF dual-hosted git repository.
vy pushed a change to branch jee-deletion
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
from 5fb8be0b98 Fix `PatternParserTest`
add cb39f288ad Fix failing location-based tests (take 2)
add 8f6ad47fbd LOG4J2-1477: Add nullability annotations
add fe7ac81dab Add OpenRewrite configuration
add d5a05bdb6b Apply OpenRewrite Java 11 migration
new 5f9ca8a490 Merge remote-tracking branch 'origin/main' into jee-deletion
new 577723fb8f Rewrite `HttpThreadContextMapFilterTest`
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../log4j/message/ReusableMessageFactoryTest.java | 32 +++---
.../org/apache/logging/log4j/util/Unbox1Test.java | 22 ++--
.../apache/logging/log4j/lang/CheckForNull.java | 25 +++--
.../log4j/lang/ElementsAreNotNullByDefault.java | 16 +--
.../org/apache/logging/log4j/lang/NotNull.java | 22 ++--
.../org/apache/logging/log4j/lang/Tainted.java | 24 +++--
.../org/apache/logging/log4j/lang/Untainted.java | 23 +++--
.../logging/log4j/{util => lang}/package-info.java | 7 +-
.../filter/HttpThreadContextMapFilterTest.java | 111 +++++++++++++++++++++
...Test.xml => HttpThreadContextMapFilterTest.xml} | 18 ++--
.../src/test/resources/log4j2-mutableFilter.xml | 35 -------
.../log4j/core/tools/picocli/CommandLine.java | 4 +-
.../logging/log4j/plugins/util/AnnotationUtil.java | 6 +-
pom.xml | 40 +++++++-
.../LOG4J2-1477_add_nullability_annotations.xml} | 7 +-
15 files changed, 275 insertions(+), 117 deletions(-)
copy log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Lookup.java => log4j-api/src/main/java/org/apache/logging/log4j/lang/CheckForNull.java (67%)
copy log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/QualifierType.java => log4j-api/src/main/java/org/apache/logging/log4j/lang/ElementsAreNotNullByDefault.java (68%)
copy log4j-core/src/main/java/org/apache/logging/log4j/core/config/Scheduled.java => log4j-api/src/main/java/org/apache/logging/log4j/lang/NotNull.java (69%)
copy log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/FactoryType.java => log4j-api/src/main/java/org/apache/logging/log4j/lang/Tainted.java (65%)
copy log4j-core/src/main/java/org/apache/logging/log4j/core/config/Scheduled.java => log4j-api/src/main/java/org/apache/logging/log4j/lang/Untainted.java (68%)
copy log4j-api/src/main/java/org/apache/logging/log4j/{util => lang}/package-info.java (75%)
create mode 100644 log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/HttpThreadContextMapFilterTest.java
copy log4j-core-test/src/test/resources/{org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.xml => HttpThreadContextMapFilterTest.xml} (76%)
delete mode 100644 log4j-core-test/src/test/resources/log4j2-mutableFilter.xml
copy src/changelog/{2.0-beta5/Added_FlumePersistentManager_which_writes_to_BerkeleyDB_and.xml => .3.x.x/LOG4J2-1477_add_nullability_annotations.xml} (82%)
(logging-log4j2) 01/02: Merge remote-tracking branch 'origin/main' into jee-deletion
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch jee-deletion
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 5f9ca8a4902c3fdefb94935936d136edb75580c0
Merge: 5fb8be0b98 d5a05bdb6b
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Nov 21 09:05:36 2023 +0100
Merge remote-tracking branch 'origin/main' into jee-deletion
.../log4j/message/ReusableMessageFactoryTest.java | 32 ++++++++---------
.../org/apache/logging/log4j/util/Unbox1Test.java | 22 ++++++------
.../apache/logging/log4j/lang/CheckForNull.java | 40 +++++++++++++++++++++
.../log4j/lang/ElementsAreNotNullByDefault.java | 31 ++++++++++++++++
.../org/apache/logging/log4j/lang/NotNull.java | 39 ++++++++++++++++++++
.../org/apache/logging/log4j/lang/Tainted.java | 41 ++++++++++++++++++++++
.../org/apache/logging/log4j/lang/Untainted.java | 40 +++++++++++++++++++++
.../apache/logging/log4j/lang/package-info.java | 28 +++++++++++++++
.../log4j/core/tools/picocli/CommandLine.java | 4 +--
.../logging/log4j/plugins/util/AnnotationUtil.java | 6 ++--
pom.xml | 40 ++++++++++++++++++++-
.../LOG4J2-1477_add_nullability_annotations.xml | 25 +++++++++++++
12 files changed, 317 insertions(+), 31 deletions(-)
(logging-log4j2) 02/02: Rewrite `HttpThreadContextMapFilterTest`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch jee-deletion
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 577723fb8f85b7280489b9fedcdc0e61c93aa9a1
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Nov 21 10:27:09 2023 +0100
Rewrite `HttpThreadContextMapFilterTest`
---
.../filter/HttpThreadContextMapFilterTest.java | 111 +++++++++++++++++++++
...lter.xml => HttpThreadContextMapFilterTest.xml} | 20 ++--
2 files changed, 122 insertions(+), 9 deletions(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/HttpThreadContextMapFilterTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/HttpThreadContextMapFilterTest.java
new file mode 100644
index 0000000000..769eaebc5f
--- /dev/null
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/HttpThreadContextMapFilterTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.filter;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+import com.github.tomakehurst.wiremock.common.FileSource;
+import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
+import com.github.tomakehurst.wiremock.extension.Parameters;
+import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
+import com.github.tomakehurst.wiremock.http.Request;
+import com.github.tomakehurst.wiremock.http.Response;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.core.test.junit.Named;
+import org.apache.logging.log4j.spi.ExtendedLogger;
+import org.junit.jupiter.api.Test;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.ok;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link ThreadContextMapFilter} using a WireMock stub.
+ */
+public class HttpThreadContextMapFilterTest {
+
+ @Test
+ @LoggerContextSource("HttpThreadContextMapFilterTest.xml")
+ public void wireMock_logs_should_be_filtered_on_MDC(final LoggerContext loggerContext, @Named("List") final ListAppender appender) throws Exception {
+
+ // Create the logger
+ final ExtendedLogger logger = loggerContext.getLogger(HttpThreadContextMapFilterTest.class);
+
+ // Create a response transformer; the only way to dynamically construct WireMock responses.
+ // We need a dynamic response generation, since there we will issue MDC changes and log statements.
+ final ResponseTransformer wireMockResponseTransformer = new ResponseTransformer() {
+
+ private final AtomicInteger invocationCounter = new AtomicInteger();
+
+ @Override
+ public Response transform(final Request request, final Response response, final FileSource files, final Parameters parameters) {
+ final int invocationCount = invocationCounter.getAndIncrement();
+ ThreadContext.put("invocationCount", "" + invocationCount);
+ logger.info("transforming request #{}", invocationCount);
+ return response;
+ }
+
+ @Override
+ public String getName() {
+ return "mdc-writer";
+ }
+
+ };
+
+ // Create the WireMock server extended using the response transformer.
+ final WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().extensions(wireMockResponseTransformer));
+ wireMockServer.stubFor(get("/").willReturn(ok().withTransformers(wireMockResponseTransformer.getName())));
+
+ wireMockServer.start();
+ try {
+
+ // Perform some HTTP requests.
+ // `HttpThreadContextMapFilterTest.xml` only allows when `invocationCount={0,2}`.
+ // Hence, there preferably needs to be more than 2 requests.
+ final String wireMockStubUrl = wireMockServer.url("/");
+ httpGet(wireMockStubUrl);
+ httpGet(wireMockStubUrl);
+ httpGet(wireMockStubUrl);
+ httpGet(wireMockStubUrl);
+ httpGet(wireMockStubUrl);
+
+ // Verify that `invocationCount={0,2}` filter in `HttpThreadContextMapFilterTest.xml` works
+ assertThat(appender.getMessages()).containsOnly("transforming request #0", "transforming request #2");
+
+ } finally {
+ wireMockServer.stop();
+ }
+
+ }
+
+ private static void httpGet(String url) throws Exception {
+ final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+ connection.connect();
+ try {
+ assertThat(connection.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_OK);
+ } finally {
+ connection.disconnect();
+ }
+ }
+
+}
diff --git a/log4j-core-test/src/test/resources/log4j2-mutableFilter.xml b/log4j-core-test/src/test/resources/HttpThreadContextMapFilterTest.xml
similarity index 73%
rename from log4j-core-test/src/test/resources/log4j2-mutableFilter.xml
rename to log4j-core-test/src/test/resources/HttpThreadContextMapFilterTest.xml
index 4a39683016..ab28f1a449 100644
--- a/log4j-core-test/src/test/resources/log4j2-mutableFilter.xml
+++ b/log4j-core-test/src/test/resources/HttpThreadContextMapFilterTest.xml
@@ -15,21 +15,23 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<Configuration name="ConfigTest" status="ERROR">
- <MutableThreadContextMapFilter configLocation="${sys:configLocation}" pollInterval="1" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
+<Configuration status="OFF" name="HttpThreadContextMapFilterTest">
+
+ <ContextMapFilter onMatch="ACCEPT" operator="or">
+ <KeyValuePair key="invocationCount" value="0"/>
+ <KeyValuePair key="invocationCount" value="2"/>
+ </ContextMapFilter>
+
<Appenders>
- <Console name="STDOUT">
- <PatternLayout pattern="%m%n"/>
- </Console>
<List name="List">
+ <PatternLayout pattern="%m"/>
</List>
</Appenders>
+
<Loggers>
- <Logger name="Test" level="error">
+ <Root level="ALL">
<AppenderRef ref="List"/>
- </Logger>
- <Root level="error">
- <AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
+
</Configuration>