Skip to content

Commit

Permalink
fix: add stateTimestamp to translation model (#4165)
Browse files Browse the repository at this point in the history
* fix: add stateTimestamp to translation model

* checkstyle

* pr remarks

* fix test
  • Loading branch information
paullatzelsperger authored May 8, 2024
1 parent b86175a commit 20c2794
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected StatefulEntityMapping(StatefulEntityStatements statements) {
add("id", statements.getIdColumn());
add("state", statements.getStateColumn());
add("stateCount", statements.getStateCountColumn());
add("stateTimestamp", statements.getStateTimestampColumn());
add("createdAt", statements.getCreatedAtColumn());
add("traceContext", new JsonFieldTranslator(statements.getTraceContextColumn()));
add("errorDetail", statements.getErrorDetailColumn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -59,34 +63,6 @@

public class TransferProcessApiEndToEndTest {

@Nested
@EndToEndTest
class InMemory extends Tests {

@RegisterExtension
public static final EdcRuntimeExtension RUNTIME = inMemoryRuntime();

InMemory() {
super(RUNTIME);
}

}

@Nested
@PostgresqlIntegrationTest
class Postgres extends Tests {

@RegisterExtension
static final BeforeAllCallback CREATE_DATABASE = context -> createDatabase("runtime");

@RegisterExtension
public static final EdcRuntimeExtension RUNTIME = postgresRuntime();

Postgres() {
super(RUNTIME);
}
}

abstract static class Tests extends ManagementApiEndToEndTestBase {

Tests(EdcRuntimeExtension runtime) {
Expand Down Expand Up @@ -243,6 +219,48 @@ void request_byState() throws JsonProcessingException {
assertThat(result).anySatisfy(it -> assertThat(it.asJsonObject().getString("state")).isEqualTo(state.toString()));
}

@Test
void request_sortByStateTimestamp() throws JsonProcessingException, InterruptedException {
var tp1 = createTransferProcessBuilder("test-tp1").build();
var tp2 = createTransferProcessBuilder("test-tp2")
.clock(Clock.fixed(Instant.now().plus(1, ChronoUnit.HOURS), ZoneId.systemDefault()))
.build();
getStore().save(tp1);
getStore().save(tp2);


var content = """
{
"@context": {
"@vocab": "https://w3id.org/edc/v0.0.1/ns/"
},
"@type": "QuerySpec",
"sortField": "stateTimestamp",
"sortOrder": "ASC",
"limit": 100,
"offset": 0
}
""";
var query = JacksonJsonLd.createObjectMapper()
.readValue(content, JsonObject.class);

var result = baseRequest()
.contentType(JSON)
.body(query)
.post("/v2/transferprocesses/request")
.then()
.log().ifError()
.statusCode(200)
.extract().body().as(JsonArray.class);

assertThat(result).isNotEmpty().hasSizeGreaterThanOrEqualTo(2);
assertThat(result).isSortedAccordingTo((o1, o2) -> {
var l1 = o1.asJsonObject().getJsonNumber("stateTimestamp").longValue();
var l2 = o2.asJsonObject().getJsonNumber("stateTimestamp").longValue();
return Long.compare(l1, l2);
});
}

private TransferProcessStore getStore() {
return runtime.getContext().getService(TransferProcessStore.class);
}
Expand Down Expand Up @@ -274,4 +292,31 @@ private JsonArrayBuilder createCallbackAddress() {
}
}

@Nested
@EndToEndTest
class InMemory extends Tests {

@RegisterExtension
public static final EdcRuntimeExtension RUNTIME = inMemoryRuntime();

InMemory() {
super(RUNTIME);
}

}

@Nested
@PostgresqlIntegrationTest
class Postgres extends Tests {

@RegisterExtension
public static final EdcRuntimeExtension RUNTIME = postgresRuntime();
@RegisterExtension
static final BeforeAllCallback CREATE_DATABASE = context -> createDatabase("runtime");

Postgres() {
super(RUNTIME);
}
}

}

0 comments on commit 20c2794

Please sign in to comment.