Search in sources :

Example 1 with CreatableTopicResult

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);
}
Also used : CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) CreatableTopicConfigs(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicConfigs) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData)

Example 2 with CreatableTopicResult

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);
}
Also used : CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData)

Example 3 with CreatableTopicResult

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)));
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with CreatableTopicResult

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());
}
Also used : CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 5 with CreatableTopicResult

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);
}
Also used : Uuid(org.apache.kafka.common.Uuid) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData)

Aggregations

CreatableTopicResult (org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult)15 CreateTopicsResponseData (org.apache.kafka.common.message.CreateTopicsResponseData)9 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 CreatableTopic (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic)7 CreateTopicsRequestData (org.apache.kafka.common.message.CreateTopicsRequestData)6 ArrayList (java.util.ArrayList)5 Uuid (org.apache.kafka.common.Uuid)5 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)5 HashMap (java.util.HashMap)4 ApiError (org.apache.kafka.common.requests.ApiError)4 TopicIdPartition (org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition)4 List (java.util.List)3 AlterIsrResponseData (org.apache.kafka.common.message.AlterIsrResponseData)3 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)3 PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)3 Map (java.util.Map)2 OptionalInt (java.util.OptionalInt)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 InvalidReplicationFactorException (org.apache.kafka.common.errors.InvalidReplicationFactorException)2