Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
3c9136b2
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
3c9136b2
编写于
7月 30, 2019
作者:
B
Boyang Jerry Peng
提交者:
Sijie Guo
7月 30, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix: check function implements correct interface (#4844)
上级
b0793a17
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
0 deletion
+43
-0
pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java
...rg/apache/pulsar/functions/utils/FunctionConfigUtils.java
+14
-0
pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
...nctions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
+29
-0
未找到文件。
pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java
浏览文件 @
3c9136b2
...
...
@@ -369,6 +369,20 @@ public class FunctionConfigUtils {
private
static
void
doJavaChecks
(
FunctionConfig
functionConfig
,
ClassLoader
clsLoader
)
{
try
{
Class
functionClass
=
clsLoader
.
loadClass
(
functionConfig
.
getClassName
());
if
(!
org
.
apache
.
pulsar
.
functions
.
api
.
Function
.
class
.
isAssignableFrom
(
functionClass
)
&&
!
java
.
util
.
function
.
Function
.
class
.
isAssignableFrom
(
functionClass
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Function class %s does not implement the correct interface"
,
functionClass
.
getName
()));
}
}
catch
(
ClassNotFoundException
e
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Function class %s must be in class path"
,
functionConfig
.
getClassName
()),
e
);
}
Class
<?>[]
typeArgs
;
try
{
typeArgs
=
FunctionCommon
.
getFunctionTypes
(
functionConfig
,
clsLoader
);
...
...
pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java
浏览文件 @
3c9136b2
...
...
@@ -43,6 +43,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.function.Consumer
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.StreamingOutput
;
...
...
@@ -109,6 +110,13 @@ public class FunctionApiV3ResourceTest {
}
}
private
static
final
class
WrongFunction
implements
Consumer
<
String
>
{
@Override
public
void
accept
(
String
s
)
{
}
}
private
static
final
String
tenant
=
"test-tenant"
;
private
static
final
String
namespace
=
"test-namespace"
;
private
static
final
String
function
=
"test-function"
;
...
...
@@ -438,6 +446,27 @@ public class FunctionApiV3ResourceTest {
}
}
@Test
(
expectedExceptions
=
RestException
.
class
,
expectedExceptionsMessageRegExp
=
"Function class .*. does not implement the correct interface"
)
public
void
testRegisterFunctionImplementWrongInterface
()
{
try
{
testRegisterFunctionMissingArguments
(
tenant
,
namespace
,
function
,
mockedInputStream
,
topicsToSerDeClassName
,
mockedFormData
,
outputTopic
,
outputSerdeClassName
,
WrongFunction
.
class
.
getName
(),
parallelism
,
null
);
}
catch
(
RestException
re
){
assertEquals
(
re
.
getResponse
().
getStatusInfo
(),
Response
.
Status
.
BAD_REQUEST
);
throw
re
;
}
}
private
void
testRegisterFunctionMissingArguments
(
String
tenant
,
String
namespace
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录