Search in sources :

Example 26 with Admin

use of org.apache.kafka.clients.admin.Admin in project kafka by apache.

the class ClientCompatibilityTest method testAdminClient.

void testAdminClient() throws Throwable {
    Properties adminProps = new Properties();
    adminProps.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, testConfig.bootstrapServer);
    try (final Admin client = Admin.create(adminProps)) {
        while (true) {
            Collection<Node> nodes = client.describeCluster().nodes().get();
            if (nodes.size() == testConfig.numClusterNodes) {
                break;
            } else if (nodes.size() > testConfig.numClusterNodes) {
                throw new KafkaException("Expected to see " + testConfig.numClusterNodes + " nodes, but saw " + nodes.size());
            }
            Thread.sleep(1);
            log.info("Saw only {} cluster nodes.  Waiting to see {}.", nodes.size(), testConfig.numClusterNodes);
        }
        testDescribeConfigsMethod(client);
        tryFeature("createTopics", testConfig.createTopicsSupported, () -> {
            try {
                client.createTopics(Collections.singleton(new NewTopic("newtopic", 1, (short) 1))).all().get();
            } catch (ExecutionException e) {
                throw e.getCause();
            }
        }, () -> createTopicsResultTest(client, Collections.singleton("newtopic")));
        while (true) {
            Collection<TopicListing> listings = client.listTopics().listings().get();
            if (!testConfig.createTopicsSupported)
                break;
            if (topicExists(listings, "newtopic"))
                break;
            Thread.sleep(1);
            log.info("Did not see newtopic.  Retrying listTopics...");
        }
        tryFeature("describeAclsSupported", testConfig.describeAclsSupported, () -> {
            try {
                client.describeAcls(AclBindingFilter.ANY).values().get();
            } catch (ExecutionException e) {
                if (e.getCause() instanceof SecurityDisabledException)
                    return;
                throw e.getCause();
            }
        });
    }
}
Also used : Node(org.apache.kafka.common.Node) TopicListing(org.apache.kafka.clients.admin.TopicListing) KafkaException(org.apache.kafka.common.KafkaException) NewTopic(org.apache.kafka.clients.admin.NewTopic) Properties(java.util.Properties) Admin(org.apache.kafka.clients.admin.Admin) ExecutionException(java.util.concurrent.ExecutionException) SecurityDisabledException(org.apache.kafka.common.errors.SecurityDisabledException)

Example 27 with Admin

use of org.apache.kafka.clients.admin.Admin in project hono by eclipse.

the class KafkaBasedInternalCommandConsumerTest method setUp.

/**
 * Sets up fixture.
 */
@BeforeEach
public void setUp() {
    final Admin kafkaAdminClient = mock(Admin.class);
    @SuppressWarnings("unchecked") final KafkaConsumer<String, Buffer> kafkaConsumer = mock(KafkaConsumer.class);
    final String adapterInstanceId = "adapterInstanceId";
    final Span span = TracingMockSupport.mockSpan();
    final Tracer tracer = TracingMockSupport.mockTracer(span);
    context = VertxMockSupport.mockContext(mock(Vertx.class));
    commandHandlers = new CommandHandlers();
    tenantClient = mock(TenantClient.class);
    doAnswer(invocation -> {
        final String tenantId = invocation.getArgument(0);
        return Future.succeededFuture(TenantObject.from(tenantId));
    }).when(tenantClient).get(anyString(), any());
    commandResponseSender = mock(CommandResponseSender.class);
    when(commandResponseSender.sendCommandResponse(any(TenantObject.class), any(RegistrationAssertion.class), any(CommandResponse.class), any())).thenReturn(Future.succeededFuture());
    internalCommandConsumer = new KafkaBasedInternalCommandConsumer(context, kafkaAdminClient, kafkaConsumer, "testClientId", tenantClient, commandResponseSender, adapterInstanceId, commandHandlers, tracer);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) CommandHandlers(org.eclipse.hono.client.command.CommandHandlers) Tracer(io.opentracing.Tracer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CommandResponse(org.eclipse.hono.client.command.CommandResponse) Admin(org.apache.kafka.clients.admin.Admin) Span(io.opentracing.Span) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) TenantClient(org.eclipse.hono.client.registry.TenantClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Admin (org.apache.kafka.clients.admin.Admin)27 ExecutionException (java.util.concurrent.ExecutionException)12 Map (java.util.Map)11 Properties (java.util.Properties)9 HashMap (java.util.HashMap)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 NewTopic (org.apache.kafka.clients.admin.NewTopic)7 AdminClientConfig (org.apache.kafka.clients.admin.AdminClientConfig)6 Test (org.junit.Test)6 Collection (java.util.Collection)5 ConfigResource (org.apache.kafka.common.config.ConfigResource)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Config (org.apache.kafka.clients.admin.Config)4 ListOffsetsResult (org.apache.kafka.clients.admin.ListOffsetsResult)4 MirrorMakerConfig (org.apache.kafka.connect.mirror.MirrorMakerConfig)4 Logger (org.slf4j.Logger)4 IOException (java.io.IOException)3