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

Fixed UUID generation for each event id #293

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ dependencies {

+ Use box name from `box.json` config as RabbitMQ connection name
+ Rise `th2_component` metric with box name as `name` label value
+ Fixed UUID generation for each event id

### 5.10.0-dev

Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/exactpro/th2/common/event/Event.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Exactpro (Exactpro Systems Limited)
* Copyright 2020-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import static com.exactpro.th2.common.event.EventUtils.createMessageBean;
Expand Down Expand Up @@ -76,10 +75,8 @@ public class Event {
// otherwise, type supported by JavaTimeModule will be serialized as array of date component
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setSerializationInclusion(NON_NULL));
protected final String UUID = generateUUID();
protected final AtomicLong ID_COUNTER = new AtomicLong();

protected final String id = UUID + '-' + ID_COUNTER.incrementAndGet();
protected final String id = generateUUID();
protected final List<Event> subEvents = new ArrayList<>();
protected final List<MessageID> attachedMessageIds = new ArrayList<>();
protected final List<IBodyData> body = new ArrayList<>();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/exactpro/th2/common/event/EventUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 Exactpro (Exactpro Systems Limited)
* Copyright 2020-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
package com.exactpro.th2.common.event;

import java.time.Instant;
import java.util.concurrent.atomic.AtomicLong;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -34,12 +35,16 @@
@SuppressWarnings("ClassNamePrefixedWithPackageName")
public class EventUtils {
public static final NoArgGenerator TIME_BASED_UUID_GENERATOR = Generators.timeBasedGenerator();
private static final String UUID = TIME_BASED_UUID_GENERATOR.generate().toString();
private static final AtomicLong ID_COUNTER = new AtomicLong();
public static final String DEFAULT_SCOPE = "th2-scope";

/**
* Creates UUID based on cached UUID plus sequential number
*/
public static String generateUUID() {
return TIME_BASED_UUID_GENERATOR.generate().toString();
return UUID + ID_COUNTER.incrementAndGet();
}

public static Message createMessageBean(String text) {
return new MessageBuilder().text(text).build();
}
Expand Down
Loading