Search in sources :

Example 1 with ExamReport

use of org.openkilda.testing.service.traffexam.model.ExamReport in project open-kilda by telstra.

the class StubServiceFactory method getTraffExamStub.

/**
 * Get a stub for {@link TraffExamService}. The instance is tied to the factory state.
 */
public TraffExamService getTraffExamStub() {
    TraffExamService serviceMock = mock(TraffExamService.class);
    when(serviceMock.hostByName(any())).thenAnswer(invocation -> {
        String hostName = (String) invocation.getArguments()[0];
        Host host = mock(Host.class);
        when(host.getName()).thenReturn(hostName);
        return host;
    });
    when(serviceMock.waitExam(any())).thenAnswer(invocation -> {
        Exam exam = (Exam) invocation.getArguments()[0];
        ExamReport report = mock(ExamReport.class);
        when(report.hasError()).thenReturn(false);
        when(report.hasTraffic()).thenReturn(flows.containsKey(exam.getFlow().getId()));
        when(report.getBandwidth()).thenReturn(new Bandwidth(exam.getFlow().getMaximumBandwidth()));
        return report;
    });
    return serviceMock;
}
Also used : TraffExamService(org.openkilda.testing.service.traffexam.TraffExamService) Bandwidth(org.openkilda.testing.service.traffexam.model.Bandwidth) ExamReport(org.openkilda.testing.service.traffexam.model.ExamReport) Host(org.openkilda.testing.service.traffexam.model.Host) Exam(org.openkilda.testing.service.traffexam.model.Exam)

Example 2 with ExamReport

use of org.openkilda.testing.service.traffexam.model.ExamReport in project open-kilda by telstra.

the class TraffExamServiceImpl method fetchReport.

@Override
public ExamReport fetchReport(Exam exam) throws NoResultsFoundException, ExamNotFinishedException {
    ExamResources resources = retrieveExamResources(exam);
    EndpointReport producerReport = fetchEndpointReport(resources.getProducer());
    EndpointReport consumerReport;
    try {
        consumerReport = fetchEndpointReport(resources.getConsumer());
    } catch (ExamNotFinishedException e) {
        if (producerReport.getError() == null) {
            throw e;
        }
        consumerReport = new EndpointReport("Don't wait for consumer report due to error on producer side");
    }
    return new ExamReport(exam, producerReport, consumerReport);
}
Also used : ExamResources(org.openkilda.testing.service.traffexam.model.ExamResources) ExamReport(org.openkilda.testing.service.traffexam.model.ExamReport) EndpointReport(org.openkilda.testing.service.traffexam.model.EndpointReport)

Aggregations

ExamReport (org.openkilda.testing.service.traffexam.model.ExamReport)2 TraffExamService (org.openkilda.testing.service.traffexam.TraffExamService)1 Bandwidth (org.openkilda.testing.service.traffexam.model.Bandwidth)1 EndpointReport (org.openkilda.testing.service.traffexam.model.EndpointReport)1 Exam (org.openkilda.testing.service.traffexam.model.Exam)1 ExamResources (org.openkilda.testing.service.traffexam.model.ExamResources)1 Host (org.openkilda.testing.service.traffexam.model.Host)1