Search in sources :

Example 6 with RestException

use of org.apache.pulsar.common.util.RestException in project pulsar by apache.

the class SinkApiV3ResourceTest method testUpdateSinkUploadFailure.

@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testUpdateSinkUploadFailure() throws Exception {
    try {
        mockWorkerUtils(ctx -> {
            ctx.when(() -> WorkerUtils.dumpToTmpFile(any())).thenCallRealMethod();
            ctx.when(() -> WorkerUtils.uploadFileToBookkeeper(anyString(), any(File.class), any(Namespace.class))).thenThrow(new IOException("upload failure"));
        });
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
        updateDefaultSink();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
Also used : RestException(org.apache.pulsar.common.util.RestException) IOException(java.io.IOException) File(java.io.File) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test)

Example 7 with RestException

use of org.apache.pulsar.common.util.RestException in project pulsar by apache.

the class SourceApiV3ResourceTest method testUpdateSourceUploadFailure.

@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testUpdateSourceUploadFailure() throws Exception {
    try {
        mockWorkerUtils(ctx -> {
            ctx.when(() -> WorkerUtils.uploadFileToBookkeeper(anyString(), any(File.class), any(Namespace.class))).thenThrow(new IOException("upload failure"));
            ctx.when(() -> WorkerUtils.dumpToTmpFile(any())).thenCallRealMethod();
        });
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);
        updateDefaultSource();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
Also used : RestException(org.apache.pulsar.common.util.RestException) IOException(java.io.IOException) File(java.io.File) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test)

Example 8 with RestException

use of org.apache.pulsar.common.util.RestException in project pulsar by apache.

the class SourceApiV3ResourceTest method testRegisterSourceUploadFailure.

@Test(expectedExceptions = RestException.class, expectedExceptionsMessageRegExp = "upload failure")
public void testRegisterSourceUploadFailure() throws Exception {
    try {
        mockWorkerUtils(ctx -> {
            ctx.when(() -> WorkerUtils.uploadFileToBookkeeper(anyString(), any(File.class), any(Namespace.class))).thenThrow(new IOException("upload failure"));
            ctx.when(() -> WorkerUtils.dumpToTmpFile(any())).thenCallRealMethod();
        });
        when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(false);
        when(mockedRuntimeFactory.externallyManaged()).thenReturn(true);
        registerDefaultSource();
        fail();
    } catch (RestException re) {
        assertEquals(re.getResponse().getStatusInfo(), Response.Status.INTERNAL_SERVER_ERROR);
        throw re;
    }
}
Also used : RestException(org.apache.pulsar.common.util.RestException) IOException(java.io.IOException) File(java.io.File) Namespace(org.apache.distributedlog.api.namespace.Namespace) Test(org.testng.annotations.Test)

Example 9 with RestException

use of org.apache.pulsar.common.util.RestException in project pulsar by apache.

the class SourceApiV3ResourceTest method testUpdateSourceFailedWithWrongPackageName.

@Test(timeOut = 20000)
public void testUpdateSourceFailedWithWrongPackageName() throws Exception {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);
    try {
        doThrow(new PulsarAdminException("package name is invalid")).when(mockedPackages).download(anyString(), anyString());
        updateDefaultSourceWithPackageUrl("source://");
    } catch (RestException e) {
        // expected exception
        assertEquals(e.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
    }
}
Also used : RestException(org.apache.pulsar.common.util.RestException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Example 10 with RestException

use of org.apache.pulsar.common.util.RestException in project pulsar by apache.

the class FunctionApiV3ResourceTest method testRegisterFunctionFailedWithWrongPackageName.

@Test(timeOut = 20000)
public void testRegisterFunctionFailedWithWrongPackageName() throws PulsarAdminException {
    try {
        doThrow(new PulsarAdminException("package name is invalid")).when(mockedPackages).download(anyString(), anyString());
        registerDefaultFunctionWithPackageUrl("function://");
    } catch (RestException e) {
        // expected exception
        assertEquals(e.getResponse().getStatusInfo(), Response.Status.BAD_REQUEST);
    }
}
Also used : RestException(org.apache.pulsar.common.util.RestException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test)

Aggregations

RestException (org.apache.pulsar.common.util.RestException)178 IOException (java.io.IOException)101 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)101 WebApplicationException (javax.ws.rs.WebApplicationException)66 FunctionMetaDataManager (org.apache.pulsar.functions.worker.FunctionMetaDataManager)65 RestUtils.throwUnavailableException (org.apache.pulsar.functions.worker.rest.RestUtils.throwUnavailableException)54 Test (org.testng.annotations.Test)45 File (java.io.File)41 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)36 Function (org.apache.pulsar.functions.proto.Function)33 Namespace (org.apache.distributedlog.api.namespace.Namespace)21 SchemaSerializationException (org.apache.pulsar.client.api.SchemaSerializationException)21 ExecutionException (java.util.concurrent.ExecutionException)18 NamespaceNotFoundException (org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)18 StreamNotFoundException (org.apache.bookkeeper.clients.exceptions.StreamNotFoundException)18 FunctionAuthData (org.apache.pulsar.functions.auth.FunctionAuthData)18 FunctionAuthUtils.getFunctionAuthData (org.apache.pulsar.functions.auth.FunctionAuthUtils.getFunctionAuthData)18 FunctionRuntimeManager (org.apache.pulsar.functions.worker.FunctionRuntimeManager)15 URI (java.net.URI)14 FunctionConfig (org.apache.pulsar.common.functions.FunctionConfig)12