use of org.apache.distributedlog.api.namespace.Namespace in project heron by twitter.
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();
}
use of org.apache.distributedlog.api.namespace.Namespace in project heron by twitter.
the class DlogStorageTest method testDiposePartial.
@Test
public void testDiposePartial() throws Exception {
Namespace mockTopoloyNs = mock(Namespace.class);
Namespace mockCheckpoint1 = mock(Namespace.class);
Namespace mockCheckpoint2 = mock(Namespace.class);
String checkpoint1 = "checkpoint1";
String checkpoint2 = "checkpoint2";
List<String> checkpoints = Lists.newArrayList(checkpoint1, checkpoint2);
List<String> chkp1Tasks = Lists.newArrayList("component1_task1", "component1_task2");
List<String> chkp2Tasks = Lists.newArrayList("component2_task1", "component2_task2");
doReturn(mockTopoloyNs).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME)));
doReturn(mockCheckpoint1).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint1")));
doReturn(mockCheckpoint2).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint2")));
when(mockTopoloyNs.getLogs()).thenReturn(checkpoints.iterator());
when(mockCheckpoint1.getLogs()).thenReturn(chkp1Tasks.iterator());
when(mockCheckpoint2.getLogs()).thenReturn(chkp2Tasks.iterator());
dlogStorage.dispose("checkpoint2", false);
verify(mockCheckpoint1, times(1)).deleteLog(eq("component1_task1"));
verify(mockCheckpoint1, times(1)).deleteLog(eq("component1_task2"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task1"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task2"));
}
use of org.apache.distributedlog.api.namespace.Namespace in project heron by twitter.
the class DlogStorageTest method testDiposeNone.
@Test
public void testDiposeNone() throws Exception {
Namespace mockTopoloyNs = mock(Namespace.class);
Namespace mockCheckpoint1 = mock(Namespace.class);
Namespace mockCheckpoint2 = mock(Namespace.class);
String checkpoint1 = "checkpoint1";
String checkpoint2 = "checkpoint2";
List<String> checkpoints = Lists.newArrayList(checkpoint1, checkpoint2);
List<String> chkp1Tasks = Lists.newArrayList("component1_task1", "component1_task2");
List<String> chkp2Tasks = Lists.newArrayList("component2_task1", "component2_task2");
doReturn(mockTopoloyNs).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME)));
doReturn(mockCheckpoint1).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint1")));
doReturn(mockCheckpoint2).when(dlogStorage).initializeNamespace(eq(URI.create(ROOT_URI + "/" + StatefulStorageTestContext.TOPOLOGY_NAME + "/checkpoint2")));
when(mockTopoloyNs.getLogs()).thenReturn(checkpoints.iterator());
when(mockCheckpoint1.getLogs()).thenReturn(chkp1Tasks.iterator());
when(mockCheckpoint2.getLogs()).thenReturn(chkp2Tasks.iterator());
dlogStorage.dispose("checkpoint0", false);
verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task1"));
verify(mockCheckpoint1, times(0)).deleteLog(eq("component1_task2"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task1"));
verify(mockCheckpoint2, times(0)).deleteLog(eq("component2_task2"));
}
use of org.apache.distributedlog.api.namespace.Namespace in project heron by twitter.
the class DlogUploaderTest method testClose.
@Test
public void testClose() throws Exception {
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
uploader.initialize(config);
uploader.close();
verify(ns, times(1)).close();
}
use of org.apache.distributedlog.api.namespace.Namespace in project heron by twitter.
the class DlogUploaderTest method testUndoSuccess.
@Test
public void testUndoSuccess() throws Exception {
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
uploader.initialize(config);
assertTrue(uploader.undo());
verify(ns, times(1)).deleteLog(eq(uploader.getPackageName()));
}
Aggregations