我正在尝试测试一个卡夫卡读者作家场景,在这个场景中,用户有写主题的权限,但没有从该主题中读取的权限。
java代码如下所示:
@TargetEnv("kafka_servers/kafka_test_server.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class KafkaConsumeJsonTest {
@Test
@Scenario('path/to/writer-can-write-but-cannot-read.json')
public void test writerWritesButCantRead(){}
}对应的JSON如下所示:
{
"scenarioName": "Writer can write to a topic but cannot read from it",
"steps": [{
"name": "write to test topic",
"url": "kafka-topic:test-topic",
"operation": "produce",
"request": {
"records": [{
"key": "101",
"value": "Hello World"
}]
},
"assertions": {
"status": "Ok",
"recordMetadata": "$NOT.NULL"
}
},
{
"name": "onload_kafka",
"url": "kafka-topic:test-topic",
"operation": "unload",
"request": {
"consumerLocalConfigs": {
"recordType": "JSON",
"maxNoOfRetryPollsOrTimeouts": 3
}
},
"assertions": {
"status": "Failed",
"message": "Caused by: org.apache.kafka.common.errors.GroupAuthorizationException: Not authorized to access group: my-group"
}
}
]
}
当我运行测试时,我会遇到:
org.apache.kafka.common.errors.GroupAuthorizationException: java.lang.RuntimeException:未授权访问组: my-group.
这是一个有效的异常,我要断言,在我的测试代码中,用户不能使用my作为gorup从主题中读取。
如何在测试用例或场景JSON中断言这一点?
谢谢你,杰
发布于 2022-02-01 10:25:28
我在零代码github上发布了这个问题,我得到了答案。
解决方案我们需要通过扩展卡夫卡客户端来创建我们自己的卡夫卡客户端。在这个定制的Kafka客户端中,我们需要尝试catch循环。在try块中,委托对超类的调用,在try块中捕获异常并返回所需的消息。在我们的零代码测试中,我们需要使用新创建的Custom客户端。
如果有人感兴趣的话,下面是完整的对话链接。
https://stackoverflow.com/questions/70393112
复制相似问题