use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.
the class InternalTopicManagerTest method shouldNotThrowExceptionIfTopicExistsWithDifferentReplication.
@Test
public void shouldNotThrowExceptionIfTopicExistsWithDifferentReplication() {
setupTopicInMockAdminClient(topic1, repartitionTopicConfig());
// attempt to create it again with replication 1
final InternalTopicManager internalTopicManager2 = new InternalTopicManager(time, mockAdminClient, new StreamsConfig(config));
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
final ValidationResult validationResult = internalTopicManager2.validate(Collections.singletonMap(topic1, internalTopicConfig));
assertThat(validationResult.missingTopics(), empty());
assertThat(validationResult.misconfigurationsForTopics(), anEmptyMap());
}
use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.
the class InternalTopicManagerTest method shouldReportMultipleMisconfigurationsForSameTopic.
@Test
public void shouldReportMultipleMisconfigurationsForSameTopic() {
final long retentionMs = 1000;
final long shorterRetentionMs = 900;
final Map<String, String> windowedChangelogConfig = windowedChangelogConfig(shorterRetentionMs);
windowedChangelogConfig.put(TopicConfig.RETENTION_BYTES_CONFIG, "1024");
setupTopicInMockAdminClient(topic1, windowedChangelogConfig);
final InternalTopicConfig internalTopicConfig1 = setupWindowedChangelogTopicConfig(topic1, 1, retentionMs);
final ValidationResult validationResult = internalTopicManager.validate(mkMap(mkEntry(topic1, internalTopicConfig1)));
final Map<String, List<String>> misconfigurationsForTopics = validationResult.misconfigurationsForTopics();
assertThat(validationResult.missingTopics(), empty());
assertThat(misconfigurationsForTopics.size(), is(1));
assertThat(misconfigurationsForTopics, hasKey(topic1));
assertThat(misconfigurationsForTopics.get(topic1).size(), is(2));
assertThat(misconfigurationsForTopics.get(topic1).get(0), is("Retention time (" + TopicConfig.RETENTION_MS_CONFIG + ") of existing internal topic " + topic1 + " is " + shorterRetentionMs + " but should be " + retentionMs + " or larger."));
assertThat(misconfigurationsForTopics.get(topic1).get(1), is("Retention byte (" + TopicConfig.RETENTION_BYTES_CONFIG + ") of existing internal topic " + topic1 + " is set but it should be unset."));
}
use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.
the class InternalTopicManagerTest method shouldOnlyRetryNotSuccessfulFuturesDuringValidation.
@Test
public void shouldOnlyRetryNotSuccessfulFuturesDuringValidation() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
final KafkaFutureImpl<TopicDescription> topicDescriptionFailFuture = new KafkaFutureImpl<>();
topicDescriptionFailFuture.completeExceptionally(new LeaderNotAvailableException("Leader Not Available!"));
final KafkaFutureImpl<TopicDescription> topicDescriptionSuccessfulFuture1 = new KafkaFutureImpl<>();
topicDescriptionSuccessfulFuture1.complete(new TopicDescription(topic1, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, cluster, Collections.emptyList()))));
final KafkaFutureImpl<TopicDescription> topicDescriptionSuccessfulFuture2 = new KafkaFutureImpl<>();
topicDescriptionSuccessfulFuture2.complete(new TopicDescription(topic2, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, cluster, Collections.emptyList()))));
EasyMock.expect(admin.describeTopics(mkSet(topic1, topic2))).andAnswer(() -> new MockDescribeTopicsResult(mkMap(mkEntry(topic1, topicDescriptionSuccessfulFuture1), mkEntry(topic2, topicDescriptionFailFuture))));
EasyMock.expect(admin.describeTopics(mkSet(topic2))).andAnswer(() -> new MockDescribeTopicsResult(mkMap(mkEntry(topic2, topicDescriptionSuccessfulFuture2))));
final KafkaFutureImpl<Config> topicConfigSuccessfulFuture = new KafkaFutureImpl<>();
topicConfigSuccessfulFuture.complete(new Config(repartitionTopicConfig().entrySet().stream().map(entry -> new ConfigEntry(entry.getKey(), entry.getValue())).collect(Collectors.toSet())));
final ConfigResource topicResource1 = new ConfigResource(Type.TOPIC, topic1);
final ConfigResource topicResource2 = new ConfigResource(Type.TOPIC, topic2);
EasyMock.expect(admin.describeConfigs(mkSet(topicResource1, topicResource2))).andAnswer(() -> new MockDescribeConfigsResult(mkMap(mkEntry(topicResource1, topicConfigSuccessfulFuture), mkEntry(topicResource2, topicConfigSuccessfulFuture))));
EasyMock.replay(admin);
final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
final ValidationResult validationResult = topicManager.validate(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2)));
assertThat(validationResult.missingTopics(), empty());
assertThat(validationResult.misconfigurationsForTopics(), anEmptyMap());
EasyMock.verify(admin);
}
use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.
the class InternalTopicManagerTest method shouldOnlyRetryDescribeConfigsWhenDescribeConfigsThrowsLeaderNotAvailableExceptionDuringValidation.
@Test
public void shouldOnlyRetryDescribeConfigsWhenDescribeConfigsThrowsLeaderNotAvailableExceptionDuringValidation() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
final KafkaFutureImpl<TopicDescription> topicDescriptionSuccessfulFuture = new KafkaFutureImpl<>();
topicDescriptionSuccessfulFuture.complete(new TopicDescription(topic1, false, Collections.singletonList(new TopicPartitionInfo(0, broker1, cluster, Collections.emptyList()))));
EasyMock.expect(admin.describeTopics(Collections.singleton(topic1))).andReturn(new MockDescribeTopicsResult(mkMap(mkEntry(topic1, topicDescriptionSuccessfulFuture))));
final KafkaFutureImpl<Config> topicConfigsFailFuture = new KafkaFutureImpl<>();
topicConfigsFailFuture.completeExceptionally(new LeaderNotAvailableException("Leader Not Available!"));
final KafkaFutureImpl<Config> topicConfigSuccessfulFuture = new KafkaFutureImpl<>();
topicConfigSuccessfulFuture.complete(new Config(repartitionTopicConfig().entrySet().stream().map(entry -> new ConfigEntry(entry.getKey(), entry.getValue())).collect(Collectors.toSet())));
final ConfigResource topicResource = new ConfigResource(Type.TOPIC, topic1);
EasyMock.expect(admin.describeConfigs(Collections.singleton(topicResource))).andReturn(new MockDescribeConfigsResult(mkMap(mkEntry(topicResource, topicConfigsFailFuture)))).andReturn(new MockDescribeConfigsResult(mkMap(mkEntry(topicResource, topicConfigSuccessfulFuture))));
EasyMock.replay(admin);
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
final ValidationResult validationResult = topicManager.validate(Collections.singletonMap(topic1, internalTopicConfig));
assertThat(validationResult.missingTopics(), empty());
assertThat(validationResult.misconfigurationsForTopics(), anEmptyMap());
EasyMock.verify(admin);
}
use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.
the class InternalTopicManagerTest method shouldValidateSuccessfullyWithEmptyInternalTopics.
@Test
public void shouldValidateSuccessfullyWithEmptyInternalTopics() {
setupTopicInMockAdminClient(topic1, repartitionTopicConfig());
final ValidationResult validationResult = internalTopicManager.validate(Collections.emptyMap());
assertThat(validationResult.missingTopics(), empty());
assertThat(validationResult.misconfigurationsForTopics(), anEmptyMap());
}
Aggregations