@Override
  public Job cancelJob(String project, String region, String jobId) {
    LOG.info("Cancelling {} under {}", jobId, project);
    Job job = new Job().setRequestedState(JobState.CANCELLED.toString());
    LOG.info("Sending job to update {}:\n{}", jobId, formatForLogging(job));
    return Failsafe.with(clientRetryPolicy())
        .get(
            () ->
                client.projects().locations().jobs().update(project, region, jobId, job).execute());
  }
@Test
  public void testCancelJob() throws IOException {
    Update update = mock(Update.class);
    when(getLocationJobs(client).update(any(), any(), any(), any()))
        .thenThrow(new IOException("Connection reset"))
        .thenThrow(new SocketTimeoutException("Read timed out"))
        .thenReturn(update);
    when(update.execute()).thenThrow(new IOException("Connection reset")).thenReturn(new Job());

    new FakePipelineLauncher(client).cancelJob(PROJECT, REGION, JOB_ID);

    verify(getLocationJobs(client), times(4))
        .update(
            projectCaptor.capture(),
            regionCaptor.capture(),
            jobIdCaptor.capture(),
            jobCaptor.capture());
    assertThat(projectCaptor.getValue()).isEqualTo(PROJECT);
    assertThat(regionCaptor.getValue()).isEqualTo(REGION);
    assertThat(jobIdCaptor.getValue()).isEqualTo(JOB_ID);
    assertThat(jobCaptor.getValue().getRequestedState()).isEqualTo(JobState.CANCELLED.toString());
  }