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