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();
}
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"));
}
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"));
}
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());
}
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);
}
Aggregations