use of org.apache.metron.job.manager.JobManager in project metron by apache.
the class PcapServiceImplTest method submitShouldProperlySubmitQueryPcapRequest.
@Test
public void submitShouldProperlySubmitQueryPcapRequest() throws Exception {
QueryPcapRequest queryPcapRequest = new QueryPcapRequest();
queryPcapRequest.setBasePath("basePath");
queryPcapRequest.setBaseInterimResultPath("baseOutputPath");
queryPcapRequest.setFinalOutputPath("finalOutputPath");
queryPcapRequest.setStartTimeMs(1L);
queryPcapRequest.setEndTimeMs(2L);
queryPcapRequest.setNumReducers(2);
queryPcapRequest.setQuery("query");
MockPcapJob mockPcapJob = new MockPcapJob();
mockPcapJobSupplier.setMockPcapJob(mockPcapJob);
JobManager jobManager = new InMemoryJobManager<>();
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
mockPcapJob.setStatus(new JobStatus().withJobId("jobId").withDescription("description").withPercentComplete(0L).withState(JobStatus.State.RUNNING));
String expectedFields = "query";
PcapStatus expectedPcapStatus = new PcapStatus();
expectedPcapStatus.setJobId("jobId");
expectedPcapStatus.setJobStatus(JobStatus.State.RUNNING.name());
expectedPcapStatus.setDescription("description");
assertEquals(expectedPcapStatus, pcapService.submit("user", queryPcapRequest));
assertEquals(expectedPcapStatus, pcapService.jobStatusToPcapStatus(jobManager.getJob("user", "jobId").getStatus()));
assertEquals("basePath", mockPcapJob.getBasePath());
assertEquals("baseOutputPath", mockPcapJob.getBaseInterrimResultPath());
assertEquals("finalOutputPath", mockPcapJob.getFinalOutputPath());
assertEquals(1000000, mockPcapJob.getStartTimeNs());
assertEquals(2000000, mockPcapJob.getEndTimeNs());
assertEquals(2, mockPcapJob.getNumReducers());
assertEquals(100, mockPcapJob.getRecPerFile());
assertTrue(mockPcapJob.getFilterImpl() instanceof QueryPcapFilter.Configurator);
Map<String, String> actualFixedFields = mockPcapJob.getFixedFields();
assertEquals("query", mockPcapJob.getQuery());
}
use of org.apache.metron.job.manager.JobManager in project metron by apache.
the class PcapServiceImplTest method fixedShouldThrowRestException.
@Test
public void fixedShouldThrowRestException() throws Exception {
FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
JobManager jobManager = mock(JobManager.class);
PcapJobSupplier pcapJobSupplier = new PcapJobSupplier();
PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, pcapJobSupplier, jobManager, pcapToPdmlScriptWrapper));
FileSystem fileSystem = mock(FileSystem.class);
doReturn(fileSystem).when(pcapService).getFileSystem();
when(jobManager.submit(pcapJobSupplier, "user")).thenThrow(new JobException("some job exception"));
RestException e = assertThrows(RestException.class, () -> pcapService.submit("user", fixedPcapRequest));
assertEquals("some job exception", e.getMessage());
}
use of org.apache.metron.job.manager.JobManager in project metron by apache.
the class PcapServiceImplTest method getConfigurationShouldThrowRestException.
@Test
public void getConfigurationShouldThrowRestException() throws Exception {
JobManager jobManager = mock(JobManager.class);
when(jobManager.getJob("user", "jobId")).thenThrow(new JobException("some job exception"));
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper);
RestException e = assertThrows(RestException.class, () -> pcapService.getConfiguration("user", "jobId"));
assertEquals("some job exception", e.getMessage());
}
use of org.apache.metron.job.manager.JobManager in project metron by apache.
the class PcapServiceImplTest method killJobShouldKillJobAndReportStatus.
@Test
public void killJobShouldKillJobAndReportStatus() throws Exception {
MockPcapJob mockPcapJob = mock(MockPcapJob.class);
JobManager jobManager = mock(JobManager.class);
JobStatus actualJobStatus = new JobStatus().withJobId("jobId").withState(JobStatus.State.KILLED).withDescription("description").withPercentComplete(100.0);
Pageable pageable = mock(Pageable.class);
when(pageable.getSize()).thenReturn(0);
when(mockPcapJob.getStatus()).thenReturn(actualJobStatus);
when(mockPcapJob.isDone()).thenReturn(true);
when(mockPcapJob.get()).thenReturn(pageable);
when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob);
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper);
PcapStatus status = pcapService.killJob("user", "jobId");
verify(jobManager, times(1)).killJob("user", "jobId");
assertThat(status.getJobStatus(), CoreMatchers.equalTo(JobStatus.State.KILLED.toString()));
}
use of org.apache.metron.job.manager.JobManager in project metron by apache.
the class PcapServiceImplTest method killNonExistentJobShouldReturnNull.
@Test
public void killNonExistentJobShouldReturnNull() throws Exception {
MockPcapJob mockPcapJob = mock(MockPcapJob.class);
JobManager jobManager = mock(JobManager.class);
doThrow(new JobNotFoundException("Not found test exception.")).when(jobManager).killJob("user", "jobId");
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, mockPcapJobSupplier, jobManager, pcapToPdmlScriptWrapper);
PcapStatus status = pcapService.killJob("user", "jobId");
verify(jobManager, times(1)).killJob("user", "jobId");
assertNull(status);
}
Aggregations