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();
}
});
}
}
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);
}
Aggregations