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