Search in sources :

Example 1 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getRawShouldThrowException.

@Test
public void getRawShouldThrowException() throws Exception {
    Path path = new Path("./target");
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    when(fileSystem.exists(path)).thenReturn(true);
    doReturn(path).when(pcapService).getPath("user", "jobId", 1);
    when(fileSystem.open(path)).thenThrow(new IOException("some exception"));
    RestException e = assertThrows(RestException.class, () -> pcapService.getRawPcap("user", "jobId", 1));
    assertEquals("some exception", e.getMessage());
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) RestException(org.apache.metron.rest.RestException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 2 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getPdmlShouldReturnNullOnNonexistentPath.

@Test
public void getPdmlShouldReturnNullOnNonexistentPath() throws Exception {
    Path path = new Path("/some/path");
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    when(fileSystem.exists(path)).thenReturn(false);
    doReturn(path).when(pcapService).getPath("user", "jobId", 1);
    assertNull(pcapService.getPdml("user", "jobId", 1));
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.jupiter.api.Test)

Example 3 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getRawShouldReturnNullOnInvalidPage.

@Test
public void getRawShouldReturnNullOnInvalidPage() throws Exception {
    Path path = new Path("/some/path");
    PcapServiceImpl pcapService = spy(new PcapServiceImpl(environment, configuration, new PcapJobSupplier(), new InMemoryJobManager<>(), pcapToPdmlScriptWrapper));
    FileSystem fileSystem = mock(FileSystem.class);
    doReturn(fileSystem).when(pcapService).getFileSystem();
    assertNull(pcapService.getRawPcap("user", "jobId", 1));
}
Also used : Path(org.apache.hadoop.fs.Path) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.junit.jupiter.api.Test)

Example 4 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getStatusShouldThrowRestException.

@Test
public void getStatusShouldThrowRestException() 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.getJobStatus("user", "jobId"));
    assertEquals("some job exception", e.getMessage());
}
Also used : MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) RestException(org.apache.metron.rest.RestException) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Example 5 with PcapJobSupplier

use of org.apache.metron.rest.config.PcapJobSupplier in project metron by apache.

the class PcapServiceImplTest method getPathShouldReturnNullOnInvalidPageSize.

@Test
public void getPathShouldReturnNullOnInvalidPageSize() throws Exception {
    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(jobManager.getJob("user", "jobId")).thenReturn(mockPcapJob);
    assertNull(pcapService.getPath("user", "jobId", 0));
    assertNull(pcapService.getPath("user", "jobId", 3));
}
Also used : MockPcapJob(org.apache.metron.rest.mock.MockPcapJob) MockPcapJobSupplier(org.apache.metron.rest.mock.MockPcapJobSupplier) PcapJobSupplier(org.apache.metron.rest.config.PcapJobSupplier) InMemoryJobManager(org.apache.metron.job.manager.InMemoryJobManager) JobManager(org.apache.metron.job.manager.JobManager) Test(org.junit.jupiter.api.Test)

Aggregations

InMemoryJobManager (org.apache.metron.job.manager.InMemoryJobManager)13 PcapJobSupplier (org.apache.metron.rest.config.PcapJobSupplier)13 MockPcapJobSupplier (org.apache.metron.rest.mock.MockPcapJobSupplier)13 Test (org.junit.jupiter.api.Test)13 FileSystem (org.apache.hadoop.fs.FileSystem)8 Path (org.apache.hadoop.fs.Path)8 JobManager (org.apache.metron.job.manager.JobManager)6 RestException (org.apache.metron.rest.RestException)5 IOException (java.io.IOException)2 MockPcapJob (org.apache.metron.rest.mock.MockPcapJob)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1