use of org.apache.distributedlog.api.namespace.Namespace in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testRegisterFunctionFailure.
@Test
public void testRegisterFunctionFailure() 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(false);
RequestResult rr = new RequestResult().setSuccess(false).setMessage("function failed to register");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
Response response = registerDefaultFunction();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(new ErrorData(rr.getMessage()).reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testRegisterFunctionInterrupted.
@Test
public void testRegisterFunctionInterrupted() 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(false);
CompletableFuture<RequestResult> requestResult = FutureUtil.failedFuture(new IOException("Function registeration interrupted"));
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
Response response = registerDefaultFunction();
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
assertEquals(new ErrorData("Function registeration interrupted").reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class Util method main.
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage : Util <src> <target>");
System.err.println("");
System.err.println("NOTE: <src>/<target> can be either a file path or a dlog stream");
Runtime.getRuntime().exit(-1);
return;
}
String srcPath = args[0];
String destPath = args[1];
Namespace srcNs = null;
Namespace destNs = null;
InputStream is = null;
OutputStream os = null;
try {
if (srcPath.startsWith("distributedlog")) {
URI srcUri = URI.create(srcPath);
Pair<URI, String> parentAndName = getParentURI(srcUri);
srcNs = openNamespace(parentAndName.first);
is = openInputStream(srcNs, parentAndName.second);
} else {
is = new FileInputStream(destPath);
}
if (destPath.startsWith("distributedlog")) {
URI destUri = URI.create(srcPath);
Pair<URI, String> parentAndName = getParentURI(destUri);
destNs = openNamespace(parentAndName.first);
os = openOutputStream(destNs, parentAndName.second);
} else {
os = new FileOutputStream(destPath);
}
copyStream(is, os);
} finally {
if (null != is) {
is.close();
}
if (null != os) {
os.close();
}
if (null != srcNs) {
srcNs.close();
}
if (null != destNs) {
destNs.close();
}
}
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogUploaderTest method testInitialize.
@Test
public void testInitialize() throws Exception {
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
uploader.initialize(config);
assertEquals(config, uploader.getConfig());
assertEquals(DL_URI, uploader.getDestTopologyNamespaceURI());
assertEquals(Context.topologyPackageFile(config), uploader.getTopologyPackageLocation());
assertEquals(URI.create(String.format("%s/%s", DL_URI, uploader.getPackageName())), uploader.getPackageURI());
}
use of org.apache.distributedlog.api.namespace.Namespace in project incubator-heron by apache.
the class DlogUploaderTest method testUndoFailure.
@Test
public void testUndoFailure() throws Exception {
Namespace ns = mock(Namespace.class);
when(nsBuilder.build()).thenReturn(ns);
Mockito.doThrow(new IOException("test")).when(ns).deleteLog(anyString());
uploader.initialize(config);
assertFalse(uploader.undo());
verify(ns, times(1)).deleteLog(eq(uploader.getPackageName()));
}
Aggregations