Skip to content

Commit

Permalink
Use FasterXML library
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Aug 7, 2024
1 parent c3b981e commit 96f351c
Show file tree
Hide file tree
Showing 126 changed files with 410 additions and 444 deletions.
5 changes: 0 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ allprojects {
println(sourceSets["main"].runtimeClasspath.asPath)
}
}

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 @@ -15,6 +15,7 @@

package org.eclipse.edc.boot.system;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ConfigurationExtension;
Expand All @@ -26,7 +27,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
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-" + UuidCreator.getTimeOrderedEpoch());
connectorId = getSetting("edc.connector.name", "edc-" + Generators.timeBasedGenerator().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,6 +14,7 @@

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

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.EdcException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -23,7 +24,6 @@
import java.io.IOException;
import java.security.Security;
import java.util.Objects;
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(UuidCreator.getTimeOrderedEpoch().toString()))
.isThrownBy(() -> parseFunction.apply(Generators.timeBasedGenerator().generate().toString()))
.withMessageContaining("Object cannot be null");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.edc.jwt;

import com.fasterxml.uuid.Generators;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.JWSVerifier;
Expand All @@ -33,7 +34,6 @@
import java.time.Instant;
import java.util.Date;
import java.util.Map;
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(UuidCreator.getTimeOrderedEpoch().toString()) // give the key a unique ID
.keyID(Generators.timeBasedGenerator().generate().toString()) // give the key a unique ID
.generate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.edc.jwt;

import com.fasterxml.uuid.Generators;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSAlgorithm;
import com.nimbusds.jose.JWSHeader;
Expand All @@ -35,7 +36,6 @@
import java.security.interfaces.RSAPublicKey;
import java.time.Instant;
import java.util.Date;
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 = UuidCreator.getTimeOrderedEpoch().toString();
publicKeyId = Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()) // give the key a unique ID
.keyID(Generators.timeBasedGenerator().generate().toString()) // give the key a unique ID
.generate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.edc.statemachine.retry;

import com.fasterxml.uuid.Generators;
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.response.ResponseFailure;
Expand All @@ -22,7 +23,6 @@

import java.time.Clock;
import java.time.Instant;
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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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,13 +14,13 @@

package org.eclipse.edc.statemachine.retry;

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

import java.time.Clock;
import java.time.Instant;
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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit + 1).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).clock(clock).stateCount(retryLimit).stateTimestamp(millis - 2L).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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,13 +14,13 @@

package org.eclipse.edc.statemachine.retry;

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

import java.time.Clock;
import java.time.Instant;
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(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldDelayTime).stateCount(1).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).stateTimestamp(shouldNotDelayTime).stateCount(2).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).stateCount(retryLimit + 1).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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(UuidCreator.getTimeOrderedEpoch().toString()).stateCount(retryLimit).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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,11 +14,11 @@

package org.eclipse.edc.statemachine.retry;

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

import java.time.Clock;
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(UuidCreator.getTimeOrderedEpoch().toString()).build();
var entity = TestEntity.Builder.newInstance().id(Generators.timeBasedGenerator().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 96f351c

Please sign in to comment.