Search in sources :

Example 11 with ValidationResult

use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.

the class InternalTopicManagerTest method shouldValidateSuccessfully.

@Test
public void shouldValidateSuccessfully() {
    setupTopicInMockAdminClient(topic1, repartitionTopicConfig());
    setupTopicInMockAdminClient(topic2, repartitionTopicConfig());
    final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
    final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
    final ValidationResult validationResult = internalTopicManager.validate(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2)));
    assertThat(validationResult.missingTopics(), empty());
    assertThat(validationResult.misconfigurationsForTopics(), anEmptyMap());
}
Also used : ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Test(org.junit.Test)

Example 12 with ValidationResult

use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.

the class InternalTopicManagerTest method shouldReportMisconfigurationsOfCleanupPolicyForWindowedChangelogTopics.

@Test
public void shouldReportMisconfigurationsOfCleanupPolicyForWindowedChangelogTopics() {
    final long retentionMs = 1000;
    final long shorterRetentionMs = 900;
    setupTopicInMockAdminClient(topic1, windowedChangelogConfig(retentionMs));
    setupTopicInMockAdminClient(topic2, windowedChangelogConfig(shorterRetentionMs));
    final Map<String, String> windowedChangelogConfigOnlyCleanupPolicyCompact = windowedChangelogConfig(retentionMs);
    windowedChangelogConfigOnlyCleanupPolicyCompact.put(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT);
    setupTopicInMockAdminClient(topic3, windowedChangelogConfigOnlyCleanupPolicyCompact);
    final Map<String, String> windowedChangelogConfigOnlyCleanupPolicyDelete = windowedChangelogConfig(shorterRetentionMs);
    windowedChangelogConfigOnlyCleanupPolicyDelete.put(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_DELETE);
    setupTopicInMockAdminClient(topic4, windowedChangelogConfigOnlyCleanupPolicyDelete);
    final Map<String, String> windowedChangelogConfigWithRetentionBytes = windowedChangelogConfig(retentionMs);
    windowedChangelogConfigWithRetentionBytes.put(TopicConfig.RETENTION_BYTES_CONFIG, "1024");
    setupTopicInMockAdminClient(topic5, windowedChangelogConfigWithRetentionBytes);
    final InternalTopicConfig internalTopicConfig1 = setupWindowedChangelogTopicConfig(topic1, 1, retentionMs);
    final InternalTopicConfig internalTopicConfig2 = setupWindowedChangelogTopicConfig(topic2, 1, retentionMs);
    final InternalTopicConfig internalTopicConfig3 = setupWindowedChangelogTopicConfig(topic3, 1, retentionMs);
    final InternalTopicConfig internalTopicConfig4 = setupWindowedChangelogTopicConfig(topic4, 1, retentionMs);
    final InternalTopicConfig internalTopicConfig5 = setupWindowedChangelogTopicConfig(topic5, 1, retentionMs);
    final ValidationResult validationResult = internalTopicManager.validate(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2), mkEntry(topic3, internalTopicConfig3), mkEntry(topic4, internalTopicConfig4), mkEntry(topic5, internalTopicConfig5)));
    final Map<String, List<String>> misconfigurationsForTopics = validationResult.misconfigurationsForTopics();
    assertThat(validationResult.missingTopics(), empty());
    assertThat(misconfigurationsForTopics.size(), is(3));
    assertThat(misconfigurationsForTopics, hasKey(topic2));
    assertThat(misconfigurationsForTopics.get(topic2).size(), is(1));
    assertThat(misconfigurationsForTopics.get(topic2).get(0), is("Retention time (" + TopicConfig.RETENTION_MS_CONFIG + ") of existing internal topic " + topic2 + " is " + shorterRetentionMs + " but should be " + retentionMs + " or larger."));
    assertThat(misconfigurationsForTopics, hasKey(topic4));
    assertThat(misconfigurationsForTopics.get(topic4).size(), is(1));
    assertThat(misconfigurationsForTopics.get(topic4).get(0), is("Retention time (" + TopicConfig.RETENTION_MS_CONFIG + ") of existing internal topic " + topic4 + " is " + shorterRetentionMs + " but should be " + retentionMs + " or larger."));
    assertThat(misconfigurationsForTopics, hasKey(topic5));
    assertThat(misconfigurationsForTopics.get(topic5).size(), is(1));
    assertThat(misconfigurationsForTopics.get(topic5).get(0), is("Retention byte (" + TopicConfig.RETENTION_BYTES_CONFIG + ") of existing internal topic " + topic5 + " is set but it should be unset."));
    assertThat(misconfigurationsForTopics, not(hasKey(topic1)));
    assertThat(misconfigurationsForTopics, not(hasKey(topic3)));
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ValidationResult(org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult) Test(org.junit.Test)

Example 13 with ValidationResult

use of org.apache.kafka.streams.processor.internals.InternalTopicManager.ValidationResult in project kafka by apache.

the class InternalTopicManagerTest method shouldReportMissingTopics.

@Test
public void shouldReportMissingTopics() {
    final String missingTopic1 = "missingTopic1";
    final String missingTopic2 = "missingTopic2";
    setupTopicInMockAdminClient(topic1, repartitionTopicConfig());
    final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
    final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(missingTopic1, 1);
    final InternalTopicConfig internalTopicConfig3 = setupRepartitionTopicConfig(missingTopic2, 1);
    final ValidationResult validationResult = internalTopicManager.validate(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(missingTopic1, internalTopicConfig2), mkEntry(missingTopic2, internalTopicConfig3)));
    final Set<String> missingTopics = validationResult.missingTopics();
    assertThat(missingTopics.size(), is(2));
    assertThat(missingTopics, hasItem(missingTopic1));
    assertThat(missingTopics, hasItem(missingTopic2));
    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