Search in sources :

Example 6 with ValidationResult

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());
}
Also used : ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 7 with ValidationResult

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."));
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Test(org.junit.Test)

Example 8 with ValidationResult

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);
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) DescribeConfigsResult(org.apache.kafka.clients.admin.DescribeConfigsResult) Matchers.not(org.hamcrest.Matchers.not) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) StreamsException(org.apache.kafka.streams.errors.StreamsException) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Matchers.hasKey(org.hamcrest.Matchers.hasKey) AdminClient(org.apache.kafka.clients.admin.AdminClient) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) After(org.junit.After) Map(java.util.Map) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) Assert.fail(org.junit.Assert.fail) TopicConfig(org.apache.kafka.common.config.TopicConfig) CreatableReplicaAssignmentCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignmentCollection) Collection(java.util.Collection) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KafkaFuture(org.apache.kafka.common.KafkaFuture) Collectors(java.util.stream.Collectors) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) List(java.util.List) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Matchers.is(org.hamcrest.Matchers.is) CreateTopicsOptions(org.apache.kafka.clients.admin.CreateTopicsOptions) Type(org.apache.kafka.common.config.ConfigResource.Type) Config(org.apache.kafka.clients.admin.Config) Uuid(org.apache.kafka.common.Uuid) StreamsConfig(org.apache.kafka.streams.StreamsConfig) CreateTopicsRequest(org.apache.kafka.common.requests.CreateTopicsRequest) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) ArrayList(java.util.ArrayList) ConfigResource(org.apache.kafka.common.config.ConfigResource) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Before(org.junit.Before) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Matchers.empty(org.hamcrest.Matchers.empty) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assert.assertNull(org.junit.Assert.assertNull) LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopicConfig(org.apache.kafka.common.config.TopicConfig) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.kafka.clients.admin.Config) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) ConfigResource(org.apache.kafka.common.config.ConfigResource) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) 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 9 with ValidationResult

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);
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) DescribeConfigsResult(org.apache.kafka.clients.admin.DescribeConfigsResult) Matchers.not(org.hamcrest.Matchers.not) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) StreamsException(org.apache.kafka.streams.errors.StreamsException) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Matchers.hasKey(org.hamcrest.Matchers.hasKey) AdminClient(org.apache.kafka.clients.admin.AdminClient) Utils.mkMap(org.apache.kafka.common.utils.Utils.mkMap) After(org.junit.After) Map(java.util.Map) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) Assert.fail(org.junit.Assert.fail) TopicConfig(org.apache.kafka.common.config.TopicConfig) CreatableReplicaAssignmentCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignmentCollection) Collection(java.util.Collection) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) KafkaFuture(org.apache.kafka.common.KafkaFuture) Collectors(java.util.stream.Collectors) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) List(java.util.List) Utils.mkEntry(org.apache.kafka.common.utils.Utils.mkEntry) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) Node(org.apache.kafka.common.Node) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) Matchers.is(org.hamcrest.Matchers.is) CreateTopicsOptions(org.apache.kafka.clients.admin.CreateTopicsOptions) Type(org.apache.kafka.common.config.ConfigResource.Type) Config(org.apache.kafka.clients.admin.Config) Uuid(org.apache.kafka.common.Uuid) StreamsConfig(org.apache.kafka.streams.StreamsConfig) CreateTopicsRequest(org.apache.kafka.common.requests.CreateTopicsRequest) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) ArrayList(java.util.ArrayList) ConfigResource(org.apache.kafka.common.config.ConfigResource) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) CreateTopicsResult(org.apache.kafka.clients.admin.CreateTopicsResult) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Before(org.junit.Before) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Matchers.empty(org.hamcrest.Matchers.empty) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Assert.assertNull(org.junit.Assert.assertNull) LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) Matchers.anEmptyMap(org.hamcrest.Matchers.anEmptyMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopicConfig(org.apache.kafka.common.config.TopicConfig) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.kafka.clients.admin.Config) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) LeaderNotAvailableException(org.apache.kafka.common.errors.LeaderNotAvailableException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) ConfigResource(org.apache.kafka.common.config.ConfigResource) ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) 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 10 with ValidationResult

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());
}
Also used : ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 List (java.util.List)8 StreamsConfig (org.apache.kafka.streams.StreamsConfig)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AdminClient (org.apache.kafka.clients.admin.AdminClient)3 Config (org.apache.kafka.clients.admin.Config)3 ConfigEntry (org.apache.kafka.clients.admin.ConfigEntry)3 CreateTopicsOptions (org.apache.kafka.clients.admin.CreateTopicsOptions)3 CreateTopicsResult (org.apache.kafka.clients.admin.CreateTopicsResult)3 TopicMetadataAndConfig (org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig)3 DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)3 DescribeConfigsResult (org.apache.kafka.clients.admin.DescribeConfigsResult)3