Skip to content

Commit

Permalink
Switch to UUIDv7
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Aug 7, 2024
1 parent 1d1b161 commit c3b981e
Show file tree
Hide file tree
Showing 134 changed files with 521 additions and 484 deletions.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ allprojects {
}
}

dependencies {
implementation("com.github.f4b6a3:uuid-creator:5.2.0")
testImplementation("com.github.f4b6a3:uuid-creator:5.2.0")
}
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;

/**
* Base service extension context.
Expand Down Expand Up @@ -106,7 +106,7 @@ public void initialize() {
getMonitor().info("Initialized " + ext.name());
});
config = loadConfig();
connectorId = getSetting("edc.connector.name", "edc-" + UUID.randomUUID());
connectorId = getSetting("edc.connector.name", "edc-" + UuidCreator.getTimeOrderedEpoch());
participantId = getSetting(PARTICIPANT_ID, ANONYMOUS_PARTICIPANT);
if (ANONYMOUS_PARTICIPANT.equals(participantId)) {
getMonitor().warning("The runtime is configured as an anonymous participant. DO NOT DO THIS IN PRODUCTION.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.IOException;
import java.security.Security;
import java.util.Objects;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
Expand All @@ -42,7 +42,7 @@ public void setUp() {
@Test
void verifyParseInvalidPemThrowsException() {
assertThatExceptionOfType(EdcException.class)
.isThrownBy(() -> parseFunction.apply(UUID.randomUUID().toString()))
.isThrownBy(() -> parseFunction.apply(UuidCreator.getTimeOrderedEpoch().toString()))
.withMessageContaining("Object cannot be null");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;

import static com.nimbusds.jose.JWSAlgorithm.RS256;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -98,7 +98,7 @@ public Map<String, Object> headers() {
private static RSAKey testKey() throws JOSEException {
return new RSAKeyGenerator(2048)
.keyUse(KeyUse.SIGNATURE) // indicate the intended use of the key
.keyID(UUID.randomUUID().toString()) // give the key a unique ID
.keyID(UuidCreator.getTimeOrderedEpoch().toString()) // give the key a unique ID
.generate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.security.interfaces.RSAPublicKey;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.jwt.spi.JwtRegisteredClaimNames.EXPIRATION_TIME;
Expand All @@ -56,7 +56,7 @@ public void setUp() throws JOSEException {
key = testKey();
ruleMock = mock(TokenValidationRule.class);
var publicKey = (RSAPublicKey) key.toPublicKey();
publicKeyId = UUID.randomUUID().toString();
publicKeyId = UuidCreator.getTimeOrderedEpoch().toString();
var resolver = new PublicKeyResolver() {
@Override
public @Nullable
Expand Down Expand Up @@ -125,7 +125,7 @@ private static String createJwt(String publicKeyId, JWTClaimsSet claimsSet, Priv
private static RSAKey testKey() throws JOSEException {
return new RSAKeyGenerator(2048)
.keyUse(KeyUse.SIGNATURE) // indicate the intended use of the key
.keyID(UUID.randomUUID().toString()) // give the key a unique ID
.keyID(UuidCreator.getTimeOrderedEpoch().toString()) // give the key a unique ID
.generate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -52,7 +52,7 @@ class AsyncStatusResultRetryProcessTest {
@Test
void shouldExecuteOnSuccess() {
when(process.get()).thenReturn(CompletableFuture.completedFuture(StatusResult.success("content")));
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new AsyncStatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

var result = retryProcess.onSuccess(onSuccess).execute("any");
Expand All @@ -65,7 +65,7 @@ void shouldExecuteOnSuccess() {
@Test
void shouldReloadEntityIfConfigured() {
when(process.get()).thenReturn(CompletableFuture.completedFuture(StatusResult.success("content")));
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new AsyncStatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);
var reloadedEntity = TestEntity.Builder.newInstance().id(entity.getId()).clock(clock).state(10).build();

Expand All @@ -80,7 +80,7 @@ void shouldReloadEntityIfConfigured() {
void shouldExecuteOnFatalError() {
CompletableFuture<StatusResult<String>> statusResult = CompletableFuture.completedFuture(StatusResult.failure(FATAL_ERROR));
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var retryProcess = new AsyncStatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onSuccess((e, r) -> {}).onFatalError(onFatalError).execute("any");
Expand All @@ -92,7 +92,7 @@ void shouldExecuteOnFatalError() {
void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
CompletableFuture<StatusResult<String>> statusResult = CompletableFuture.failedFuture(new EdcException("error"));
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var retryProcess = new AsyncStatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onSuccess((e, r) -> {}).onRetryExhausted(onRetryExhausted).execute("any");
Expand All @@ -104,7 +104,7 @@ void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
void shouldExecuteOnRetry_whenFailureAndRetriesHaveNotBeenExhausted() {
CompletableFuture<StatusResult<String>> statusResult = CompletableFuture.failedFuture(new EdcException("error"));
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var retryProcess = new AsyncStatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onSuccess((e, r) -> {}).onFailure(onFailure).execute("any");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
Expand All @@ -47,7 +47,7 @@ class CompletableFutureRetryProcessTest {
@Test
void shouldExecuteOnSuccess() {
when(process.get()).thenReturn(CompletableFuture.completedFuture("content"));
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new CompletableFutureRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

var result = retryProcess.onSuccess(onSuccess).execute("any");
Expand All @@ -60,7 +60,7 @@ void shouldExecuteOnSuccess() {
@Test
void shouldReloadEntityIfConfigured() {
when(process.get()).thenReturn(CompletableFuture.completedFuture("content"));
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new CompletableFutureRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);
var reloadedEntity = TestEntity.Builder.newInstance().id(entity.getId()).clock(clock).state(10).build();

Expand All @@ -75,7 +75,7 @@ void shouldReloadEntityIfConfigured() {
void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
CompletableFuture<String> statusResult = CompletableFuture.failedFuture(new EdcException("error"));
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var retryProcess = new CompletableFutureRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onRetryExhausted(onRetryExhausted).execute("any");
Expand All @@ -87,7 +87,7 @@ void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
void shouldExecuteOnRetry_whenFailureAndRetriesHaveNotBeenExhausted() {
CompletableFuture<String> statusResult = CompletableFuture.failedFuture(new EdcException("error"));
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var retryProcess = new CompletableFutureRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onFailure(onFailure).execute("any");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -46,7 +46,7 @@ class RetryProcessTest {

@Test
void execute_shouldNotProcess_whenItShouldDelay() {
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock);

boolean any = retryProcess.execute("any");
Expand All @@ -57,7 +57,7 @@ void execute_shouldNotProcess_whenItShouldDelay() {

@Test
void execute_shouldNotProcess_whenItShouldDelayAndExecuteOnDelayIfSet() {
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var onDelay = mock(Consumer.class);
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock).onDelay(onDelay);

Expand All @@ -71,7 +71,7 @@ void execute_shouldNotProcess_whenItShouldDelayAndExecuteOnDelayIfSet() {
@Test
void execute_shouldProcess_whenItIsNotRetry() {
when(process.get()).thenReturn(true);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateTimestamp(shouldDelayTime).stateCount(1).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(1).build();
var onDelay = mock(Consumer.class);
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock).onDelay(onDelay);

Expand All @@ -84,7 +84,7 @@ void execute_shouldProcess_whenItIsNotRetry() {
@Test
void execute_shouldProcess_whenItIsRetryButDoesNotDelay() {
when(process.get()).thenReturn(true);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateTimestamp(shouldNotDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldNotDelayTime).stateCount(2).build();
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock);

boolean any = retryProcess.execute("any");
Expand All @@ -95,15 +95,15 @@ void execute_shouldProcess_whenItIsRetryButDoesNotDelay() {

@Test
void retriesExhausted_shouldReturnTrueIfRetriesHaveBeenExhausted() {
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateCount(retryLimit + 1).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateCount(retryLimit + 1).build();
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock);

assertThat(retryProcess.retriesExhausted(entity)).isTrue();
}

@Test
void retriesExhausted_shouldReturnFalseIfRetriesHaveNotBeenExhausted() {
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).stateCount(retryLimit).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).stateCount(retryLimit).build();
var retryProcess = new TestRetryProcess(entity, configuration, monitor, clock);

assertThat(retryProcess.retriesExhausted(entity)).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.function.Supplier;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -30,7 +30,7 @@ class SimpleRetryProcessTest {

@Test
void shouldProcess() {
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).build();
Supplier<Boolean> process = mock(Supplier.class);
when(process.get()).thenReturn(true);
var configuration = new EntityRetryProcessConfiguration(2, () -> () -> 2L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
import com.github.f4b6a3.uuid.UuidCreator;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

Expand All @@ -48,7 +48,7 @@ class StatusResultRetryProcessTest {
@Test
void shouldExecuteOnSuccess() {
when(process.get()).thenReturn(StatusResult.success("content"));
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new StatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

var result = retryProcess.onSuccess(onSuccess).execute("any");
Expand All @@ -62,7 +62,7 @@ void shouldExecuteOnSuccess() {
void shouldExecuteOnFatalError() {
StatusResult<String> statusResult = StatusResult.failure(FATAL_ERROR, "error");
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var retryProcess = new StatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onFatalError(onFatalError).execute("any");
Expand All @@ -74,7 +74,7 @@ void shouldExecuteOnFatalError() {
void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
StatusResult<String> statusResult = StatusResult.failure(ERROR_RETRY, "error");
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var retryProcess = new StatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onRetryExhausted(onRetryExhausted).execute("any");
Expand All @@ -86,7 +86,7 @@ void shouldExecuteOnRetryExhausted_whenFailureAndRetriesHaveBeenExhausted() {
void shouldExecuteOnRetry_whenFailureAndRetriesHaveNotBeenExhausted() {
StatusResult<String> statusResult = StatusResult.failure(ERROR_RETRY, "error");
when(process.get()).thenReturn(statusResult);
var entity = TestEntity.Builder.newInstance().id(UUID.randomUUID().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var retryProcess = new StatusResultRetryProcess<>(entity, process, mock(Monitor.class), clock, configuration);

retryProcess.onFailure(onFailure).execute("any");
Expand Down
2 changes: 2 additions & 0 deletions core/common/transform-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {

api(libs.jakartaJson)

implementation("com.github.f4b6a3:uuid-creator:5.2.0")

testImplementation(project(":core:common:junit"))
testImplementation(project(":extensions:common:json-ld"))
}
Loading

0 comments on commit c3b981e

Please sign in to comment.