Skip to content

Instantly share code, notes, and snippets.

@Romeh
Created Dec 18, 2017
Embed
What would you like to do?
@Test
public void testMapReducedJobsWithFailFastSync(){
// example of ignite jobs, first one succeeded , second fail, third succeeded , but the reducer will fail fast once he collect the failed job
IgniteCallable validationServiceJob1=() -> ServiceResponse.<String>builder().response("Job 1 is valid").serviceOrigin("job1")
.success(true).build();
IgniteCallable validationServiceJob2=() -> ServiceResponse.<String>builder().response("Job 2 is failed").serviceOrigin("job2")
.success(false).build();
IgniteCallable validationServiceJob3=() -> ServiceResponse.<String>builder().response("Job 3 is valid").serviceOrigin("job3")
.success(true).build();
final MapReduceResponse mapReduceResponse = computeService.validateWithAllServicesInParallelSync(
Arrays.asList(validationServiceJob1,validationServiceJob2,validationServiceJob3)
);
boolean status=true;
for(ServiceResponse serviceResponse: mapReduceResponse.getReducedResponses().values()){
status=status && serviceResponse.isSuccess();
}
// make sure the aggregated status is failed
assertEquals(status,false);
assertEquals(mapReduceResponse.isSuccess(),false);
}
@Test
public void testMapReducedJobsWithFailFastSyncFirstAllSuccess(){
// example of ignite jobs, all succeeded , so the reducer collect all and return successfully
IgniteCallable validationServiceJob1=() -> ServiceResponse.<String>builder().serviceOrigin("job1")
.response("Job 1 is valid").success(true).build();
IgniteCallable validationServiceJob2=() -> ServiceResponse.<String>builder().serviceOrigin("job2")
.response("Job 2 is valid").success(true).build();
IgniteCallable validationServiceJob3=() -> ServiceResponse.<String>builder().serviceOrigin("job3")
.response("Job 3 is valid").success(true).build();
final MapReduceResponse mapReduceResponse = computeService.validateWithAllServicesInParallelSync(
Arrays.asList(validationServiceJob1,validationServiceJob2,validationServiceJob3)
);
boolean status=true;
for(ServiceResponse serviceResponse: mapReduceResponse.getReducedResponses().values()){
status=status && serviceResponse.isSuccess();
}
// make sure the aggregated status is success
assertEquals(status,true);
assertEquals(mapReduceResponse.isSuccess(),true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment