Skip to content

Commit

Permalink
Change generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Aug 8, 2024
1 parent da66e8a commit 1d775a1
Show file tree
Hide file tree
Showing 123 changed files with 428 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package org.eclipse.edc.boot.system;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ConfigurationExtension;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void initialize() {
getMonitor().info("Initialized " + ext.name());
});
config = loadConfig();
connectorId = getSetting("edc.connector.name", "edc-" + Generators.timeBasedGenerator().generate());
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 @@ -14,7 +14,7 @@

package org.eclipse.edc.connector.core.security;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.EdcException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void setUp() {
@Test
void verifyParseInvalidPemThrowsException() {
assertThatExceptionOfType(EdcException.class)
.isThrownBy(() -> parseFunction.apply(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.jwt;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSVerifier;
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(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.jwt;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void setUp() throws JOSEException {
key = testKey();
ruleMock = mock(TokenValidationRule.class);
var publicKey = (RSAPublicKey) key.toPublicKey();
publicKeyId = Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.statemachine.retry;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.response.ResponseFailure;
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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.statemachine.retry;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -47,7 +47,7 @@ class CompletableFutureRetryProcessTest {
@Test
void shouldExecuteOnSuccess() {
when(process.get()).thenReturn(CompletableFuture.completedFuture("content"));
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.statemachine.retry;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.retry.WaitStrategy;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -46,7 +46,7 @@ class RetryProcessTest {

@Test
void execute_shouldNotProcess_whenItShouldDelay() {
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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(Generators.timeBasedGenerator().generate().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 @@ -14,7 +14,7 @@

package org.eclipse.edc.statemachine.retry;

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

Expand All @@ -30,7 +30,7 @@ class SimpleRetryProcessTest {

@Test
void shouldProcess() {
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().generate().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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package org.eclipse.edc.statemachine.retry;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.response.ResponseFailure;
import org.eclipse.edc.spi.response.StatusResult;
Expand Down Expand Up @@ -48,7 +48,7 @@ class StatusResultRetryProcessTest {
@Test
void shouldExecuteOnSuccess() {
when(process.get()).thenReturn(StatusResult.success("content"));
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().generate().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidGenerator.INSTANCE.generate().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(Generators.timeBasedGenerator().generate().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(UuidGenerator.INSTANCE.generate().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(Generators.timeBasedGenerator().generate().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 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(Generators.timeBasedGenerator().generate().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 StatusResultRetryProcess<>(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 @@ -14,7 +14,7 @@

package org.eclipse.edc.core.transform.transformer.from;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.uuid.UuidGenerator;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonBuilderFactory;
Expand Down Expand Up @@ -151,7 +151,7 @@ public JsonObject visitPolicy(Policy policy) {
policy.getObligations().forEach(duty -> obligationsBuilder.add(duty.accept(this)));

var builder = jsonFactory.createObjectBuilder()
.add(ID, Generators.timeBasedGenerator().generate().toString())
.add(ID, UuidGenerator.INSTANCE.generate().toString())
.add(TYPE, OdrlNamespace.ODRL_SCHEMA + getTypeAsString(policy.getType()))
.add(ODRL_PERMISSION_ATTRIBUTE, permissionsBuilder)
.add(ODRL_PROHIBITION_ATTRIBUTE, prohibitionsBuilder)
Expand Down
Loading

0 comments on commit 1d775a1

Please sign in to comment.