Search in sources :

Example 6 with ErrorData

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

the class FunctionApiV2ResourceTest method testUpdateFunctionUploadFailure.

@Test
public void testUpdateFunctionUploadFailure() 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(true);
    Response response = updateDefaultFunction();
    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 7 with ErrorData

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

the class FunctionApiV2ResourceTest method testDeregisterFunctionFailure.

@Test
public void testDeregisterFunctionFailure() throws Exception {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    RequestResult rr = new RequestResult().setSuccess(false).setMessage("function failed to deregister");
    CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
    when(mockedManager.deregisterFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(requestResult);
    Response response = deregisterDefaultFunction();
    assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertEquals(new ErrorData(rr.getMessage()).reason, ((ErrorData) response.getEntity()).reason);
}
Also used : Response(javax.ws.rs.core.Response) RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with ErrorData

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

the class FunctionApiV2ResourceTest method testGetFunctionMissingArguments.

private void testGetFunctionMissingArguments(String tenant, String namespace, String function, String missingFieldName) throws IOException {
    Response response = resource.getFunctionInfo(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 9 with ErrorData

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

the class FunctionApiV2ResourceTest method testUpdateFunctionFailure.

@Test
public void testUpdateFunctionFailure() 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(false).setMessage("function failed to register");
    CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
    when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
    Response response = updateDefaultFunction();
    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 10 with ErrorData

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

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