Search in sources :

Example 56 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogUploaderTest method testUploadPackage.

@Test
public void testUploadPackage() throws Exception {
    uploader = Mockito.spy(uploader);
    Namespace ns = mock(Namespace.class);
    when(nsBuilder.build()).thenReturn(ns);
    when(ns.logExists(anyString())).thenReturn(false);
    DistributedLogManager dlm = mock(DistributedLogManager.class);
    when(ns.openLog(anyString())).thenReturn(dlm);
    AppendOnlyStreamWriter asw = mock(AppendOnlyStreamWriter.class);
    when(dlm.getAppendOnlyStreamWriter()).thenReturn(asw);
    Mockito.doReturn(true).when(uploader).isLocalFileExists(Mockito.anyString());
    uploader.initialize(config);
    uploader.uploadPackage();
    verify(ns, never()).deleteLog(eq(uploader.getPackageName()));
    verify(copier, times(1)).copyFileToStream(eq(uploader.getTopologyPackageLocation()), any(OutputStream.class));
    verify(asw, times(1)).close();
    verify(dlm, times(1)).close();
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) OutputStream(java.io.OutputStream) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.junit.Test)

Example 57 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

the class DlogStorageTest method testDiposeAll.

@Test
public void testDiposeAll() 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(StatefulStorageTestContext.TOPOLOGY_NAME, "checkpoint0", true);
    verify(mockCheckpoint1, times(1)).deleteLog(eq("component1_task1"));
    verify(mockCheckpoint1, times(1)).deleteLog(eq("component1_task2"));
    verify(mockCheckpoint2, times(1)).deleteLog(eq("component2_task1"));
    verify(mockCheckpoint2, times(1)).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 58 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.

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(StatefulStorageTestContext.TOPOLOGY_NAME, "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 59 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testUpdateFunctionSuccess.

@Test
public void testUpdateFunctionSuccess() throws Exception {
    mockStatic(Utils.class);
    doNothing().when(Utils.class);
    Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    RequestResult rr = new RequestResult().setSuccess(true).setMessage("function registered");
    CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
    when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
    Response response = updateDefaultFunction();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) Response(javax.ws.rs.core.Response) RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) InputStream(java.io.InputStream) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 60 with Namespace

use of org.apache.distributedlog.api.namespace.Namespace in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testUpdateFunctionInterrupted.

@Test
public void testUpdateFunctionInterrupted() throws Exception {
    mockStatic(Utils.class);
    doNothing().when(Utils.class);
    Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    CompletableFuture<RequestResult> requestResult = FutureUtil.failedFuture(new IOException("Function registeration interrupted"));
    when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
    Response response = updateDefaultFunction();
    assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function registeration interrupted").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) Response(javax.ws.rs.core.Response) RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) InputStream(java.io.InputStream) IOException(java.io.IOException) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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