Commit 3ffe6744 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Stripped protocols also from negotiated transfer result in case of error on...

Stripped protocols also from negotiated transfer result in case of error on synchronous transfer endpoint
parent c040003e
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -209,11 +209,11 @@ public class JobService {
            // Need to catch other exceptions too to avoid inconsistent job status
        } catch (VoSpaceErrorSummarizableException e) {
            job.setPhase(ExecutionPhase.ERROR);
            uriService.getTransfer(job).getProtocols().clear();
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(e));
        } catch (Exception e) {
            job.setPhase(ExecutionPhase.ERROR);
            uriService.getTransfer(job).getProtocols().clear();
            stripProtocols(job, negotiatedTransfer);
            job.setErrorSummary(ErrorSummaryFactory.newErrorSummary(
                    new InternalFaultException(e)));
        } finally {
@@ -221,6 +221,13 @@ public class JobService {
        }
    }
    
    private void stripProtocols(JobSummary job, Transfer negotiatedTransfer) {
        uriService.getTransfer(job).getProtocols().clear();
        if (negotiatedTransfer != null) {
            negotiatedTransfer.getProtocols().clear();
        }
    }

    private void setJobResults(JobSummary jobSummary, Transfer transfer) {
        String baseUrl = servletRequest.getRequestURL().substring(0,
                servletRequest.getRequestURL().indexOf(servletRequest.getContextPath()));
+31 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ import net.ivoa.xml.uws.v1.JobSummary;
import net.ivoa.xml.vospace.v2.Protocol;
import net.ivoa.xml.vospace.v2.Transfer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -108,18 +110,42 @@ public class JobServiceTest {

    @Test
    public void testSyncJobResultVoSpaceError() {
        when(uriService.getTransfer(any())).thenReturn(getPullFromVoSpaceHttpTransfer());
        Transfer transfer = getPullFromVoSpaceHttpTransfer();
        assertFalse(transfer.getProtocols().isEmpty());
        when(uriService.getTransfer(any())).thenReturn(transfer);
        doThrow(new NodeBusyException("/foo")).when(uriService).getNegotiatedTransfer(any(), any());
        jobService.createSyncJobResult(new JobSummary());
        verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
        assertTrue(transfer.getProtocols().isEmpty());
    }

    @Test
    public void testSyncJobResultUnexpectedError() {
        when(uriService.getTransfer(any())).thenReturn(getPullFromVoSpaceHttpTransfer());
        Transfer transfer = getPullFromVoSpaceHttpTransfer();
        assertFalse(transfer.getProtocols().isEmpty());
        when(uriService.getTransfer(any())).thenReturn(transfer);
        doThrow(new NullPointerException()).when(uriService).getNegotiatedTransfer(any(), any());
        jobService.createSyncJobResult(new JobSummary());
        verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
        assertTrue(transfer.getProtocols().isEmpty());
    }

    @Test
    public void testSyncJobResultErrorAfterNegotiatedTransfer() {
        Transfer transfer = getPullFromVoSpaceHttpTransfer();
        assertFalse(transfer.getProtocols().isEmpty());
        when(uriService.getTransfer(any())).thenReturn(transfer);

        Transfer negotiatedTransfer = getPullFromVoSpaceHttpTransfer();
        assertFalse(negotiatedTransfer.getProtocols().isEmpty());
        when(uriService.getNegotiatedTransfer(any(), any())).thenReturn(negotiatedTransfer);

        doThrow(new NullPointerException()).when(servletRequest).getContextPath();
        jobService.createSyncJobResult(new JobSummary());

        verify(jobDAO, times(1)).createJob(argThat(j -> ExecutionPhase.ERROR.equals(j.getPhase())), any());
        assertTrue(transfer.getProtocols().isEmpty());
        assertTrue(negotiatedTransfer.getProtocols().isEmpty());
    }

    @Test