Search in sources :

Example 16 with Namespace

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);
}
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) 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)

Example 17 with Namespace

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);
}
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)

Example 18 with Namespace

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();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) URI(java.net.URI) Namespace(org.apache.distributedlog.api.namespace.Namespace) FileInputStream(java.io.FileInputStream)

Example 19 with Namespace

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

Example 20 with Namespace

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

Aggregations

Namespace (org.apache.distributedlog.api.namespace.Namespace)50 Test (org.junit.Test)31 URI (java.net.URI)26 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 InputStream (java.io.InputStream)12 IOException (java.io.IOException)10 Response (javax.ws.rs.core.Response)8 Test (org.testng.annotations.Test)8 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)6 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)6 AsyncLogReader (org.apache.distributedlog.api.AsyncLogReader)5 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)5 LogWriter (org.apache.distributedlog.api.LogWriter)5 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)5 DLSN (org.apache.distributedlog.DLSN)4 DistributedLogConfiguration (org.apache.distributedlog.DistributedLogConfiguration)4 Matchers.anyString (org.mockito.Matchers.anyString)4 DLInputStream (com.twitter.heron.dlog.DLInputStream)3 OutputStream (java.io.OutputStream)3