Search in sources :

Example 1 with RequestResult

use of org.apache.pulsar.functions.worker.request.RequestResult in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testRegisterFunctionSuccess.

@Test
public void testRegisterFunctionSuccess() 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(true).setMessage("function registered");
    CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
    when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
    Response response = registerDefaultFunction();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
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) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with RequestResult

use of org.apache.pulsar.functions.worker.request.RequestResult in project incubator-pulsar by apache.

the class FunctionApiV2ResourceTest method testDeregisterFunctionSuccess.

@Test
public void testDeregisterFunctionSuccess() throws Exception {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    RequestResult rr = new RequestResult().setSuccess(true).setMessage("function deregistered");
    CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
    when(mockedManager.deregisterFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(requestResult);
    Response response = deregisterDefaultFunction();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    assertEquals(rr.toJson(), response.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) RequestResult(org.apache.pulsar.functions.worker.request.RequestResult) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with RequestResult

use of org.apache.pulsar.functions.worker.request.RequestResult 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 4 with RequestResult

use of org.apache.pulsar.functions.worker.request.RequestResult 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 5 with RequestResult

use of org.apache.pulsar.functions.worker.request.RequestResult 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

RequestResult (org.apache.pulsar.functions.worker.request.RequestResult)13 Response (javax.ws.rs.core.Response)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Test (org.testng.annotations.Test)9 ErrorData (org.apache.pulsar.common.policies.data.ErrorData)8 InputStream (java.io.InputStream)6 Namespace (org.apache.distributedlog.api.namespace.Namespace)6 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)6 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)2 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)2 ServiceRequestInfo (org.apache.pulsar.functions.worker.request.ServiceRequestInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 MessageId (org.apache.pulsar.client.api.MessageId)1