1
1
/*
2
- * Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2
+ * Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import com .iexec .commons .poco .chain .DealParams ;
29
29
import com .iexec .commons .poco .task .TaskDescription ;
30
30
import com .iexec .commons .poco .tee .TeeEnclaveConfiguration ;
31
+ import com .iexec .commons .poco .utils .BytesUtils ;
31
32
import com .iexec .sms .api .TeeSessionGenerationResponse ;
32
33
import com .iexec .worker .config .WorkerConfigurationService ;
33
34
import com .iexec .worker .docker .DockerService ;
44
45
import org .mockito .junit .jupiter .MockitoExtension ;
45
46
46
47
import java .time .Duration ;
47
- import java .util .ArrayList ;
48
- import java .util .Arrays ;
49
- import java .util .Collections ;
50
48
import java .util .List ;
51
49
52
50
import static org .mockito .ArgumentMatchers .any ;
55
53
@ ExtendWith (MockitoExtension .class )
56
54
class AppComputeServiceTests {
57
55
56
+ private static final String CHAIN_DEAL_ID = "CHAIN_DEAL_ID" ;
58
57
private static final String CHAIN_TASK_ID = "CHAIN_TASK_ID" ;
59
- private static final String DATASET_URI = "DATASET_URI" ;
60
58
private static final String APP_URI = "APP_URI" ;
61
59
private static final String WORKER_NAME = "WORKER_NAME" ;
62
60
private static final TeeSessionGenerationResponse SECURE_SESSION = mock (TeeSessionGenerationResponse .class );
@@ -66,13 +64,17 @@ class AppComputeServiceTests {
66
64
public static final long HEAP_SIZE = 1024 ;
67
65
68
66
private final DealParams dealParams = DealParams .builder ()
69
- .iexecInputFiles (Arrays . asList ("file0" , "file1" ))
67
+ .iexecInputFiles (List . of ("file0" , "file1" ))
70
68
.build ();
71
69
72
70
private final TaskDescription .TaskDescriptionBuilder taskDescriptionBuilder = TaskDescription .builder ()
71
+ .chainDealId (CHAIN_DEAL_ID )
73
72
.chainTaskId (CHAIN_TASK_ID )
73
+ .botIndex (0 )
74
+ .botSize (1 )
75
+ .botFirstIndex (0 )
74
76
.appUri (APP_URI )
75
- .datasetUri ( DATASET_URI )
77
+ .datasetAddress ( BytesUtils . EMPTY_ADDRESS )
76
78
.maxExecutionTime (MAX_EXECUTION_TIME )
77
79
.dealParams (dealParams )
78
80
.isTeeTask (true );
@@ -103,16 +105,14 @@ void shouldRunCompute() {
103
105
String iexecOutBind = IEXEC_OUT + ":" + IexecFileHelper .SLASH_IEXEC_OUT ;
104
106
when (dockerService .getIexecOutBind (CHAIN_TASK_ID )).thenReturn (iexecOutBind );
105
107
when (workerConfigService .getWorkerName ()).thenReturn (WORKER_NAME );
106
- DockerRunResponse expectedDockerRunResponse = DockerRunResponse
107
- .builder ()
108
+ DockerRunResponse expectedDockerRunResponse = DockerRunResponse .builder ()
108
109
.finalStatus (DockerRunFinalStatus .SUCCESS )
109
110
.executionDuration (Duration .ofSeconds (10 ))
110
111
.build ();
111
112
when (dockerService .run (any ())).thenReturn (expectedDockerRunResponse );
112
113
113
- AppComputeResponse appComputeResponse =
114
- appComputeService .runCompute (taskDescription ,
115
- SECURE_SESSION );
114
+ final AppComputeResponse appComputeResponse =
115
+ appComputeService .runCompute (taskDescription , SECURE_SESSION );
116
116
117
117
Assertions .assertThat (appComputeResponse .isSuccessful ()).isTrue ();
118
118
verify (dockerService ).run (any ());
@@ -123,7 +123,7 @@ void shouldRunCompute() {
123
123
argumentCaptor .getAllValues ().get (0 );
124
124
HostConfig hostConfig = HostConfig .newHostConfig ()
125
125
.withBinds (Bind .parse (inputBind ), Bind .parse (iexecOutBind ))
126
- .withDevices (new ArrayList <> ());
126
+ .withDevices (List . of ());
127
127
Assertions .assertThat (dockerRunRequest ).isEqualTo (
128
128
DockerRunRequest .builder ()
129
129
.hostConfig (hostConfig )
@@ -145,10 +145,8 @@ void shouldRunComputeWithTeeAndConnectAppToLas() {
145
145
.build ();
146
146
when (teeServicesManager .getTeeService (any ())).thenReturn (teeMockedService );
147
147
when (teeMockedService .buildComputeDockerEnv (taskDescription , SECURE_SESSION ))
148
- .thenReturn (Arrays .asList ("var0" , "var1" ));
149
- List <String > env = new ArrayList <>(Arrays .asList ("var0" , "var1" ));
150
- env .addAll (IexecEnvUtils .getComputeStageEnvList (taskDescription ));
151
- Collections .sort (env );
148
+ .thenReturn (List .of ("var0" , "var1" ));
149
+ final List <String > env = List .of ("var0" , "var1" );
152
150
String inputBind = INPUT + ":" + IexecFileHelper .SLASH_IEXEC_IN ;
153
151
when (dockerService .getInputBind (CHAIN_TASK_ID )).thenReturn (inputBind );
154
152
String iexecOutBind = IEXEC_OUT + ":" + IexecFileHelper .SLASH_IEXEC_OUT ;
@@ -176,7 +174,6 @@ void shouldRunComputeWithTeeAndConnectAppToLas() {
176
174
verify (dockerService ).run (argumentCaptor .capture ());
177
175
DockerRunRequest dockerRunRequest =
178
176
argumentCaptor .getAllValues ().get (0 );
179
- Collections .sort (dockerRunRequest .getEnv ());
180
177
HostConfig hostConfig = HostConfig .newHostConfig ()
181
178
.withBinds (Bind .parse (inputBind ), Bind .parse (iexecOutBind ))
182
179
.withDevices (devices )
0 commit comments