Search in sources :

Example 61 with Namespace

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();
}
Also used : Path(java.nio.file.Path) DistributedLogConfiguration(org.apache.distributedlog.DistributedLogConfiguration) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) EndOfStreamException(org.apache.distributedlog.exceptions.EndOfStreamException) DLInputStream(org.apache.heron.dlog.DLInputStream) InputStream(java.io.InputStream) LogReader(org.apache.distributedlog.api.LogReader) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) File(java.io.File) Namespace(org.apache.distributedlog.api.namespace.Namespace) NamespaceBuilder(org.apache.distributedlog.api.namespace.NamespaceBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 62 with Namespace

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"));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Namespace(org.apache.distributedlog.api.namespace.Namespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 63 with Namespace

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"));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Namespace(org.apache.distributedlog.api.namespace.Namespace) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 64 with Namespace

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();
}
Also used : Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 65 with Namespace

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()));
}
Also used : Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Aggregations

Namespace (org.apache.distributedlog.api.namespace.Namespace)66 Test (org.junit.Test)43 URI (java.net.URI)30 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 InputStream (java.io.InputStream)16 IOException (java.io.IOException)12 Response (javax.ws.rs.core.Response)8 Matchers.anyString (org.mockito.Matchers.anyString)8 Test (org.testng.annotations.Test)8 OutputStream (java.io.OutputStream)6 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)6 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)6 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)5 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)5 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)5 LogReader (org.apache.distributedlog.api.LogReader)5 LogWriter (org.apache.distributedlog.api.LogWriter)5 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)5 File (java.io.File)4