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);
}
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."));
}
}
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));
}
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());
}
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());
}
Aggregations