Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jenkins-library 2.7.4, improve testcontainers tests #116

Merged
merged 1 commit into from
Nov 14, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ All notable changes to this project will be documented in this file.
- Reindent `build.gradle` file. (#114)
- Standardisation of the dockerfile and its location in regard to other java components. (#115)

### Dependency Upgrades

- Upgrade to `jenkins-library` 2.7.4. (#116)

## [[8.2.0]](https://github.com/iExecBlockchainComputing/iexec-blockchain-adapter-api/releases/tag/v8.2.0) 2023-09-28

### Bug Fixes
Expand Down
7 changes: 2 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@Library('[email protected].3') _
@Library('[email protected].4') _
buildJavaProject(
buildInfo: getBuildInfo(),
integrationTestsEnvVars: ['BROKER_PRIVATE_KEY'],
shouldPublishJars: true,
shouldPublishDockerImages: true,
dockerfileDir: '.',
buildContext: '.')
shouldPublishDockerImages: true)
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ allprojects {
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}
sourceCompatibility = '11'
targetCompatibility = '11'
}
}

Expand Down Expand Up @@ -152,6 +154,5 @@ tasks.register('buildImage', Exec) {
group 'Build'
description 'Builds an OCI image from a Dockerfile.'
dependsOn bootJar
commandLine("sh", "-c", "docker build --build-arg jar=$jarPathForOCI -t $ociImageName:$gitShortCommit ."
+ " && docker tag $ociImageName:$gitShortCommit $ociImageName:dev")
commandLine 'docker', 'build', '--build-arg', 'jar=' + jarPathForOCI, '-t', ociImageName + ':dev', '.'
}
2 changes: 2 additions & 0 deletions iexec-blockchain-adapter-api-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
}

java {
sourceCompatibility = '11'
targetCompatibility = '11'
withJavadocJar()
withSourcesJar()
}
Expand Down
65 changes: 38 additions & 27 deletions src/itest/java/com/iexec/blockchain/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.DockerComposeContainer;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand All @@ -74,9 +74,14 @@
@Slf4j
@Testcontainers
@ActiveProfiles("itest")
@SpringBootTest(properties = { "chain.max-allowed-tx-per-block=2"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(properties = {"chain.max-allowed-tx-per-block=2"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class IntegrationTests {

private static final String CHAIN_SVC_NAME = "ibaa-chain";
private static final int CHAIN_SVC_PORT = 8545;
private static final String MONGO_SVC_NAME = "ibaa-blockchain-adapter-mongo";
private static final int MONGO_SVC_PORT = 13012;

public static final String USER = "admin";
public static final String PASSWORD = "whatever";
public static final int BLOCK_TIME_MS = 5000;
Expand All @@ -86,44 +91,50 @@ class IntegrationTests {
public static final int MAX_POLLING_ATTEMPTS = MAX_BLOCK_TO_WAIT * POLLING_PER_BLOCK;

@Container
static DockerComposeContainer<?> environment = new DockerComposeContainer<>(new File("docker-compose.yml"))
.withExposedService("ibaa-chain", 8545, Wait.forListeningPort())
.withExposedService("ibaa-blockchain-adapter-mongo", 13012, Wait.forListeningPort());
static ComposeContainer environment = new ComposeContainer(new File("docker-compose.yml"))
.withPull(true)
.withExposedService(CHAIN_SVC_NAME, CHAIN_SVC_PORT, Wait.forListeningPort())
.withExposedService(MONGO_SVC_NAME, MONGO_SVC_PORT, Wait.forListeningPort());

@DynamicPropertySource
static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("chain.id", () -> "65535");
registry.add("chain.hubAddress", () -> "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca");
registry.add("chain.nodeAddress", () -> getServiceUrl(environment.getServicePort("ibaa-chain", 8545)));
registry.add("spring.data.mongodb.port", () -> environment.getServicePort("ibaa-blockchain-adapter-mongo", 13012));
registry.add("chain.nodeAddress", () -> getServiceUrl(
environment.getServiceHost(CHAIN_SVC_NAME, CHAIN_SVC_PORT),
environment.getServicePort(CHAIN_SVC_NAME, CHAIN_SVC_PORT)));
registry.add("sprint.data.mongodb.host", () -> environment.getServiceHost(MONGO_SVC_NAME, MONGO_SVC_PORT));
registry.add("spring.data.mongodb.port", () -> environment.getServicePort(MONGO_SVC_NAME, MONGO_SVC_PORT));
}

@LocalServerPort
private int randomServerPort;

@Autowired
private IexecHubService iexecHubService;

@Autowired
private CredentialsService credentialsService;

@Autowired
private BrokerService brokerService;
private final IexecHubService iexecHubService;
private final CredentialsService credentialsService;
private final BrokerService brokerService;
private final ChainConfig chainConfig;
private BlockchainAdapterApiClient appClient;

@Autowired
private ChainConfig chainConfig;
private BlockchainAdapterApiClient appClient;
IntegrationTests(IexecHubService iexecHubService, CredentialsService credentialsService,
BrokerService brokerService, ChainConfig chainConfig) {
this.iexecHubService = iexecHubService;
this.credentialsService = credentialsService;
this.brokerService = brokerService;
this.chainConfig = chainConfig;
}

@BeforeEach
void setUp(TestInfo testInfo) {
log.info(">>> {}", testInfo.getDisplayName());
appClient = BlockchainAdapterApiClientBuilder
.getInstanceWithBasicAuth(Logger.Level.FULL, getServiceUrl(randomServerPort), USER, PASSWORD);
.getInstanceWithBasicAuth(Logger.Level.FULL, getServiceUrl("localhost", randomServerPort), USER, PASSWORD);
}

private static String getServiceUrl(int servicePort) {
log.info("service url http://localhost:{}", servicePort);
return "http://localhost:" + servicePort;
private static String getServiceUrl(String serviceHost, int servicePort) {
log.info("service url http://{}:{}", serviceHost, servicePort);
return "http://" + serviceHost + ":" + servicePort;
}

@Test
Expand All @@ -142,15 +153,15 @@ public void shouldBeFinalized() throws Exception {
String enclaveSignature = BytesUtils.bytesToString(new byte[65]);
WorkerpoolAuthorization workerpoolAuthorization =
mockAuthorization(chainTaskId, enclaveChallenge);
receipt = iexecHubService.contribute(
receipt = iexecHubService.contribute(
chainTaskId,
someBytes32Payload,
workerpoolAuthorization.getSignature().getValue(),
enclaveChallenge,
enclaveSignature);
log.info("contribute {}", receipt);
waitStatus(chainTaskId, ChainTaskStatus.REVEALING,
MAX_POLLING_ATTEMPTS);
MAX_POLLING_ATTEMPTS);

receipt = iexecHubService.reveal(chainTaskId, someBytes32Payload);
log.info("reveal {}", receipt);
Expand All @@ -161,7 +172,7 @@ public void shouldBeFinalized() throws Exception {
Assertions.assertTrue(StringUtils.isNotEmpty(finalizeResponseBody));
log.info("Requested task finalize: {}", finalizeResponseBody);
waitStatus(chainTaskId, ChainTaskStatus.COMPLETED,
MAX_POLLING_ATTEMPTS);
MAX_POLLING_ATTEMPTS);
}

@Test
Expand All @@ -183,7 +194,7 @@ public void shouldBurstTransactionsWithAverageOfOneTxPerBlock() {
//maximum waiting time equals nb of submitted txs
//1 tx/block means N txs / N blocks
waitStatus(chainTaskId, ACTIVE,
(taskVolume / 2 + 2) * MAX_POLLING_ATTEMPTS);
(taskVolume / 2 + 2) * MAX_POLLING_ATTEMPTS);
//no need to wait for propagation update in db
Assertions.assertTrue(true);
} catch (Exception e) {
Expand All @@ -206,7 +217,7 @@ private String triggerDeal(int taskVolume) {
secondsTimeout, secondsPollingInterval);
log.info("Created app: {}", appAddress);
String workerpool = iexecHubService.createWorkerpool(buildRandomName("pool"),
secondsTimeout, secondsPollingInterval);
secondsTimeout, secondsPollingInterval);
log.info("Created workerpool: {}", workerpool);
String datasetAddress = iexecHubService.createDataset(buildRandomName("data"),
"https://abc.com/def.jpeg",
Expand Down Expand Up @@ -299,7 +310,7 @@ private RequestOrder buildRequestOrder(
boolean isCompatibleVolume =
appOrder.getVolume().equals(workerpoolOrder.getVolume())
&& appOrder.getVolume().equals(datasetOrder.getVolume());
if (!isCompatibleVolume){
if (!isCompatibleVolume) {
log.info("Volumes are not compatible");
return null;
}
Expand Down