Search in sources :

Example 1 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testDeregisterNotExistedFunction.

@Test
public void testDeregisterNotExistedFunction() {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
    Response response = deregisterDefaultFunction();
    assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function " + function + " doesn't exist").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testUpdateNotExistedFunction.

@Test
public void testUpdateNotExistedFunction() throws IOException {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
    Response response = updateDefaultFunction();
    assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function " + function + " doesn't exist").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testRegisterFunctionUploadFailure.

@Test
public void testRegisterFunctionUploadFailure() throws Exception {
    mockStatic(Utils.class);
    doThrow(new IOException("upload failure")).when(Utils.class);
    Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
    Response response = registerDefaultFunction();
    assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("upload failure").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) 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 4 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testGetNotExistedFunction.

@Test
public void testGetNotExistedFunction() throws IOException {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
    Response response = getDefaultFunctionInfo();
    assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function " + function + " doesn't exist").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testRegisterFunctionMissingArguments.

private void testRegisterFunctionMissingArguments(String tenant, String namespace, String function, InputStream inputStream, FormDataContentDisposition details, String outputTopic, String inputTopic, String inputSerdeClassName, String outputSerdeClassName, String className, Integer parallelism, String missingFieldName) throws IOException {
    FunctionConfig.Builder functionConfigBuilder = FunctionConfig.newBuilder();
    if (tenant != null) {
        functionConfigBuilder.setTenant(tenant);
    }
    if (namespace != null) {
        functionConfigBuilder.setNamespace(namespace);
    }
    if (function != null) {
        functionConfigBuilder.setName(function);
    }
    if (outputTopic != null) {
        functionConfigBuilder.setOutput(outputTopic);
    }
    if (inputTopic != null && inputSerdeClassName != null) {
        functionConfigBuilder.putCustomSerdeInputs(inputTopic, inputSerdeClassName);
    }
    if (outputSerdeClassName != null) {
        functionConfigBuilder.setOutputSerdeClassName(outputSerdeClassName);
    }
    if (className != null) {
        functionConfigBuilder.setClassName(className);
    }
    if (parallelism != null) {
        functionConfigBuilder.setParallelism(parallelism);
    }
    FunctionConfig functionConfig = functionConfigBuilder.build();
    Response response = resource.registerFunction(tenant, namespace, function, inputStream, details, org.apache.pulsar.functions.utils.Utils.printJson(functionConfig));
    assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    if (missingFieldName.equals("parallelism")) {
        Assert.assertEquals(new ErrorData("Parallelism needs to be set to a positive number").reason, ((ErrorData) response.getEntity()).reason);
    } else {
        Assert.assertEquals(new ErrorData(missingFieldName + " is not provided").reason, ((ErrorData) response.getEntity()).reason);
    }
}
Also used : FunctionConfig(org.apache.pulsar.functions.proto.Function.FunctionConfig) Response(javax.ws.rs.core.Response) ErrorData(org.apache.pulsar.common.policies.data.ErrorData)

Aggregations

ErrorData (org.apache.pulsar.common.policies.data.ErrorData)26 Response (javax.ws.rs.core.Response)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Test (org.testng.annotations.Test)12 IOException (java.io.IOException)9 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)9 Path (javax.ws.rs.Path)8 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)8 RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)8 InputStream (java.io.InputStream)6 Namespace (org.apache.distributedlog.api.namespace.Namespace)6 ExecutionException (java.util.concurrent.ExecutionException)5 FunctionConfig (org.apache.pulsar.functions.proto.Function.FunctionConfig)5 GET (javax.ws.rs.GET)4 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)2 PackageLocationMetaData (org.apache.pulsar.functions.proto.Function.PackageLocationMetaData)2 FunctionRuntimeManager (org.apache.pulsar.functions.worker.FunctionRuntimeManager)2 Gson (com.google.gson.Gson)1 DELETE (javax.ws.rs.DELETE)1