Search in sources :

Example 1 with AlterUserScramCredentialsResponseData

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

the class KafkaAdminClientTest method testAlterUserScramCredentialsUnknownMechanism.

@Test
public void testAlterUserScramCredentialsUnknownMechanism() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        final String user0Name = "user0";
        ScramMechanism user0ScramMechanism0 = ScramMechanism.UNKNOWN;
        final String user1Name = "user1";
        ScramMechanism user1ScramMechanism0 = ScramMechanism.UNKNOWN;
        final String user2Name = "user2";
        ScramMechanism user2ScramMechanism0 = ScramMechanism.SCRAM_SHA_256;
        AlterUserScramCredentialsResponseData responseData = new AlterUserScramCredentialsResponseData();
        responseData.setResults(Arrays.asList(new AlterUserScramCredentialsResponseData.AlterUserScramCredentialsResult().setUser(user2Name)));
        env.kafkaClient().prepareResponse(new AlterUserScramCredentialsResponse(responseData));
        AlterUserScramCredentialsResult result = env.adminClient().alterUserScramCredentials(Arrays.asList(new UserScramCredentialDeletion(user0Name, user0ScramMechanism0), new UserScramCredentialUpsertion(user1Name, new ScramCredentialInfo(user1ScramMechanism0, 8192), "password"), new UserScramCredentialUpsertion(user2Name, new ScramCredentialInfo(user2ScramMechanism0, 4096), "password")));
        Map<String, KafkaFuture<Void>> resultData = result.values();
        assertEquals(3, resultData.size());
        Arrays.asList(user0Name, user1Name).stream().forEach(u -> {
            assertTrue(resultData.containsKey(u));
            try {
                resultData.get(u).get();
                fail("Expected request for user " + u + " to complete exceptionally, but it did not");
            } catch (Exception expected) {
            // ignore
            }
        });
        assertTrue(resultData.containsKey(user2Name));
        try {
            resultData.get(user2Name).get();
        } catch (Exception e) {
            fail("Expected request for user " + user2Name + " to NOT complete excdptionally, but it did");
        }
        try {
            result.all().get();
            fail("Expected 'result.all().get()' to throw an exception since at least one user failed, but it did not");
        } catch (final Exception expected) {
        // ignore, expected
        }
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) AlterUserScramCredentialsResponse(org.apache.kafka.common.requests.AlterUserScramCredentialsResponse) ThrottlingQuotaExceededException(org.apache.kafka.common.errors.ThrottlingQuotaExceededException) KafkaException(org.apache.kafka.common.KafkaException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) AuthenticationException(org.apache.kafka.common.errors.AuthenticationException) SecurityDisabledException(org.apache.kafka.common.errors.SecurityDisabledException) ExecutionException(java.util.concurrent.ExecutionException) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) UnknownMemberIdException(org.apache.kafka.common.errors.UnknownMemberIdException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) GroupSubscribedToTopicException(org.apache.kafka.common.errors.GroupSubscribedToTopicException) ConfigException(org.apache.kafka.common.config.ConfigException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) InvalidRequestException(org.apache.kafka.common.errors.InvalidRequestException) NotLeaderOrFollowerException(org.apache.kafka.common.errors.NotLeaderOrFollowerException) InvalidTopicException(org.apache.kafka.common.errors.InvalidTopicException) TopicDeletionDisabledException(org.apache.kafka.common.errors.TopicDeletionDisabledException) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException) SaslAuthenticationException(org.apache.kafka.common.errors.SaslAuthenticationException) FencedInstanceIdException(org.apache.kafka.common.errors.FencedInstanceIdException) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) LogDirNotFoundException(org.apache.kafka.common.errors.LogDirNotFoundException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) OffsetOutOfRangeException(org.apache.kafka.common.errors.OffsetOutOfRangeException) ApiException(org.apache.kafka.common.errors.ApiException) AlterUserScramCredentialsResponseData(org.apache.kafka.common.message.AlterUserScramCredentialsResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with AlterUserScramCredentialsResponseData

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

the class KafkaAdminClientTest method testAlterUserScramCredentials.

@Test
public void testAlterUserScramCredentials() throws Exception {
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        final String user0Name = "user0";
        ScramMechanism user0ScramMechanism0 = ScramMechanism.SCRAM_SHA_256;
        ScramMechanism user0ScramMechanism1 = ScramMechanism.SCRAM_SHA_512;
        final String user1Name = "user1";
        ScramMechanism user1ScramMechanism0 = ScramMechanism.SCRAM_SHA_256;
        final String user2Name = "user2";
        ScramMechanism user2ScramMechanism0 = ScramMechanism.SCRAM_SHA_512;
        AlterUserScramCredentialsResponseData responseData = new AlterUserScramCredentialsResponseData();
        responseData.setResults(Arrays.asList(user0Name, user1Name, user2Name).stream().map(u -> new AlterUserScramCredentialsResponseData.AlterUserScramCredentialsResult().setUser(u).setErrorCode(Errors.NONE.code())).collect(Collectors.toList()));
        env.kafkaClient().prepareResponse(new AlterUserScramCredentialsResponse(responseData));
        AlterUserScramCredentialsResult result = env.adminClient().alterUserScramCredentials(Arrays.asList(new UserScramCredentialDeletion(user0Name, user0ScramMechanism0), new UserScramCredentialUpsertion(user0Name, new ScramCredentialInfo(user0ScramMechanism1, 8192), "password"), new UserScramCredentialUpsertion(user1Name, new ScramCredentialInfo(user1ScramMechanism0, 8192), "password"), new UserScramCredentialDeletion(user2Name, user2ScramMechanism0)));
        Map<String, KafkaFuture<Void>> resultData = result.values();
        assertEquals(3, resultData.size());
        Arrays.asList(user0Name, user1Name, user2Name).stream().forEach(u -> {
            assertTrue(resultData.containsKey(u));
            assertFalse(resultData.get(u).isCompletedExceptionally());
        });
    }
}
Also used : AlterUserScramCredentialsResponseData(org.apache.kafka.common.message.AlterUserScramCredentialsResponseData) KafkaFuture(org.apache.kafka.common.KafkaFuture) AlterUserScramCredentialsResponse(org.apache.kafka.common.requests.AlterUserScramCredentialsResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

KafkaFuture (org.apache.kafka.common.KafkaFuture)2 AlterUserScramCredentialsResponseData (org.apache.kafka.common.message.AlterUserScramCredentialsResponseData)2 AlterUserScramCredentialsResponse (org.apache.kafka.common.requests.AlterUserScramCredentialsResponse)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ExecutionException (java.util.concurrent.ExecutionException)1 KafkaException (org.apache.kafka.common.KafkaException)1 ConfigException (org.apache.kafka.common.config.ConfigException)1 ApiException (org.apache.kafka.common.errors.ApiException)1 AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)1 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)1 FencedInstanceIdException (org.apache.kafka.common.errors.FencedInstanceIdException)1 GroupAuthorizationException (org.apache.kafka.common.errors.GroupAuthorizationException)1 GroupSubscribedToTopicException (org.apache.kafka.common.errors.GroupSubscribedToTopicException)1 InvalidRequestException (org.apache.kafka.common.errors.InvalidRequestException)1 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)1 LeaderNotAvailableException (org.apache.kafka.common.errors.LeaderNotAvailableException)1 LogDirNotFoundException (org.apache.kafka.common.errors.LogDirNotFoundException)1 NotLeaderOrFollowerException (org.apache.kafka.common.errors.NotLeaderOrFollowerException)1 OffsetOutOfRangeException (org.apache.kafka.common.errors.OffsetOutOfRangeException)1