Search in sources :

Example 21 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.

the class InternalTopicManagerTest method shouldCompleteValidateWhenTopicLeaderNotAvailableAndThenDescribeSuccess.

@Test
public void shouldCompleteValidateWhenTopicLeaderNotAvailableAndThenDescribeSuccess() {
    final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
    final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
    final TopicPartitionInfo partitionInfo = new TopicPartitionInfo(0, broker1, Collections.singletonList(broker1), Collections.singletonList(broker1));
    final KafkaFutureImpl<TopicDescription> topicDescriptionFailFuture = new KafkaFutureImpl<>();
    topicDescriptionFailFuture.completeExceptionally(new LeaderNotAvailableException("Leader Not Available!"));
    final KafkaFutureImpl<TopicDescription> topicDescriptionSuccessFuture = new KafkaFutureImpl<>();
    topicDescriptionSuccessFuture.complete(new TopicDescription(topic1, false, Collections.singletonList(partitionInfo), Collections.emptySet()));
    EasyMock.expect(admin.describeTopics(Collections.singleton(topic1))).andReturn(new MockDescribeTopicsResult(Collections.singletonMap(topic1, topicDescriptionFailFuture))).once();
    EasyMock.expect(admin.describeTopics(Collections.singleton(topic1))).andReturn(new MockDescribeTopicsResult(Collections.singletonMap(topic1, topicDescriptionSuccessFuture))).once();
    EasyMock.replay(admin);
    final InternalTopicConfig internalTopicConfig = new RepartitionTopicConfig(topic1, Collections.emptyMap());
    internalTopicConfig.setNumberOfPartitions(1);
    topicManager.makeReady(Collections.singletonMap(topic1, internalTopicConfig));
    EasyMock.verify(admin);
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) AdminClient(org.apache.kafka.clients.admin.AdminClient) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 22 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.

the class InternalTopicManagerTest method shouldLogWhenTopicNotFoundAndNotThrowException.

@Test
public void shouldLogWhenTopicNotFoundAndNotThrowException() {
    mockAdminClient.addTopic(false, topic1, Collections.singletonList(new TopicPartitionInfo(0, broker1, cluster, Collections.emptyList())), null);
    final InternalTopicConfig internalTopicConfig = new RepartitionTopicConfig(topic1, Collections.emptyMap());
    internalTopicConfig.setNumberOfPartitions(1);
    final InternalTopicConfig internalTopicConfigII = new RepartitionTopicConfig("internal-topic", Collections.emptyMap());
    internalTopicConfigII.setNumberOfPartitions(1);
    final Map<String, InternalTopicConfig> topicConfigMap = new HashMap<>();
    topicConfigMap.put(topic1, internalTopicConfig);
    topicConfigMap.put("internal-topic", internalTopicConfigII);
    LogCaptureAppender.setClassLoggerToDebug(InternalTopicManager.class);
    try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(InternalTopicManager.class)) {
        internalTopicManager.makeReady(topicConfigMap);
        assertThat(appender.getMessages(), hasItem("stream-thread [" + threadName + "] Topic internal-topic is unknown or not found, hence not existed yet.\n" + "Error message was: org.apache.kafka.common.errors.UnknownTopicOrPartitionException: Topic internal-topic not found."));
    }
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) HashMap(java.util.HashMap) LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) Test(org.junit.Test)

Example 23 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.

the class WorkerUtilsTest method testExistingTopicsMustHaveRequestedNumberOfPartitions.

@Test
public void testExistingTopicsMustHaveRequestedNumberOfPartitions() throws Throwable {
    List<TopicPartitionInfo> tpInfo = new ArrayList<>();
    tpInfo.add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
    tpInfo.add(new TopicPartitionInfo(1, broker2, singleReplica, Collections.<Node>emptyList()));
    adminClient.addTopic(false, TEST_TOPIC, tpInfo, null);
    assertThrows(RuntimeException.class, () -> WorkerUtils.createTopics(log, adminClient, Collections.singletonMap(TEST_TOPIC, NEW_TEST_TOPIC), false));
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 24 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.

the class WorkerUtilsTest method testCreateRetriesOnTimeout.

@Test
public void testCreateRetriesOnTimeout() throws Throwable {
    adminClient.timeoutNextRequest(1);
    WorkerUtils.createTopics(log, adminClient, Collections.singletonMap(TEST_TOPIC, NEW_TEST_TOPIC), true);
    assertEquals(new TopicDescription(TEST_TOPIC, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()))), adminClient.describeTopics(Collections.singleton(TEST_TOPIC)).topicNameValues().get(TEST_TOPIC).get());
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) Test(org.junit.jupiter.api.Test)

Example 25 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project kafka by apache.

the class WorkerUtilsTest method testExistingTopicsNotCreated.

@Test
public void testExistingTopicsNotCreated() throws Throwable {
    final String existingTopic = "existing-topic";
    List<TopicPartitionInfo> tpInfo = new ArrayList<>();
    tpInfo.add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
    tpInfo.add(new TopicPartitionInfo(1, broker2, singleReplica, Collections.<Node>emptyList()));
    tpInfo.add(new TopicPartitionInfo(2, broker3, singleReplica, Collections.<Node>emptyList()));
    adminClient.addTopic(false, existingTopic, tpInfo, null);
    WorkerUtils.createTopics(log, adminClient, Collections.singletonMap(existingTopic, new NewTopic(existingTopic, tpInfo.size(), TEST_REPLICATION_FACTOR)), false);
    assertEquals(Collections.singleton(existingTopic), adminClient.listTopics().names().get());
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.jupiter.api.Test)

Aggregations

TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)62 Test (org.junit.Test)33 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)31 Node (org.apache.kafka.common.Node)28 ArrayList (java.util.ArrayList)20 MockAdminClient (org.apache.kafka.clients.admin.MockAdminClient)18 NewTopic (org.apache.kafka.clients.admin.NewTopic)16 HashMap (java.util.HashMap)14 Cluster (org.apache.kafka.common.Cluster)11 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)11 StreamsConfig (org.apache.kafka.streams.StreamsConfig)11 Test (org.junit.jupiter.api.Test)10 TopicPartition (org.apache.kafka.common.TopicPartition)8 ConfigResource (org.apache.kafka.common.config.ConfigResource)8 Map (java.util.Map)7 AdminClient (org.apache.kafka.clients.admin.AdminClient)7 Config (org.apache.kafka.clients.admin.Config)7 TopicMetadataAndConfig (org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig)7 TopicConfig (org.apache.kafka.common.config.TopicConfig)7 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)6