Skip to content
代码片段 群组 项目
未验证 提交 6d18b044 编辑于 作者: k-raina's avatar k-raina 提交者: GitHub
浏览文件

KSECURITY-532 : Fix flaky test: RbacSbcIntegrationTest (#6946)

* Fix flaky test in RbacSbcIntegrationTest
上级 06d4f407
No related branches found
No related tags found
无相关合并请求
......@@ -25,6 +25,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Tag("integration")
public class RbacSbcIntegrationTest {
......@@ -73,9 +75,9 @@ public class RbacSbcIntegrationTest {
adminClient -> adminClient.removeBrokers(Collections.singletonList(0)).all();
// Broker removal fails as we try to remove a broker with partitions that have RF = 1.
// Authorization is tested nonetheless, as it is done before the code reaches the Balancer
verifySbcAPIAccess(BROKER_USER, removeBrokerApi, InvalidBrokerRemovalException.class);
verifySbcAPIAccess(SYSTEM_ADMIN_USER, removeBrokerApi, InvalidBrokerRemovalException.class);
verifySbcAPIAccess(CLUSTER_ADMIN_USER, removeBrokerApi, InvalidBrokerRemovalException.class);
verifySbcAPIAccess(BROKER_USER, removeBrokerApi, Arrays.asList(InvalidBrokerRemovalException.class, BalancerOfflineException.class));
verifySbcAPIAccess(SYSTEM_ADMIN_USER, removeBrokerApi, Arrays.asList(InvalidBrokerRemovalException.class, BalancerOfflineException.class));
verifySbcAPIAccess(CLUSTER_ADMIN_USER, removeBrokerApi, Arrays.asList(InvalidBrokerRemovalException.class, BalancerOfflineException.class));
verifySbcAPIAccess(RESOURCE_OWNER_USER, removeBrokerApi, ClusterAuthorizationException.class);
Function<KafkaAdminClient, KafkaFuture<?>> describeBrokerRemoveApi =
......@@ -142,17 +144,22 @@ public class RbacSbcIntegrationTest {
if (possibleExceptions.isEmpty()) {
future.get();
} else {
// try all of the exceptions
// try all of the possible exceptions. Return if any of the possible exception is thrown
for (int i = 0; i < possibleExceptions.size(); i++) {
Class<? extends Throwable> possibleException = possibleExceptions.get(i);
try {
TestUtils.assertFutureError(future, possibleException);
TestUtils.assertFutureThrows(future, possibleException);
return;
} catch (Throwable t) {
if (i != possibleExceptions.size() - 1) {
// swallow this exception and try the next one
continue;
}
assertEquals(possibleException, t.getClass(),
"Expected a " + possibleException.getSimpleName() + " exception, but got " +
t.getClass().getSimpleName());
throw t;
}
}
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册