Skip to content

Commit

Permalink
Merge remote-tracking branch 'apache/2.x' into 2.x-ppkarwasz
Browse files Browse the repository at this point in the history
  • Loading branch information
ppkarwasz committed Mar 18, 2024
2 parents dadb52b + baf18f6 commit 9106176
Show file tree
Hide file tree
Showing 330 changed files with 29,006 additions and 24,323 deletions.
17 changes: 16 additions & 1 deletion .github/generate-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ RELEASE_NOTES_FILE="$SCRIPT_DIR/../src/site/_release-notes/_$PROJECT_VERSION.ado
exit 1
}

dump_review_kit() {
wget -q -O - https://raw.githubusercontent.com/apache/logging-parent/main/.github/release-review-kit.txt \
| sed -n '/-----8<-----~( cut here )~-----8<-----/,$p' \
| tail -n +2 \
| sed -r 's!^! !g'
}

dump_release_notes() {
awk "f{print} /^Release date::/{f=1}" "$RELEASE_NOTES_FILE" \
| sed -r 's!'$PROJECT_REPO'/(issues|pull)/[0-9]+\[([0-9]+)\]!#\2!g' \
Expand Down Expand Up @@ -77,7 +84,15 @@ Please download, test, and cast your votes on this mailing list.
This vote is open for 72 hours and will pass unless getting a
net negative vote count. All votes are welcome and we encourage
everyone to test the release, but only the Logging Services PMC
votes are officially counted.
votes are officially counted. At least 3 +1 votes and more
positive than negative votes are required.
== Review kit
The minimum set of steps needed to review the uploaded distribution
files in the Subversion repository can be summarized as follows:
$(dump_review_kit)
== Release Notes
EOF
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecards-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
steps:

- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # 4.1.2
with:
persist-credentials: false

Expand All @@ -70,6 +70,6 @@ jobs:
retention-days: 5

- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@47b3d888fe66b639e431abf22ebca059152f1eea # 2.1.22
uses: github/codeql-action/upload-sarif@8a470fddafa5cbb6266ee11b37ef4d8aae19c571 # 2.1.22
with:
sarif_file: results.sarif
1 change: 1 addition & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
-Dfile.encoding=UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.ResourceLock;

/**
* Shortcut to {@link StatusLoggerMockExtension}.
Expand All @@ -32,4 +33,5 @@
@Target({TYPE, METHOD})
@Documented
@ExtendWith({ExtensionContextAnchor.class, StatusLoggerMockExtension.class})
@ResourceLock("log4j2.StatusLogger")
public @interface UsingStatusLoggerMock {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the license.
*/
@Export
@Version("2.23.0")
@Version("2.23.1")
package org.apache.logging.log4j.test.junit;

import org.osgi.annotation.bundle.Export;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
/*
* 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.internal.map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.logging.log4j.test.junit.UsingThreadContextMap;
import org.apache.logging.log4j.util.TriConsumer;
import org.junit.jupiter.api.Test;

/**
* Tests the {@code StringArrayThreadContextMap} class.
*/
@UsingThreadContextMap
public class StringArrayThreadContextMapTest {

@Test
public void testEqualsVsSameKind() {
final StringArrayThreadContextMap map1 = createMap();
final StringArrayThreadContextMap map2 = createMap();
assertEquals(map1, map1);
assertEquals(map2, map2);
assertEquals(map1, map2);
assertEquals(map2, map1);
}

@Test
public void testHashCodeVsSameKind() {
final StringArrayThreadContextMap map1 = createMap();
final StringArrayThreadContextMap map2 = createMap();
assertEquals(map1.hashCode(), map2.hashCode());
}

@Test
public void testGet() {
final StringArrayThreadContextMap map1 = createMap();
assertNull(map1.get("test"));
map1.put("test", "test");
assertEquals("test", map1.get("test"));
assertNull(map1.get("not_present"));
assertEquals("test", map1.getValue("test"));
assertNull(map1.getValue("not_present"));

map1.clear();
assertNull(map1.get("not_present"));
}

@Test
public void testPut() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertTrue(map.isEmpty());
assertFalse(map.containsKey("key"));
map.put("key", "value");

assertFalse(map.isEmpty());
assertTrue(map.containsKey("key"));
assertEquals("value", map.get("key"));
}

@Test
public void testPutAll() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertTrue(map.isEmpty());
assertFalse(map.containsKey("key"));
final int mapSize = 10;
final Map<String, String> newMap = new HashMap<>(mapSize);
for (int i = 1; i <= mapSize; i++) {
newMap.put("key" + i, "value" + i);
}
map.putAll(newMap);
assertFalse(map.isEmpty());
for (int i = 1; i <= mapSize; i++) {
assertTrue(map.containsKey("key" + i));
assertEquals("value" + i, map.get("key" + i));
}
}

/**
* Test method for
* {@link org.apache.logging.log4j.internal.map.StringArrayThreadContextMap#remove(java.lang.String)}
* .
*/
@Test
public void testRemove() {
final StringArrayThreadContextMap map = createMap();
assertEquals("value", map.get("key"));
assertEquals("value2", map.get("key2"));

map.remove("key");
assertFalse(map.containsKey("key"));
assertEquals("value2", map.get("key2"));

map.clear();
map.remove("test");
}

@Test
public void testRemoveAll() {
final StringArrayThreadContextMap map = createMap();

Map<String, String> newValues = new HashMap<>();
newValues.put("1", "value1");
newValues.put("2", "value2");

map.putAll(newValues);
map.removeAll(newValues.keySet());

map.put("3", "value3");

map.clear();
map.removeAll(newValues.keySet());
}

@Test
public void testClear() {
final StringArrayThreadContextMap map = createMap();

map.clear();
assertTrue(map.isEmpty());
assertFalse(map.containsKey("key"));
assertFalse(map.containsKey("key2"));
}

/**
* @return
*/
private StringArrayThreadContextMap createMap() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertTrue(map.isEmpty());
map.put("key", "value");
map.put("key2", "value2");
assertEquals("value", map.get("key"));
assertEquals("value2", map.get("key2"));
return map;
}

@Test
public void testGetCopyReturnsMutableMap() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertTrue(map.isEmpty());
final Map<String, String> copy = map.getCopy();
assertTrue(copy.isEmpty());

copy.put("key", "value"); // mutable
assertEquals("value", copy.get("key"));

// thread context map not affected
assertTrue(map.isEmpty());
}

@Test
public void testGetCopyReturnsMutableCopy() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
map.put("key1", "value1");
assertFalse(map.isEmpty());
final Map<String, String> copy = map.getCopy();
assertEquals("value1", copy.get("key1")); // copy has values too

copy.put("key", "value"); // copy is mutable
assertEquals("value", copy.get("key"));

// thread context map not affected
assertFalse(map.containsKey("key"));

// clearing context map does not affect copy
map.clear();
assertTrue(map.isEmpty());

assertFalse(copy.isEmpty());
}

@Test
public void testGetImmutableMapReturnsNullIfEmpty() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertTrue(map.isEmpty());
assertNull(map.getImmutableMapOrNull());
}

@Test
public void testGetImmutableMapReturnsImmutableMapIfNonEmpty() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
map.put("key1", "value1");
assertFalse(map.isEmpty());

final Map<String, String> immutable = map.getImmutableMapOrNull();
assertEquals("value1", immutable.get("key1")); // copy has values too

// immutable
assertThrows(UnsupportedOperationException.class, () -> immutable.put("key", "value"));
}

@Test
public void testGetImmutableMapCopyNotAffectdByContextMapChanges() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
map.put("key1", "value1");
assertFalse(map.isEmpty());

final Map<String, String> immutable = map.getImmutableMapOrNull();
assertEquals("value1", immutable.get("key1")); // copy has values too

// clearing context map does not affect copy
map.clear();
assertTrue(map.isEmpty());

assertFalse(immutable.isEmpty());
}

@Test
public void testToStringShowsMapContext() {
final StringArrayThreadContextMap map = new StringArrayThreadContextMap();
assertEquals("{}", map.toString());

map.put("key1", "value1");
assertEquals("{key1=value1}", map.toString());

map.remove("key1");
map.put("key2", "value2");
assertEquals("{key2=value2}", map.toString());
}

@Test
public void testEmptyMap() {
assertNull(UnmodifiableArrayBackedMap.EMPTY_MAP.get("test"));
}

@Test
public void testForEachBiConsumer_Log4jUtil() {
StringArrayThreadContextMap map = createMap();
Set<String> keys = new HashSet<>();
org.apache.logging.log4j.util.BiConsumer<String, String> log4j_util_action =
new org.apache.logging.log4j.util.BiConsumer<String, String>() {
@Override
public void accept(String key, String value) {
keys.add(key);
}
};
map.forEach(log4j_util_action);
assertEquals(map.toMap().keySet(), keys);

map.clear();
keys.clear();
map.forEach(log4j_util_action);
assertTrue(keys.isEmpty());
}

@Test
public void testForEachTriConsumer() {
StringArrayThreadContextMap map = createMap();
HashMap<String, String> iterationResultMap = new HashMap<>();
TriConsumer<String, String, Map<String, String>> triConsumer =
new TriConsumer<String, String, Map<String, String>>() {
@Override
public void accept(String k, String v, Map<String, String> s) {
s.put(k, v);
}
};
map.forEach(triConsumer, iterationResultMap);
assertEquals(map.toMap(), iterationResultMap);

map.clear();
iterationResultMap.clear();
map.forEach(triConsumer, iterationResultMap);
assertTrue(iterationResultMap.isEmpty());
}
}
Loading

0 comments on commit 9106176

Please sign in to comment.