Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deterministic UUID option for PatternLayout #3532

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
kazariad committed Mar 17, 2025
commit 7f126de6bd0b07fca373322a804f975c25d8475a
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.UUID;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.test.layout.LogEventFixtures;
import org.junit.jupiter.api.Test;

public class UuidTest {
@@ -107,6 +109,20 @@ public void testThreads() throws Exception {
assertEquals(0, errors, errors + " duplicate UUIDS");
}

@Test
public void testHashBasedUuid() {
LogEvent event1 = LogEventFixtures.createLogEvent();
LogEvent event2 = LogEventFixtures.createLogEvent()
.asBuilder()
.setThrown(event1.getThrown())
.build();
UUID uuid1 = UuidUtil.getHashBasedUuid(event1);
UUID uuid2 = UuidUtil.getHashBasedUuid(event2);
assertEquals(uuid1, uuid2, "UUIDs don't match");
assertEquals(8, uuid1.version(), "Wrong version");
assertEquals(2, uuid1.variant(), "Wrong variant");
}

private static class Worker extends Thread {

private final UUID[] uuids;