use of org.apache.metron.rest.mock.MockPcapJob 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.rest.mock.MockPcapJob 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);
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapServiceImplTest method getConfigurationShouldProperlyReturnFixedFilterConfiguration.
@Test
public void getConfigurationShouldProperlyReturnFixedFilterConfiguration() throws Exception {
FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
fixedPcapRequest.setBasePath("basePath");
fixedPcapRequest.setBaseInterimResultPath("baseOutputPath");
fixedPcapRequest.setFinalOutputPath("finalOutputPath");
fixedPcapRequest.setStartTimeMs(1L);
fixedPcapRequest.setEndTimeMs(2L);
fixedPcapRequest.setNumReducers(2);
fixedPcapRequest.setIpSrcAddr("ip_src_addr");
fixedPcapRequest.setIpDstAddr("ip_dst_addr");
fixedPcapRequest.setIpSrcPort(1000);
fixedPcapRequest.setIpDstPort(2000);
fixedPcapRequest.setProtocol("tcp");
fixedPcapRequest.setPacketFilter("filter");
fixedPcapRequest.setIncludeReverse(true);
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"));
pcapService.submit("user", fixedPcapRequest);
Map<String, Object> configuration = pcapService.getConfiguration("user", "jobId");
assertEquals("basePath", configuration.get(PcapOptions.BASE_PATH.getKey()));
assertEquals("finalOutputPath", configuration.get(PcapOptions.FINAL_OUTPUT_PATH.getKey()));
assertEquals(1L, configuration.get(PcapOptions.START_TIME_MS.getKey()));
assertEquals(2L, configuration.get(PcapOptions.END_TIME_MS.getKey()));
assertEquals(2, configuration.get(PcapOptions.NUM_REDUCERS.getKey()));
assertEquals("ip_src_addr", configuration.get(FixedPcapOptions.IP_SRC_ADDR.getKey()));
assertEquals("ip_dst_addr", configuration.get(FixedPcapOptions.IP_DST_ADDR.getKey()));
assertEquals(1000, configuration.get(FixedPcapOptions.IP_SRC_PORT.getKey()));
assertEquals(2000, configuration.get(FixedPcapOptions.IP_DST_PORT.getKey()));
assertEquals("tcp", configuration.get(FixedPcapOptions.PROTOCOL.getKey()));
assertEquals("filter", configuration.get(FixedPcapOptions.PACKET_FILTER.getKey()));
assertEquals(true, configuration.get(FixedPcapOptions.INCLUDE_REVERSE.getKey()));
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapServiceImplTest method submitShouldProperlySubmitWithDefaults.
@Test
public void submitShouldProperlySubmitWithDefaults() throws Exception {
long beforeJobTime = System.currentTimeMillis();
FixedPcapRequest fixedPcapRequest = new FixedPcapRequest();
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));
PcapStatus expectedPcapStatus = new PcapStatus();
expectedPcapStatus.setJobId("jobId");
expectedPcapStatus.setJobStatus(JobStatus.State.RUNNING.name());
expectedPcapStatus.setDescription("description");
assertEquals(expectedPcapStatus, pcapService.submit("user", fixedPcapRequest));
assertEquals("/base/path", mockPcapJob.getBasePath());
assertEquals("/base/interim/result/path", mockPcapJob.getBaseInterrimResultPath());
assertEquals("/final/output/path", mockPcapJob.getFinalOutputPath());
assertEquals(0, mockPcapJob.getStartTimeNs());
assertTrue(beforeJobTime <= mockPcapJob.getEndTimeNs() / 1000000);
assertTrue(System.currentTimeMillis() >= mockPcapJob.getEndTimeNs() / 1000000);
assertEquals(10, mockPcapJob.getNumReducers());
assertEquals(100, mockPcapJob.getRecPerFile());
assertTrue(mockPcapJob.getFilterImpl() instanceof FixedPcapFilter.Configurator);
assertEquals(new HashMap<>(), mockPcapJob.getFixedFields());
}
use of org.apache.metron.rest.mock.MockPcapJob in project metron by apache.
the class PcapServiceImplTest method getPathShouldProperlyReturnPath.
@Test
public void getPathShouldProperlyReturnPath() throws Exception {
Path actualPath = new Path("/path");
MockPcapJob mockPcapJob = mock(MockPcapJob.class);
JobManager jobManager = mock(JobManager.class);
Pageable pageable = mock(Pageable.class);
PcapServiceImpl pcapService = new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), jobManager, pcapToPdmlScriptWrapper);
when(pageable.getSize()).thenReturn(2);
when(mockPcapJob.isDone()).thenReturn(true);
when(mockPcapJob.get()).thenReturn(pageable);
when(pageable.getPage(0)).thenReturn(actualPath);
when(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob);
assertEquals("/path", pcapService.getPath("user", "jobId", 1).toUri().getPath());
}
Aggregations