Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
73 changes: 35 additions & 38 deletions src/itest/java/com/iexec/blockchain/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<ChainTask> oChainTask = iexecHubService.getChainTask(chainTaskId);
private void waitBeforeFinalizing(String chainTaskId) {
final Optional<ChainTask> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> matchOrders(@RequestBody BrokerOrder brokerOrder) {
try {
String dealId = brokerService.matchOrders(brokerOrder);
Expand Down