use of org.apache.distributedlog.api.namespace.NamespaceBuilder in project incubator-heron by apache.
the class DLDownloaderTest method testDownload.
@Test
public void testDownload() throws Exception {
String logName = "test-download";
URI uri = URI.create("distributedlog://127.0.0.1/test/distributedlog/" + logName);
File tempFile = File.createTempFile("test", "download");
// make sure it is deleted when the test completes
tempFile.deleteOnExit();
Path path = Paths.get(tempFile.toURI());
Namespace ns = mock(Namespace.class);
DistributedLogManager dlm = mock(DistributedLogManager.class);
LogReader reader = mock(LogReader.class);
when(ns.openLog(anyString())).thenReturn(dlm);
when(dlm.getInputStream(eq(DLSN.InitialDLSN))).thenReturn(reader);
when(reader.readNext(anyBoolean())).thenThrow(new EndOfStreamException("eos"));
NamespaceBuilder nsBuilder = mock(NamespaceBuilder.class);
when(nsBuilder.clientId(anyString())).thenReturn(nsBuilder);
when(nsBuilder.conf(any(DistributedLogConfiguration.class))).thenReturn(nsBuilder);
when(nsBuilder.uri(any(URI.class))).thenReturn(nsBuilder);
when(nsBuilder.build()).thenReturn(ns);
PowerMockito.mockStatic(Extractor.class);
PowerMockito.doNothing().when(Extractor.class, "extract", any(InputStream.class), any(Path.class));
DLDownloader downloader = new DLDownloader(() -> nsBuilder);
downloader.download(uri, path);
URI parentUri = URI.create("distributedlog://127.0.0.1/test/distributedlog");
verify(nsBuilder, times(1)).clientId(eq("heron-downloader"));
verify(nsBuilder, times(1)).conf(eq(CONF));
verify(nsBuilder, times(1)).uri(parentUri);
PowerMockito.verifyStatic(times(1));
Extractor.extract(any(InputStream.class), eq(path));
verify(ns, times(1)).openLog(eq(logName));
verify(ns, times(1)).close();
}
Aggregations