Search in sources :

Example 16 with ErrorData

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

the class FunctionApiV2ResourceTest method testUpdateFunctionMissingArguments.

private void testUpdateFunctionMissingArguments(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.updateFunction(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)

Example 17 with ErrorData

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

the class FunctionApiV2ResourceTest method testRegisterExistedFunction.

@Test
public void testRegisterExistedFunction() throws IOException {
    Configurator.setRootLevel(Level.DEBUG);
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    Response response = registerDefaultFunction();
    assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function " + function + " already exists").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 18 with ErrorData

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

the class FunctionApiV2ResourceTest method testDeregisterFunctionMissingArguments.

private void testDeregisterFunctionMissingArguments(String tenant, String namespace, String function, String missingFieldName) {
    Response response = resource.deregisterFunction(tenant, namespace, function);
    assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData(missingFieldName + " is not provided").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) ErrorData(org.apache.pulsar.common.policies.data.ErrorData)

Example 19 with ErrorData

use of org.apache.pulsar.common.policies.data.ErrorData 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)

Example 20 with ErrorData

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

the class FunctionApiV2ResourceTest method testDeregisterFunctionInterrupted.

@Test
public void testDeregisterFunctionInterrupted() throws Exception {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    CompletableFuture<RequestResult> requestResult = FutureUtil.failedFuture(new IOException("Function deregisteration interrupted"));
    when(mockedManager.deregisterFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(requestResult);
    Response response = deregisterDefaultFunction();
    assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData("Function deregisteration interrupted").reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) IOException(java.io.IOException) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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