Search in sources :

Example 11 with TopicsInfo

use of org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo in project kafka by apache.

the class ChangelogTopicsTest method shouldOnlyContainPreExistingSourceBasedChangelogs.

@Test
public void shouldOnlyContainPreExistingSourceBasedChangelogs() {
    expect(internalTopicManager.makeReady(Collections.emptyMap())).andStubReturn(Collections.emptySet());
    final Map<Subtopology, TopicsInfo> topicGroups = mkMap(mkEntry(SUBTOPOLOGY_0, TOPICS_INFO3));
    final Set<TaskId> tasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);
    final Map<Subtopology, Set<TaskId>> tasksForTopicGroup = mkMap(mkEntry(SUBTOPOLOGY_0, tasks));
    replay(internalTopicManager);
    final ChangelogTopics changelogTopics = new ChangelogTopics(internalTopicManager, topicGroups, tasksForTopicGroup, "[test] ");
    changelogTopics.setup();
    verify(internalTopicManager);
    final TopicPartition changelogPartition0 = new TopicPartition(SOURCE_TOPIC_NAME, 0);
    final TopicPartition changelogPartition1 = new TopicPartition(SOURCE_TOPIC_NAME, 1);
    final TopicPartition changelogPartition2 = new TopicPartition(SOURCE_TOPIC_NAME, 2);
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_0), is(mkSet(changelogPartition0)));
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_1), is(mkSet(changelogPartition1)));
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_2), is(mkSet(changelogPartition2)));
    assertThat(changelogTopics.preExistingSourceTopicBasedPartitions(), is(mkSet(changelogPartition0, changelogPartition1, changelogPartition2)));
    assertThat(changelogTopics.preExistingNonSourceTopicBasedPartitions(), is(Collections.emptySet()));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) TopicPartition(org.apache.kafka.common.TopicPartition) TopicsInfo(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo) Subtopology(org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology) Test(org.junit.Test)

Example 12 with TopicsInfo

use of org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo in project kafka by apache.

the class ChangelogTopicsTest method shouldContainBothTypesOfPreExistingChangelogs.

@Test
public void shouldContainBothTypesOfPreExistingChangelogs() {
    expect(internalTopicManager.makeReady(mkMap(mkEntry(CHANGELOG_TOPIC_NAME1, CHANGELOG_TOPIC_CONFIG)))).andStubReturn(Collections.emptySet());
    final Map<Subtopology, TopicsInfo> topicGroups = mkMap(mkEntry(SUBTOPOLOGY_0, TOPICS_INFO4));
    final Set<TaskId> tasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);
    final Map<Subtopology, Set<TaskId>> tasksForTopicGroup = mkMap(mkEntry(SUBTOPOLOGY_0, tasks));
    replay(internalTopicManager);
    final ChangelogTopics changelogTopics = new ChangelogTopics(internalTopicManager, topicGroups, tasksForTopicGroup, "[test] ");
    changelogTopics.setup();
    verify(internalTopicManager);
    assertThat(CHANGELOG_TOPIC_CONFIG.numberOfPartitions().orElse(Integer.MIN_VALUE), is(3));
    final TopicPartition changelogPartition0 = new TopicPartition(CHANGELOG_TOPIC_NAME1, 0);
    final TopicPartition changelogPartition1 = new TopicPartition(CHANGELOG_TOPIC_NAME1, 1);
    final TopicPartition changelogPartition2 = new TopicPartition(CHANGELOG_TOPIC_NAME1, 2);
    final TopicPartition sourcePartition0 = new TopicPartition(SOURCE_TOPIC_NAME, 0);
    final TopicPartition sourcePartition1 = new TopicPartition(SOURCE_TOPIC_NAME, 1);
    final TopicPartition sourcePartition2 = new TopicPartition(SOURCE_TOPIC_NAME, 2);
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_0), is(mkSet(sourcePartition0, changelogPartition0)));
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_1), is(mkSet(sourcePartition1, changelogPartition1)));
    assertThat(changelogTopics.preExistingPartitionsFor(TASK_0_2), is(mkSet(sourcePartition2, changelogPartition2)));
    assertThat(changelogTopics.preExistingSourceTopicBasedPartitions(), is(mkSet(sourcePartition0, sourcePartition1, sourcePartition2)));
    assertThat(changelogTopics.preExistingNonSourceTopicBasedPartitions(), is(mkSet(changelogPartition0, changelogPartition1, changelogPartition2)));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) Utils.mkSet(org.apache.kafka.common.utils.Utils.mkSet) Set(java.util.Set) TopicPartition(org.apache.kafka.common.TopicPartition) TopicsInfo(org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo) Subtopology(org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology) Test(org.junit.Test)

Aggregations

TopicsInfo (org.apache.kafka.streams.processor.internals.InternalTopologyBuilder.TopicsInfo)12 TopicPartition (org.apache.kafka.common.TopicPartition)8 Test (org.junit.Test)7 Subtopology (org.apache.kafka.streams.processor.internals.TopologyMetadata.Subtopology)6 Set (java.util.Set)5 TaskId (org.apache.kafka.streams.processor.TaskId)5 PartitionInfo (org.apache.kafka.common.PartitionInfo)4 TaskAssignmentException (org.apache.kafka.streams.errors.TaskAssignmentException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Utils.mkSet (org.apache.kafka.common.utils.Utils.mkSet)3 Collections (java.util.Collections)1 SortedSet (java.util.SortedSet)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 UUID.randomUUID (java.util.UUID.randomUUID)1 Collectors (java.util.stream.Collectors)1