use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class AllBrokersStrategyIntegrationTest method testFatalFulfillmentError.
@Test
public void testFatalFulfillmentError() throws Exception {
AllBrokersStrategy.AllBrokersFuture<Integer> result = new AllBrokersStrategy.AllBrokersFuture<>();
AdminApiDriver<AllBrokersStrategy.BrokerKey, Integer> driver = buildDriver(result);
List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> lookupSpecs = driver.poll();
assertEquals(1, lookupSpecs.size());
AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> lookupSpec = lookupSpecs.get(0);
int brokerId = 1;
driver.onResponse(time.milliseconds(), lookupSpec, responseWithBrokers(Collections.singleton(brokerId)), Node.noNode());
assertTrue(result.all().isDone());
Map<Integer, KafkaFutureImpl<Integer>> brokerFutures = result.all().get();
KafkaFutureImpl<Integer> future = brokerFutures.get(brokerId);
assertFalse(future.isDone());
List<AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey>> requestSpecs = driver.poll();
assertEquals(1, requestSpecs.size());
AdminApiDriver.RequestSpec<AllBrokersStrategy.BrokerKey> requestSpec = requestSpecs.get(0);
driver.onFailure(time.milliseconds(), requestSpec, new UnknownServerException());
assertTrue(future.isDone());
TestUtils.assertFutureThrows(future, UnknownServerException.class);
assertEquals(Collections.emptyList(), driver.poll());
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class DescribeProducersHandlerTest method testUnexpectedError.
@Test
public void testUnexpectedError() {
TopicPartition topicPartition = new TopicPartition("foo", 5);
Throwable exception = assertFatalError(topicPartition, Errors.UNKNOWN_SERVER_ERROR);
assertTrue(exception instanceof UnknownServerException);
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class PartitionLeaderStrategyTest method testUnexpectedTopicErrror.
@Test
public void testUnexpectedTopicErrror() {
TopicPartition topicPartition = new TopicPartition("foo", 0);
Throwable exception = assertFatalTopicError(topicPartition, Errors.UNKNOWN_SERVER_ERROR);
assertTrue(exception instanceof UnknownServerException);
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class UpdateFeaturesRequestTest method testGetErrorResponse.
@Test
public void testGetErrorResponse() {
UpdateFeaturesRequestData.FeatureUpdateKeyCollection features = new UpdateFeaturesRequestData.FeatureUpdateKeyCollection();
features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("foo").setMaxVersionLevel((short) 2));
features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("bar").setMaxVersionLevel((short) 3));
UpdateFeaturesRequest request = new UpdateFeaturesRequest(new UpdateFeaturesRequestData().setFeatureUpdates(features), UpdateFeaturesRequestData.HIGHEST_SUPPORTED_VERSION);
UpdateFeaturesResponse response = request.getErrorResponse(0, new UnknownServerException());
assertEquals(Errors.UNKNOWN_SERVER_ERROR, response.topLevelError().error());
assertEquals(0, response.data().results().size());
assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 1), response.errorCounts());
}
use of org.apache.kafka.common.errors.UnknownServerException in project kafka by apache.
the class ReplicationControlManager method createPartitions.
void createPartitions(CreatePartitionsTopic topic, List<ApiMessageAndVersion> records) {
Uuid topicId = topicsByName.get(topic.name());
if (topicId == null) {
throw new UnknownTopicOrPartitionException();
}
TopicControlInfo topicInfo = topics.get(topicId);
if (topicInfo == null) {
throw new UnknownTopicOrPartitionException();
}
if (topic.count() == topicInfo.parts.size()) {
throw new InvalidPartitionsException("Topic already has " + topicInfo.parts.size() + " partition(s).");
} else if (topic.count() < topicInfo.parts.size()) {
throw new InvalidPartitionsException("The topic " + topic.name() + " currently " + "has " + topicInfo.parts.size() + " partition(s); " + topic.count() + " would not be an increase.");
}
int additional = topic.count() - topicInfo.parts.size();
if (topic.assignments() != null) {
if (topic.assignments().size() != additional) {
throw new InvalidReplicaAssignmentException("Attempted to add " + additional + " additional partition(s), but only " + topic.assignments().size() + " assignment(s) were specified.");
}
}
Iterator<PartitionRegistration> iterator = topicInfo.parts.values().iterator();
if (!iterator.hasNext()) {
throw new UnknownServerException("Invalid state: topic " + topic.name() + " appears to have no partitions.");
}
PartitionRegistration partitionInfo = iterator.next();
if (partitionInfo.replicas.length > Short.MAX_VALUE) {
throw new UnknownServerException("Invalid replication factor " + partitionInfo.replicas.length + ": expected a number equal to less than " + Short.MAX_VALUE);
}
short replicationFactor = (short) partitionInfo.replicas.length;
int startPartitionId = topicInfo.parts.size();
List<List<Integer>> placements;
List<List<Integer>> isrs;
if (topic.assignments() != null) {
placements = new ArrayList<>();
isrs = new ArrayList<>();
for (int i = 0; i < topic.assignments().size(); i++) {
CreatePartitionsAssignment assignment = topic.assignments().get(i);
validateManualPartitionAssignment(assignment.brokerIds(), OptionalInt.of(replicationFactor));
placements.add(assignment.brokerIds());
List<Integer> isr = assignment.brokerIds().stream().filter(clusterControl::unfenced).collect(Collectors.toList());
if (isr.isEmpty()) {
throw new InvalidReplicaAssignmentException("All brokers specified in the manual partition assignment for " + "partition " + (startPartitionId + i) + " are fenced.");
}
isrs.add(isr);
}
} else {
placements = clusterControl.placeReplicas(startPartitionId, additional, replicationFactor);
isrs = placements;
}
int partitionId = startPartitionId;
for (int i = 0; i < placements.size(); i++) {
List<Integer> placement = placements.get(i);
List<Integer> isr = isrs.get(i);
records.add(new ApiMessageAndVersion(new PartitionRecord().setPartitionId(partitionId).setTopicId(topicId).setReplicas(placement).setIsr(isr).setRemovingReplicas(Collections.emptyList()).setAddingReplicas(Collections.emptyList()).setLeader(isr.get(0)).setLeaderEpoch(0).setPartitionEpoch(0), PARTITION_RECORD.highestSupportedVersion()));
partitionId++;
}
}
Aggregations