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