Search in sources :

Example 21 with JobStatus

use of org.apache.metron.job.JobStatus in project metron by apache.

the class PcapJobTest method job_reports_percent_complete.

@Test
public void job_reports_percent_complete() throws Exception {
    when(mrJob.isComplete()).thenReturn(false);
    when(mrStatus.getState()).thenReturn(org.apache.hadoop.mapreduce.JobStatus.State.RUNNING);
    when(mrJob.getStatus()).thenReturn(mrStatus);
    when(mrJob.mapProgress()).thenReturn(0.5f);
    when(mrJob.reduceProgress()).thenReturn(0f);
    Statusable<Path> statusable = testJob.submit(finalizer, config);
    timer.updateJobStatus();
    JobStatus status = statusable.getStatus();
    assertThat(status.getState(), equalTo(State.RUNNING));
    assertThat(status.getDescription(), equalTo("map: 50.0%, reduce: 0.0%"));
    assertThat(status.getPercentComplete(), equalTo(25.0 * 0.75));
    when(mrJob.mapProgress()).thenReturn(1.0f);
    when(mrJob.reduceProgress()).thenReturn(0.5f);
    timer.updateJobStatus();
    status = statusable.getStatus();
    assertThat(status.getDescription(), equalTo("map: 100.0%, reduce: 50.0%"));
    assertThat(status.getPercentComplete(), equalTo(75.0 * 0.75));
    when(mrJob.mapProgress()).thenReturn(1.0f);
    when(mrJob.reduceProgress()).thenReturn(1.0f);
    timer.updateJobStatus();
    status = statusable.getStatus();
    assertThat(status.getDescription(), equalTo("map: 100.0%, reduce: 100.0%"));
    assertThat(status.getPercentComplete(), equalTo(75.0));
    when(mrJob.isComplete()).thenReturn(true);
    when(mrStatus.getState()).thenReturn(org.apache.hadoop.mapreduce.JobStatus.State.SUCCEEDED);
    when(mrJob.mapProgress()).thenReturn(1.0f);
    when(mrJob.reduceProgress()).thenReturn(1.0f);
    timer.updateJobStatus();
    status = statusable.getStatus();
    assertThat(status.getDescription(), equalTo("Job completed."));
    assertThat(status.getPercentComplete(), equalTo(100.0));
}
Also used : Path(org.apache.hadoop.fs.Path) JobStatus(org.apache.metron.job.JobStatus) Test(org.junit.jupiter.api.Test)

Aggregations

JobStatus (org.apache.metron.job.JobStatus)21 Test (org.junit.jupiter.api.Test)18 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 Path (org.apache.hadoop.fs.Path)10 PcapPages (org.apache.metron.pcap.PcapPages)5 IOException (java.io.IOException)3 JobException (org.apache.metron.job.JobException)3 FixedPcapFilter (org.apache.metron.pcap.filter.fixed.FixedPcapFilter)2 File (java.io.File)1 QueryPcapFilter (org.apache.metron.pcap.filter.query.QueryPcapFilter)1 RestException (org.apache.metron.rest.RestException)1 PcapStatus (org.apache.metron.rest.model.pcap.PcapStatus)1