Skip to content

Commit

Permalink
feat: switch to UUIDv7 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Aug 20, 2024
1 parent e86fd33 commit 4edceca
Show file tree
Hide file tree
Showing 129 changed files with 567 additions and 508 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@

### Overview

#### Requirements
Change the type of UUID

#### Implementation
#### Changes

- Database performance improvement

#### Details

See the [fork's documentation](docs/developer/fork/0.2.1.X.md#switch-to-uuidv7): `Switch to UUID v7`

#### Compatibility

No incompatibilities are expected.

#### Resolution plan

Either update to a newer version of the EDC where the problem creating too many leases doesn't happen or propose this change to the core EDC.

## [0.2.1.3] - 2024-06-05

### Overview
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ allprojects {
println(sourceSets["main"].runtimeClasspath.asPath)
}
}

}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
import org.eclipse.edc.spi.uuid.UuidGenerator;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
* 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-" + UuidGenerator.INSTANCE.generate());
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 @@ -15,6 +15,7 @@
package org.eclipse.edc.connector.core.security;

import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -23,7 +24,6 @@
import java.io.IOException;
import java.security.Security;
import java.util.Objects;
import java.util.UUID;

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(UuidGenerator.INSTANCE.generate().toString()))
.withMessageContaining("Object cannot be null");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.nimbusds.jwt.SignedJWT;
import org.eclipse.edc.jwt.spi.JwtDecorator;
import org.eclipse.edc.jwt.spi.TokenGenerationService;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -33,7 +34,6 @@
import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

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(UuidGenerator.INSTANCE.generate().toString()) // give the key a unique ID
.generate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.edc.jwt.spi.TokenValidationService;
import org.eclipse.edc.spi.iam.PublicKeyResolver;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -35,7 +36,6 @@
import java.security.interfaces.RSAPublicKey;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;

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 = UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().toString()) // give the key a unique ID
.generate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.response.ResponseFailure;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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 @@ -16,11 +16,11 @@

import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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 @@ -16,11 +16,11 @@

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.retry.WaitStrategy;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.Instant;
import java.util.UUID;
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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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(UuidGenerator.INSTANCE.generate().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 @@ -15,10 +15,10 @@
package org.eclipse.edc.statemachine.retry;

import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.util.UUID;
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(UuidGenerator.INSTANCE.generate().toString()).build();
Supplier<Boolean> process = mock(Supplier.class);
when(process.get()).thenReturn(true);
var configuration = new EntityRetryProcessConfiguration(2, () -> () -> 2L);
Expand Down
Loading

0 comments on commit 4edceca

Please sign in to comment.