Search in sources :

Example 1 with CreateAclsResponseData

use of org.apache.kafka.common.message.CreateAclsResponseData in project kafka by apache.

the class KafkaAdminClientTest method testCreateAcls.

@Test
public void testCreateAcls() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        // Test a call where we successfully create two ACLs.
        env.kafkaClient().prepareResponse(new CreateAclsResponse(new CreateAclsResponseData().setResults(asList(new CreateAclsResponseData.AclCreationResult(), new CreateAclsResponseData.AclCreationResult()))));
        CreateAclsResult results = env.adminClient().createAcls(asList(ACL1, ACL2));
        assertCollectionIs(results.values().keySet(), ACL1, ACL2);
        for (KafkaFuture<Void> future : results.values().values()) future.get();
        results.all().get();
        // Test a call where we fail to create one ACL.
        env.kafkaClient().prepareResponse(new CreateAclsResponse(new CreateAclsResponseData().setResults(asList(new CreateAclsResponseData.AclCreationResult().setErrorCode(Errors.SECURITY_DISABLED.code()).setErrorMessage("Security is disabled"), new CreateAclsResponseData.AclCreationResult()))));
        results = env.adminClient().createAcls(asList(ACL1, ACL2));
        assertCollectionIs(results.values().keySet(), ACL1, ACL2);
        TestUtils.assertFutureError(results.values().get(ACL1), SecurityDisabledException.class);
        results.values().get(ACL2).get();
        TestUtils.assertFutureError(results.all(), SecurityDisabledException.class);
    }
}
Also used : CreateAclsResponseData(org.apache.kafka.common.message.CreateAclsResponseData) CreateAclsResponse(org.apache.kafka.common.requests.CreateAclsResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with CreateAclsResponseData

use of org.apache.kafka.common.message.CreateAclsResponseData in project kafka by apache.

the class CreateAclsRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) {
    CreateAclsResponseData.AclCreationResult result = CreateAclsRequest.aclResult(throwable);
    List<CreateAclsResponseData.AclCreationResult> results = Collections.nCopies(data.creations().size(), result);
    return new CreateAclsResponse(new CreateAclsResponseData().setThrottleTimeMs(throttleTimeMs).setResults(results));
}
Also used : AclCreationResult(org.apache.kafka.common.message.CreateAclsResponseData.AclCreationResult) CreateAclsResponseData(org.apache.kafka.common.message.CreateAclsResponseData) AclCreationResult(org.apache.kafka.common.message.CreateAclsResponseData.AclCreationResult)

Aggregations

CreateAclsResponseData (org.apache.kafka.common.message.CreateAclsResponseData)2 AclCreationResult (org.apache.kafka.common.message.CreateAclsResponseData.AclCreationResult)1 CreateAclsResponse (org.apache.kafka.common.requests.CreateAclsResponse)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1