diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a8b6d91..28605f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Fix and harmonize `Dockerfile entrypoint` in all Spring Boot applications. (#102) ### Quality - Upgrade to Gradle 8.2.1 with up-to-date plugins. (#100) +- Clean TODOs. (#104) ### Dependency Upgrades - Upgrade to `eclipse-temurin` 11.0.20. (#98) - Upgrade to Spring Boot 2.7.14. (#99) diff --git a/iexec-blockchain-adapter-api-library/src/main/java/com/iexec/blockchain/api/BlockchainAdapterApiClient.java b/iexec-blockchain-adapter-api-library/src/main/java/com/iexec/blockchain/api/BlockchainAdapterApiClient.java index c6a98d89..3f5e745e 100644 --- a/iexec-blockchain-adapter-api-library/src/main/java/com/iexec/blockchain/api/BlockchainAdapterApiClient.java +++ b/iexec-blockchain-adapter-api-library/src/main/java/com/iexec/blockchain/api/BlockchainAdapterApiClient.java @@ -37,9 +37,7 @@ public interface BlockchainAdapterApiClient { // region authenticated APIs - - //TODO update endpoint - @RequestLine("POST /broker/broker/orders/match") + @RequestLine("POST /broker/orders/match") String matchOrders(BrokerOrder brokerOrder); @RequestLine("GET /metrics") diff --git a/src/itest/java/com/iexec/blockchain/IntegrationTests.java b/src/itest/java/com/iexec/blockchain/IntegrationTests.java index 904d7a75..8f19e965 100644 --- a/src/itest/java/com/iexec/blockchain/IntegrationTests.java +++ b/src/itest/java/com/iexec/blockchain/IntegrationTests.java @@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -63,7 +64,7 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; import static com.iexec.commons.poco.chain.ChainTaskStatus.ACTIVE; @@ -322,53 +323,49 @@ private RequestOrder buildRequestOrder( .build(); } - //TODO: Use `Awaitility` in `waitStatus` & `waitBeforeFinalizing` methods /** * * @param pollingTimeMs recommended value is block time */ - private void waitStatus(String chainTaskId, ChainTaskStatus statusToWait, int pollingTimeMs, int maxAttempts) throws Exception { - ChainTaskStatus status = null; - int attempts = 0; - while(true) { - attempts++; - log.info("Status [status:{}, chainTaskId:{}, attempt:{}]", status, chainTaskId, attempts); - status = iexecHubService.getChainTask(chainTaskId) - .map(ChainTask::getStatus) - .orElse(UNSET); - if (status.equals(statusToWait) || attempts > maxAttempts) { - break; - } - TimeUnit.MILLISECONDS.sleep(pollingTimeMs); - } - if (!status.equals(statusToWait)) { - throw new TimeoutException("Too long to wait for task: " + chainTaskId); - } - log.info("Status reached [status:{}, chainTaskId:{}]", status, chainTaskId); + private void waitStatus(String chainTaskId, ChainTaskStatus statusToWait, int pollingTimeMs, int maxAttempts) { + final AtomicInteger attempts = new AtomicInteger(); + Awaitility.await() + .pollInterval(pollingTimeMs, TimeUnit.MILLISECONDS) + .timeout((long) maxAttempts * pollingTimeMs, TimeUnit.MILLISECONDS) + .until(() -> { + final ChainTaskStatus status = iexecHubService.getChainTask(chainTaskId) + .map(ChainTask::getStatus) + .orElse(UNSET); + log.info("Status [status:{}, chainTaskId:{}, attempt:{}]", status, chainTaskId, attempts.incrementAndGet()); + return status.equals(statusToWait); + } + ); + log.info("Status reached [status:{}, chainTaskId:{}]", statusToWait, chainTaskId); } - private void waitBeforeFinalizing(String chainTaskId) throws Exception { - Optional oChainTask = iexecHubService.getChainTask(chainTaskId); + private void waitBeforeFinalizing(String chainTaskId) { + final Optional oChainTask = iexecHubService.getChainTask(chainTaskId); if (oChainTask.isEmpty()) { return; } - ChainTask chainTask = oChainTask.get(); - int winnerCounter = chainTask.getWinnerCounter(); - int revealCounter = chainTask.getRevealCounter(); - int attempts = 0; + final ChainTask chainTask = oChainTask.get(); + final int winnerCounter = chainTask.getWinnerCounter(); log.info("{} {}", POLLING_INTERVAL_MS, MAX_POLLING_ATTEMPTS); - while (revealCounter != winnerCounter) { - attempts++; - log.info("Waiting for reveals ({}/{}), attempt {}", revealCounter, winnerCounter, attempts); - Thread.sleep(BLOCK_TIME_MS); - revealCounter = iexecHubService.getChainTask(chainTaskId) - .map(ChainTask::getRevealCounter) - .orElse(0); - if (attempts == MAX_BLOCK_TO_WAIT) { - throw new TimeoutException("Too long to wait for reveal: " + chainTaskId); - } - } - log.info("All revealed ({}/{})", revealCounter, winnerCounter); + + final AtomicInteger attempts = new AtomicInteger(); + Awaitility.await() + .pollInterval(POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) + .timeout((long) MAX_POLLING_ATTEMPTS * POLLING_INTERVAL_MS, TimeUnit.MILLISECONDS) + .until(() -> { + final int revealCounter = iexecHubService.getChainTask(chainTaskId) + .map(ChainTask::getRevealCounter) + .orElse(0); + log.info("Waiting for reveals ({}/{}), attempt {}", revealCounter, winnerCounter, attempts.incrementAndGet()); + return revealCounter == winnerCounter; + } + ); + + log.info("All revealed ({}/{})", winnerCounter, winnerCounter); } public WorkerpoolAuthorization mockAuthorization(String chainTaskId, diff --git a/src/main/java/com/iexec/blockchain/broker/BrokerController.java b/src/main/java/com/iexec/blockchain/broker/BrokerController.java index e871e212..aaa8068b 100644 --- a/src/main/java/com/iexec/blockchain/broker/BrokerController.java +++ b/src/main/java/com/iexec/blockchain/broker/BrokerController.java @@ -34,7 +34,7 @@ public BrokerController(BrokerService brokerService) { * @return deal ID if orders are matched on-chain */ @Operation(security = @SecurityRequirement(name = SWAGGER_BASIC_AUTH)) - @PostMapping("/broker/orders/match") + @PostMapping("/orders/match") public ResponseEntity matchOrders(@RequestBody BrokerOrder brokerOrder) { try { String dealId = brokerService.matchOrders(brokerOrder);