use of org.apache.kafka.common.KafkaFuture in project kafka by apache.
the class KafkaAdminClientTest method testDescribeConfigsPartialResponse.
@Test
public void testDescribeConfigsPartialResponse() throws Exception {
ConfigResource topic = new ConfigResource(ConfigResource.Type.TOPIC, "topic");
ConfigResource topic2 = new ConfigResource(ConfigResource.Type.TOPIC, "topic2");
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponse(new DescribeConfigsResponse(new DescribeConfigsResponseData().setResults(asList(new DescribeConfigsResponseData.DescribeConfigsResult().setResourceName(topic.name()).setResourceType(topic.type().id()).setErrorCode(Errors.NONE.code()).setConfigs(emptyList())))));
Map<ConfigResource, KafkaFuture<Config>> result = env.adminClient().describeConfigs(asList(topic, topic2)).values();
assertEquals(new HashSet<>(asList(topic, topic2)), result.keySet());
result.get(topic);
TestUtils.assertFutureThrows(result.get(topic2), ApiException.class);
}
}
use of org.apache.kafka.common.KafkaFuture in project kafka by apache.
the class KafkaAdminClientTest method testDescribeLogDirsOfflineDir.
@Test
public void testDescribeLogDirsOfflineDir() throws ExecutionException, InterruptedException {
Set<Integer> brokers = singleton(0);
String logDir = "/var/data/kafka";
Errors error = Errors.KAFKA_STORAGE_ERROR;
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponseFrom(prepareDescribeLogDirsResponse(error, logDir, emptyList()), env.cluster().nodeById(0));
DescribeLogDirsResult result = env.adminClient().describeLogDirs(brokers);
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> descriptions = result.descriptions();
assertEquals(brokers, descriptions.keySet());
assertNotNull(descriptions.get(0));
Map<String, LogDirDescription> descriptionsMap = descriptions.get(0).get();
assertEquals(singleton(logDir), descriptionsMap.keySet());
assertEquals(error.exception().getClass(), descriptionsMap.get(logDir).error().getClass());
assertEquals(emptySet(), descriptionsMap.get(logDir).replicaInfos().keySet());
Map<Integer, Map<String, LogDirDescription>> allDescriptions = result.allDescriptions().get();
assertEquals(brokers, allDescriptions.keySet());
Map<String, LogDirDescription> allMap = allDescriptions.get(0);
assertNotNull(allMap);
assertEquals(singleton(logDir), allMap.keySet());
assertEquals(error.exception().getClass(), allMap.get(logDir).error().getClass());
assertEquals(emptySet(), allMap.get(logDir).replicaInfos().keySet());
}
}
use of org.apache.kafka.common.KafkaFuture in project kafka by apache.
the class ListTransactionsResultTest method testPartialFailure.
@Test
public void testPartialFailure() throws Exception {
KafkaFutureImpl<Collection<TransactionListing>> future1 = new KafkaFutureImpl<>();
KafkaFutureImpl<Collection<TransactionListing>> future2 = new KafkaFutureImpl<>();
Map<Integer, KafkaFutureImpl<Collection<TransactionListing>>> brokerFutures = new HashMap<>();
brokerFutures.put(1, future1);
brokerFutures.put(2, future2);
future.complete(brokerFutures);
List<TransactionListing> broker1Listings = asList(new TransactionListing("foo", 12345L, TransactionState.ONGOING), new TransactionListing("bar", 98765L, TransactionState.PREPARE_ABORT));
future1.complete(broker1Listings);
future2.completeExceptionally(new KafkaException());
Map<Integer, KafkaFuture<Collection<TransactionListing>>> resultBrokerFutures = result.byBrokerId().get();
// Ensure that the future for broker 1 completes successfully
assertEquals(Utils.mkSet(1, 2), resultBrokerFutures.keySet());
assertEquals(broker1Listings, resultBrokerFutures.get(1).get());
// Everything else should fail
assertFutureThrows(result.all(), KafkaException.class);
assertFutureThrows(result.allByBrokerId(), KafkaException.class);
assertFutureThrows(resultBrokerFutures.get(2), KafkaException.class);
}
use of org.apache.kafka.common.KafkaFuture in project kafka by apache.
the class MockAdminClient method handleDescribeTopicsUsingIds.
public synchronized Map<Uuid, KafkaFuture<TopicDescription>> handleDescribeTopicsUsingIds(Collection<Uuid> topicIds, DescribeTopicsOptions options) {
Map<Uuid, KafkaFuture<TopicDescription>> topicDescriptions = new HashMap<>();
if (timeoutNextRequests > 0) {
for (Uuid requestedTopicId : topicIds) {
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.completeExceptionally(new TimeoutException());
topicDescriptions.put(requestedTopicId, future);
}
--timeoutNextRequests;
return topicDescriptions;
}
for (Uuid requestedTopicId : topicIds) {
for (Map.Entry<String, TopicMetadata> topicDescription : allTopics.entrySet()) {
String topicName = topicDescription.getKey();
Uuid topicId = this.topicIds.get(topicName);
if (topicId != null && topicId.equals(requestedTopicId) && !topicDescription.getValue().markedForDeletion) {
if (topicDescription.getValue().fetchesRemainingUntilVisible > 0) {
topicDescription.getValue().fetchesRemainingUntilVisible--;
} else {
TopicMetadata topicMetadata = topicDescription.getValue();
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.complete(new TopicDescription(topicName, topicMetadata.isInternalTopic, topicMetadata.partitions, Collections.emptySet(), topicId));
topicDescriptions.put(requestedTopicId, future);
break;
}
}
}
if (!topicDescriptions.containsKey(requestedTopicId)) {
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.completeExceptionally(new UnknownTopicIdException("Topic id" + requestedTopicId + " not found."));
topicDescriptions.put(requestedTopicId, future);
}
}
return topicDescriptions;
}
use of org.apache.kafka.common.KafkaFuture in project kafka by apache.
the class MockAdminClient method handleDeleteTopicsUsingNames.
private Map<String, KafkaFuture<Void>> handleDeleteTopicsUsingNames(Collection<String> topicNameCollection, DeleteTopicsOptions options) {
Map<String, KafkaFuture<Void>> deleteTopicsResult = new HashMap<>();
Collection<String> topicNames = new ArrayList<>(topicNameCollection);
if (timeoutNextRequests > 0) {
for (final String topicName : topicNames) {
KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
future.completeExceptionally(new TimeoutException());
deleteTopicsResult.put(topicName, future);
}
--timeoutNextRequests;
return deleteTopicsResult;
}
for (final String topicName : topicNames) {
KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
if (allTopics.remove(topicName) == null) {
future.completeExceptionally(new UnknownTopicOrPartitionException(String.format("Topic %s does not exist.", topicName)));
} else {
topicNames.remove(topicIds.remove(topicName));
future.complete(null);
}
deleteTopicsResult.put(topicName, future);
}
return deleteTopicsResult;
}
Aggregations