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

Feature/immutable events #608

Merged
merged 1 commit into from
Jul 31, 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
19 changes: 7 additions & 12 deletions src/main/java/com/iexec/core/replicate/ReplicateUpdatedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,18 +17,13 @@
package com.iexec.core.replicate;

import com.iexec.common.replicate.ReplicateStatusUpdate;
import lombok.Builder;
import lombok.Value;

import lombok.*;

@Data
@Value
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class ReplicateUpdatedEvent {

private String chainTaskId;
private String walletAddress;
private ReplicateStatusUpdate replicateStatusUpdate;
String chainTaskId;
String walletAddress;
ReplicateStatusUpdate replicateStatusUpdate;
}
18 changes: 7 additions & 11 deletions src/main/java/com/iexec/core/task/event/ConsensusReachedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,17 +16,13 @@

package com.iexec.core.task.event;

import lombok.*;
import lombok.Builder;
import lombok.Value;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Value
@Builder
public class ConsensusReachedEvent {

private String chainTaskId;
private String consensus;
private long blockNumber;
String chainTaskId;
String consensus;
long blockNumber;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,13 +18,7 @@

import lombok.*;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
@Value
public class ContributionTimeoutEvent {

private String chainTaskId;
String chainTaskId;
}
14 changes: 5 additions & 9 deletions src/main/java/com/iexec/core/task/event/PleaseUploadEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,14 +16,10 @@

package com.iexec.core.task.event;

import lombok.*;
import lombok.Value;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Value
public class PleaseUploadEvent {
private String chainTaskId;
private String workerWallet;
String chainTaskId;
String workerWallet;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,15 +16,9 @@

package com.iexec.core.task.event;

import lombok.*;
import lombok.Value;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
@Value
public class ResultUploadTimeoutEvent {

private String chainTaskId;
}
String chainTaskId;
}
13 changes: 4 additions & 9 deletions src/main/java/com/iexec/core/task/event/TaskCompletedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,14 +17,9 @@
package com.iexec.core.task.event;

import com.iexec.core.task.Task;
import lombok.*;
import lombok.Value;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Value
public class TaskCompletedEvent {

private Task task;
Task task;
}
13 changes: 4 additions & 9 deletions src/main/java/com/iexec/core/task/event/TaskCreatedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,14 +16,9 @@

package com.iexec.core.task.event;

import lombok.*;
import lombok.Value;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Value
public class TaskCreatedEvent {

private String chainTaskId;
String chainTaskId;
}
10 changes: 4 additions & 6 deletions src/main/java/com/iexec/core/task/event/TaskFailedEvent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 IEXEC BLOCKCHAIN TECH
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,11 +16,9 @@

package com.iexec.core.task.event;

import lombok.*;
import lombok.Value;

@AllArgsConstructor
@Getter
@Value
public class TaskFailedEvent {

private String chainTaskId;
String chainTaskId;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 IEXEC BLOCKCHAIN TECH
* Copyright 2021-2023 IEXEC BLOCKCHAIN TECH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,13 +16,9 @@

package com.iexec.core.task.event;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Value;

@AllArgsConstructor
@Getter
@Builder
@Value
public class TaskRunningFailedEvent {
private String chainTaskId;
String chainTaskId;
}
14 changes: 4 additions & 10 deletions src/main/java/com/iexec/core/task/update/TaskUpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void running2ConsensusReached(Task task) {
if (optional.isEmpty()) return;
ChainTask chainTask = optional.get();

// change the the revealDeadline and consensus of the task from the chainTask info
// change the revealDeadline and consensus of the task from the chainTask info
task.setRevealDeadline(new Date(chainTask.getRevealDeadline()));
task.setConsensus(chainTask.getConsensusValue());
long consensusBlockNumber = iexecHubService.getConsensusBlock(chainTaskId, task.getInitializationBlockNumber()).getBlockNumber();
Expand Down Expand Up @@ -376,9 +376,7 @@ void initializedOrRunning2ContributionTimeout(Task task) {
if (isInitializedOrRunningTask && isNowAfterContributionDeadline) {
updateTaskStatusAndSave(task, CONTRIBUTION_TIMEOUT);
updateTaskStatusAndSave(task, FAILED);
applicationEventPublisher.publishEvent(ContributionTimeoutEvent.builder()
.chainTaskId(task.getChainTaskId())
.build());
applicationEventPublisher.publishEvent(new ContributionTimeoutEvent(task.getChainTaskId()));
}
}

Expand Down Expand Up @@ -430,9 +428,7 @@ void running2RunningFailed(Task task) {
// - e.g. failing script, dataset can't be retrieved, app can't be downloaded, ...
updateTaskStatusAndSave(task, RUNNING_FAILED);
updateTaskStatusAndSave(task, FAILED);
applicationEventPublisher.publishEvent(TaskRunningFailedEvent.builder()
.chainTaskId(task.getChainTaskId())
.build());
applicationEventPublisher.publishEvent(new TaskRunningFailedEvent(task.getChainTaskId()));
}

void consensusReached2AtLeastOneReveal2ResultUploading(Task task) {
Expand Down Expand Up @@ -553,9 +549,7 @@ void resultUploading2UploadTimeout(Task task) {

if (isTaskInResultUploading && isNowAfterFinalDeadline) {
updateTaskStatusAndSave(task, RESULT_UPLOAD_TIMEOUT);
applicationEventPublisher.publishEvent(ResultUploadTimeoutEvent.builder()
.chainTaskId(task.getChainTaskId())
.build());
applicationEventPublisher.publishEvent(new ResultUploadTimeoutEvent(task.getChainTaskId()));
updateTaskStatusAndSave(task, FAILED);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/com/iexec/core/task/listener/TaskListenerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,14 @@ void init() {

@Test
void shouldUpdateTaskOnTasCreatedEvent() {
TaskCreatedEvent event = new TaskCreatedEvent();
event.setChainTaskId(CHAIN_TASK_ID);
TaskCreatedEvent event = new TaskCreatedEvent(CHAIN_TASK_ID);
taskListeners.onTaskCreatedEvent(event);
verify(taskUpdateRequestManager).publishRequest(anyString());
}

@Test
void shouldProcessContributionTimeoutEvent() {
ContributionTimeoutEvent event = new ContributionTimeoutEvent();
event.setChainTaskId(CHAIN_TASK_ID);
ContributionTimeoutEvent event = new ContributionTimeoutEvent(CHAIN_TASK_ID);
Replicate replicate1 = new Replicate(WALLET1, CHAIN_TASK_ID);
Replicate replicate2 = new Replicate(WALLET2, CHAIN_TASK_ID);
List<Replicate> replicates = List.of(replicate1, replicate2);
Expand All @@ -102,9 +100,11 @@ void shouldProcessContributionTimeoutEvent() {
void shouldNotifyWinnersAndLosersOnTaskConsensusReached() {
String winningHash = "hash";
String badHash = "bad";
ConsensusReachedEvent event = new ConsensusReachedEvent();
event.setChainTaskId(CHAIN_TASK_ID);
event.setConsensus(winningHash);
ConsensusReachedEvent event = ConsensusReachedEvent.builder()
.chainTaskId(CHAIN_TASK_ID)
.consensus(winningHash)
.blockNumber(0L)
.build();
Replicate replicate1 = new Replicate(WALLET1, CHAIN_TASK_ID);
replicate1.setContributionHash(winningHash);
Replicate replicate2 = new Replicate(WALLET2, CHAIN_TASK_ID);
Expand Down