use of org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult in project kafka by apache.
the class RequestResponseTest method createCreateTopicResponse.
private CreateTopicsResponse createCreateTopicResponse() {
CreateTopicsResponseData data = new CreateTopicsResponseData();
data.topics().add(new CreatableTopicResult().setName("t1").setErrorCode(Errors.INVALID_TOPIC_EXCEPTION.code()).setErrorMessage(null));
data.topics().add(new CreatableTopicResult().setName("t2").setErrorCode(Errors.LEADER_NOT_AVAILABLE.code()).setErrorMessage("Leader with id 5 is not available."));
data.topics().add(new CreatableTopicResult().setName("t3").setErrorCode(Errors.NONE.code()).setNumPartitions(1).setReplicationFactor((short) 2).setConfigs(singletonList(new CreatableTopicConfigs().setName("min.insync.replicas").setValue("2"))));
return new CreateTopicsResponse(data);
}
use of org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult in project kafka by apache.
the class CreateTopicsRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
CreateTopicsResponseData response = new CreateTopicsResponseData();
if (version() >= 2) {
response.setThrottleTimeMs(throttleTimeMs);
}
ApiError apiError = ApiError.fromThrowable(e);
for (CreatableTopic topic : data.topics()) {
response.topics().add(new CreatableTopicResult().setName(topic.name()).setErrorCode(apiError.error().code()).setErrorMessage(apiError.message()));
}
return new CreateTopicsResponse(response);
}
use of org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult in project kafka by apache.
the class ReplicationControlManagerTest method testRemoveLeaderships.
@Test
public void testRemoveLeaderships() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replicationControl = ctx.replicationControl;
ctx.registerBrokers(0, 1, 2, 3);
ctx.unfenceBrokers(0, 1, 2, 3);
CreatableTopicResult result = ctx.createTestTopic("foo", new int[][] { new int[] { 0, 1, 2 }, new int[] { 1, 2, 3 }, new int[] { 2, 3, 0 }, new int[] { 0, 2, 1 } });
Set<TopicIdPartition> expectedPartitions = new HashSet<>();
expectedPartitions.add(new TopicIdPartition(result.topicId(), 0));
expectedPartitions.add(new TopicIdPartition(result.topicId(), 3));
assertEquals(expectedPartitions, RecordTestUtils.iteratorToSet(replicationControl.brokersToIsrs().iterator(0, true)));
List<ApiMessageAndVersion> records = new ArrayList<>();
replicationControl.handleBrokerFenced(0, records);
ctx.replay(records);
assertEquals(Collections.emptySet(), RecordTestUtils.iteratorToSet(replicationControl.brokersToIsrs().iterator(0, true)));
}
use of org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult in project kafka by apache.
the class ReplicationControlManagerTest method testCreateTopicsWithValidateOnlyFlag.
@Test
public void testCreateTopicsWithValidateOnlyFlag() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ctx.registerBrokers(0, 1, 2);
ctx.unfenceBrokers(0, 1, 2);
CreateTopicsRequestData request = new CreateTopicsRequestData().setValidateOnly(true);
request.topics().add(new CreatableTopic().setName("foo").setNumPartitions(1).setReplicationFactor((short) 3));
ControllerResult<CreateTopicsResponseData> result = ctx.replicationControl.createTopics(request);
assertEquals(0, result.records().size());
CreatableTopicResult topicResult = result.response().topics().find("foo");
assertEquals((short) 0, topicResult.errorCode());
}
use of org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult in project kafka by apache.
the class MockController method createTopics.
@Override
public synchronized CompletableFuture<CreateTopicsResponseData> createTopics(CreateTopicsRequestData request) {
CreateTopicsResponseData response = new CreateTopicsResponseData();
for (CreatableTopic topic : request.topics()) {
if (topicNameToId.containsKey(topic.name())) {
response.topics().add(new CreatableTopicResult().setName(topic.name()).setErrorCode(Errors.TOPIC_ALREADY_EXISTS.code()));
} else {
long topicId = nextTopicId.getAndIncrement();
Uuid topicUuid = new Uuid(0, topicId);
topicNameToId.put(topic.name(), topicUuid);
topics.put(topicUuid, new MockTopic(topic.name(), topicUuid));
response.topics().add(new CreatableTopicResult().setName(topic.name()).setErrorCode(Errors.NONE.code()).setTopicId(topicUuid));
// For a better mock, we might want to return configs, replication factor,
// etc. Right now, the tests that use MockController don't need these
// things.
}
}
return CompletableFuture.completedFuture(response);
}
Aggregations