Skip to content

Commit

Permalink
test(pub-period-migration) fix "canSearchUsingMetadataDateUpdatedInde…
Browse files Browse the repository at this point in the history
…x" test
  • Loading branch information
SvitlanaKovalova1 committed Oct 22, 2024
1 parent 777262c commit 9ed68bb
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/test/java/org/folio/rest/api/InstanceStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public void canSearchUsingMetadataDateUpdatedIndex()

JsonObject secondInstanceToCreate = nod(secondInstanceId);

IndividualResource ir = createInstance(secondInstanceToCreate);
IndividualResource ir = createInstanceWithDelay(secondInstanceToCreate);

CompletableFuture<Response> getCompleted = new CompletableFuture<>();

Expand Down Expand Up @@ -3041,6 +3041,34 @@ private IndividualResource createInstance(JsonObject instanceToCreate)
return new IndividualResource(response);
}

private IndividualResource createInstanceWithDelay(JsonObject instanceToCreate)
throws InterruptedException, ExecutionException, TimeoutException {
// delay before creating the instance
CompletableFuture<Void> delayFuture = CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
// create the instance
CompletableFuture<Response> createCompleted = delayFuture.thenCompose(v -> {
CompletableFuture<Response> responseFuture = new CompletableFuture<>();

getClient().post(instancesStorageUrl(""), instanceToCreate,
TENANT_ID, json(responseFuture));

return responseFuture;
});
// get the response
Response response = createCompleted.get(2, TimeUnit.SECONDS);

assertThat(format("Create instance failed: %s", response.getBody()),
response.getStatusCode(), is(201));

return new IndividualResource(response);
}

private Response update(JsonObject instance) {
final UUID id = UUID.fromString(instance.getString("id"));
CompletableFuture<Response> replaceCompleted = new CompletableFuture<>();
Expand Down

0 comments on commit 9ed68bb

Please sign in to comment.