4343import lombok .extern .slf4j .Slf4j ;
4444import org .junit .jupiter .api .BeforeEach ;
4545import org .junit .jupiter .api .Test ;
46+ import org .junit .jupiter .api .extension .ExtendWith ;
4647import org .junit .jupiter .api .io .TempDir ;
4748import org .junit .jupiter .params .ParameterizedTest ;
4849import org .junit .jupiter .params .provider .MethodSource ;
4950import org .mockito .ArgumentCaptor ;
5051import org .mockito .InjectMocks ;
5152import org .mockito .Mock ;
52- import org .mockito .MockitoAnnotations ;
53+ import org .mockito .junit . jupiter . MockitoExtension ;
5354
5455import java .io .File ;
5556import java .io .IOException ;
6768import static org .mockito .Mockito .*;
6869
6970@ Slf4j
71+ @ ExtendWith (MockitoExtension .class )
7072class PostComputeServiceTests {
7173
7274 private static final String CHAIN_TASK_ID = "CHAIN_TASK_ID" ;
7375 private static final String DATASET_URI = "DATASET_URI" ;
7476 private static final String WORKER_NAME = "WORKER_NAME" ;
7577 private static final String TEE_POST_COMPUTE_IMAGE = "TEE_POST_COMPUTE_IMAGE" ;
76- private static final long TEE_POST_COMPUTE_HEAP = 1024 ;
7778 private static final String TEE_POST_COMPUTE_ENTRYPOINT = "postComputeEntrypoint" ;
7879 private static final TeeSessionGenerationResponse SECURE_SESSION = mock (TeeSessionGenerationResponse .class );
7980 private static final long MAX_EXECUTION_TIME = 1000 ;
@@ -118,13 +119,6 @@ class PostComputeServiceTests {
118119
119120 @ BeforeEach
120121 void beforeEach () {
121- MockitoAnnotations .openMocks (this );
122- when (dockerService .getClient ()).thenReturn (dockerClientInstanceMock );
123- when (teeServicesManager .getTeeService (any ())).thenReturn (teeMockedService );
124- when (properties .getPreComputeProperties ()).thenReturn (preComputeProperties );
125- when (properties .getPostComputeProperties ()).thenReturn (postComputeProperties );
126- when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (properties );
127-
128122 output = jUnitTemporaryFolder .getAbsolutePath ();
129123 iexecOut = output + IexecFileHelper .SLASH_IEXEC_OUT ;
130124 computedJson = iexecOut + IexecFileHelper .SLASH_COMPUTED_JSON ;
@@ -218,17 +212,18 @@ void shouldRunTeePostComputeAndConnectToLasNetwork() {
218212 .maxExecutionTime (MAX_EXECUTION_TIME )
219213 .build ();
220214 List <String > env = Arrays .asList ("var0" , "var1" );
215+ when (dockerService .getClient ()).thenReturn (dockerClientInstanceMock );
216+ when (teeServicesManager .getTeeService (any ())).thenReturn (teeMockedService );
217+ when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (properties );
218+ when (properties .getPostComputeProperties ()).thenReturn (postComputeProperties );
221219 when (postComputeProperties .getImage ()).thenReturn (TEE_POST_COMPUTE_IMAGE );
222- when (postComputeProperties .getHeapSizeInBytes ()).thenReturn (TEE_POST_COMPUTE_HEAP );
223220 when (postComputeProperties .getEntrypoint ()).thenReturn (TEE_POST_COMPUTE_ENTRYPOINT );
224221 when (dockerClientInstanceMock .isImagePresent (TEE_POST_COMPUTE_IMAGE ))
225222 .thenReturn (true );
226223 when (teeMockedService .buildPostComputeDockerEnv (taskDescription , SECURE_SESSION ))
227224 .thenReturn (env );
228225 String iexecOutBind = iexecOut + ":" + IexecFileHelper .SLASH_IEXEC_OUT ;
229226 when (dockerService .getIexecOutBind (CHAIN_TASK_ID )).thenReturn (iexecOutBind );
230- when (workerConfigService .getTaskOutputDir (CHAIN_TASK_ID )).thenReturn (output );
231- when (workerConfigService .getTaskIexecOutDir (CHAIN_TASK_ID )).thenReturn (iexecOut );
232227 when (workerConfigService .getWorkerName ()).thenReturn (WORKER_NAME );
233228 when (workerConfigService .getDockerNetworkName ()).thenReturn (lasNetworkName );
234229 DockerRunResponse expectedDockerRunResponse = DockerRunResponse
@@ -276,9 +271,10 @@ void shouldNotRunTeePostComputeSinceDockerImageNotFoundLocally() {
276271 .datasetUri (DATASET_URI )
277272 .maxExecutionTime (MAX_EXECUTION_TIME )
278273 .build ();
274+ when (dockerService .getClient ()).thenReturn (dockerClientInstanceMock );
275+ when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (properties );
276+ when (properties .getPostComputeProperties ()).thenReturn (postComputeProperties );
279277 when (postComputeProperties .getImage ()).thenReturn (TEE_POST_COMPUTE_IMAGE );
280- when (postComputeProperties .getHeapSizeInBytes ()).thenReturn (TEE_POST_COMPUTE_HEAP );
281- when (postComputeProperties .getEntrypoint ()).thenReturn (TEE_POST_COMPUTE_ENTRYPOINT );
282278 when (dockerClientInstanceMock .isImagePresent (TEE_POST_COMPUTE_IMAGE ))
283279 .thenReturn (false );
284280
@@ -298,17 +294,18 @@ void shouldRunTeePostComputeWithFailDockerResponse(Map.Entry<Integer, ReplicateS
298294 .maxExecutionTime (MAX_EXECUTION_TIME )
299295 .build ();
300296 List <String > env = Arrays .asList ("var0" , "var1" );
297+ when (dockerService .getClient ()).thenReturn (dockerClientInstanceMock );
298+ when (teeServicesManager .getTeeService (any ())).thenReturn (teeMockedService );
299+ when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (properties );
300+ when (properties .getPostComputeProperties ()).thenReturn (postComputeProperties );
301301 when (postComputeProperties .getImage ()).thenReturn (TEE_POST_COMPUTE_IMAGE );
302- when (postComputeProperties .getHeapSizeInBytes ()).thenReturn (TEE_POST_COMPUTE_HEAP );
303302 when (postComputeProperties .getEntrypoint ()).thenReturn (TEE_POST_COMPUTE_ENTRYPOINT );
304303 when (dockerClientInstanceMock .isImagePresent (TEE_POST_COMPUTE_IMAGE ))
305304 .thenReturn (true );
306305 when (teeMockedService .buildPostComputeDockerEnv (taskDescription , SECURE_SESSION ))
307306 .thenReturn (env );
308307 String iexecOutBind = iexecOut + ":" + IexecFileHelper .SLASH_IEXEC_OUT ;
309308 when (dockerService .getIexecOutBind (CHAIN_TASK_ID )).thenReturn (iexecOutBind );
310- when (workerConfigService .getTaskOutputDir (CHAIN_TASK_ID )).thenReturn (output );
311- when (workerConfigService .getTaskIexecOutDir (CHAIN_TASK_ID )).thenReturn (iexecOut );
312309 when (workerConfigService .getWorkerName ()).thenReturn (WORKER_NAME );
313310 when (workerConfigService .getDockerNetworkName ()).thenReturn ("lasNetworkName" );
314311 DockerRunResponse expectedDockerRunResponse =
@@ -318,8 +315,11 @@ void shouldRunTeePostComputeWithFailDockerResponse(Map.Entry<Integer, ReplicateS
318315 .build ();
319316 when (dockerService .run (any ())).thenReturn (expectedDockerRunResponse );
320317 when (sgxService .getSgxDriverMode ()).thenReturn (SgxDriverMode .LEGACY );
321- when (computeExitCauseService .getExitCausesAndPruneForGivenComputeStage (CHAIN_TASK_ID , ComputeStage .POST , POST_COMPUTE_FAILED_UNKNOWN_ISSUE ))
322- .thenReturn (List .of (exitCodeKeyToExpectedCauseValue .getValue ()));
318+ // Only stub computeExitCauseService for exitCode == 1
319+ if (exitCodeKeyToExpectedCauseValue .getKey () == 1 ) {
320+ when (computeExitCauseService .getExitCausesAndPruneForGivenComputeStage (CHAIN_TASK_ID , ComputeStage .POST , POST_COMPUTE_FAILED_UNKNOWN_ISSUE ))
321+ .thenReturn (List .of (exitCodeKeyToExpectedCauseValue .getValue ()));
322+ }
323323
324324 PostComputeResponse postComputeResponse =
325325 postComputeService .runTeePostCompute (taskDescription , SECURE_SESSION );
@@ -346,15 +346,17 @@ void shouldNotRunTeePostComputeSinceTimeout() {
346346 .maxExecutionTime (MAX_EXECUTION_TIME )
347347 .build ();
348348 List <String > env = Arrays .asList ("var0" , "var1" );
349+ when (dockerService .getClient ()).thenReturn (dockerClientInstanceMock );
350+ when (teeServicesManager .getTeeService (any ())).thenReturn (teeMockedService );
351+ when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (properties );
352+ when (properties .getPostComputeProperties ()).thenReturn (postComputeProperties );
349353 when (postComputeProperties .getImage ()).thenReturn (TEE_POST_COMPUTE_IMAGE );
350- when (postComputeProperties .getHeapSizeInBytes ()).thenReturn (TEE_POST_COMPUTE_HEAP );
351354 when (postComputeProperties .getEntrypoint ()).thenReturn (TEE_POST_COMPUTE_ENTRYPOINT );
352355 when (dockerClientInstanceMock .isImagePresent (TEE_POST_COMPUTE_IMAGE ))
353356 .thenReturn (true );
354357 when (teeMockedService .buildPostComputeDockerEnv (taskDescription , SECURE_SESSION ))
355358 .thenReturn (env );
356359 when (dockerService .getIexecOutBind (CHAIN_TASK_ID )).thenReturn ("/iexec_out:/iexec_out" );
357- when (workerConfigService .getTaskOutputDir (CHAIN_TASK_ID )).thenReturn (output );
358360 when (workerConfigService .getWorkerName ()).thenReturn (WORKER_NAME );
359361 when (workerConfigService .getDockerNetworkName ()).thenReturn ("lasNetworkName" );
360362 DockerRunResponse expectedDockerRunResponse =
0 commit comments