Search in sources :

Example 1 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project ksql by confluentinc.

the class JoinNodeTest method setupTopicClientExpectations.

private void setupTopicClientExpectations(int streamPartitions, int tablePartitions) {
    Node node = new Node(0, "localhost", 9091);
    List<TopicPartitionInfo> streamPartitionInfoList = IntStream.range(0, streamPartitions).mapToObj(p -> new TopicPartitionInfo(p, node, Collections.emptyList(), Collections.emptyList())).collect(Collectors.toList());
    EasyMock.expect(topicClient.describeTopics(Arrays.asList("test1"))).andReturn(Collections.singletonMap("test1", new TopicDescription("test1", false, streamPartitionInfoList)));
    List<TopicPartitionInfo> tablePartitionInfoList = IntStream.range(0, tablePartitions).mapToObj(p -> new TopicPartitionInfo(p, node, Collections.emptyList(), Collections.emptyList())).collect(Collectors.toList());
    EasyMock.expect(topicClient.describeTopics(Arrays.asList("test2"))).andReturn(Collections.singletonMap("test2", new TopicDescription("test2", false, tablePartitionInfoList)));
    EasyMock.replay(topicClient);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) SchemaKStream(io.confluent.ksql.structured.SchemaKStream) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) SchemaKTable(io.confluent.ksql.structured.SchemaKTable) LogicalPlanBuilder(io.confluent.ksql.structured.LogicalPlanBuilder) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) EasyMock.mock(org.easymock.EasyMock.mock) HashMap(java.util.HashMap) KafkaTopicClient(io.confluent.ksql.util.KafkaTopicClient) Schema(org.apache.kafka.connect.data.Schema) TopologyDescription(org.apache.kafka.streams.TopologyDescription) Map(java.util.Map) MetaStore(io.confluent.ksql.metastore.MetaStore) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LinkedList(java.util.LinkedList) Before(org.junit.Before) Utils(org.apache.kafka.common.utils.Utils) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) SOURCE_NODE(io.confluent.ksql.planner.plan.PlanTestUtil.SOURCE_NODE) Field(org.apache.kafka.connect.data.Field) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) KsqlConfig(io.confluent.ksql.util.KsqlConfig) MetaStoreFixture(io.confluent.ksql.util.MetaStoreFixture) Collectors(java.util.stream.Collectors) List(java.util.List) MAPVALUES_NODE(io.confluent.ksql.planner.plan.PlanTestUtil.MAPVALUES_NODE) KsqlException(io.confluent.ksql.util.KsqlException) Node(org.apache.kafka.common.Node) StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) Assert(org.junit.Assert) Collections(java.util.Collections) Topology(org.apache.kafka.streams.Topology) PlanTestUtil.getNodeByName(io.confluent.ksql.planner.plan.PlanTestUtil.getNodeByName) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) TopicDescription(org.apache.kafka.clients.admin.TopicDescription)

Example 2 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.

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());
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) NewTopic(org.apache.kafka.clients.admin.NewTopic) Test(org.junit.Test)

Example 3 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.

the class WorkerUtilsTest method testExistingTopicsMustHaveRequestedNumberOfPartitions.

@Test(expected = RuntimeException.class)
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);
    WorkerUtils.createTopics(log, adminClient, Collections.singletonMap(TEST_TOPIC, NEW_TEST_TOPIC), false);
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.

the class StreamsResetterTest method shouldDeleteTopic.

@Test
public void shouldDeleteTopic() throws InterruptedException, ExecutionException {
    Cluster cluster = createCluster(1);
    try (MockAdminClient adminClient = new MockAdminClient(cluster.nodes(), cluster.nodeById(0))) {
        TopicPartitionInfo topicPartitionInfo = new TopicPartitionInfo(0, cluster.nodeById(0), cluster.nodes(), Collections.<Node>emptyList());
        adminClient.addTopic(false, TOPIC, Collections.singletonList(topicPartitionInfo), null);
        streamsResetter.doDelete(Collections.singletonList(TOPIC), adminClient);
        assertEquals(Collections.emptySet(), adminClient.listTopics().names().get());
    }
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Cluster(org.apache.kafka.common.Cluster) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Example 5 with TopicPartitionInfo

use of org.apache.kafka.common.TopicPartitionInfo in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopicManagerTest method shouldNotThrowExceptionIfExistsWithDifferentReplication.

@Test
public void shouldNotThrowExceptionIfExistsWithDifferentReplication() {
    mockAdminClient.addTopic(false, topic, Collections.singletonList(new TopicPartitionInfo(0, broker1, cluster, Collections.<Node>emptyList())), null);
    // attempt to create it again with replication 1
    final InternalTopicManager internalTopicManager2 = new InternalTopicManager(mockAdminClient, new StreamsConfig(config));
    final InternalTopicConfig internalTopicConfig = new RepartitionTopicConfig(topic, Collections.<String, String>emptyMap());
    internalTopicConfig.setNumberOfPartitions(1);
    internalTopicManager2.makeReady(Collections.singletonMap(topic, internalTopicConfig));
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Aggregations

TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)62 Test (org.junit.Test)33 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)31 Node (org.apache.kafka.common.Node)28 ArrayList (java.util.ArrayList)20 MockAdminClient (org.apache.kafka.clients.admin.MockAdminClient)18 NewTopic (org.apache.kafka.clients.admin.NewTopic)16 HashMap (java.util.HashMap)14 Cluster (org.apache.kafka.common.Cluster)11 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)11 StreamsConfig (org.apache.kafka.streams.StreamsConfig)11 Test (org.junit.jupiter.api.Test)10 TopicPartition (org.apache.kafka.common.TopicPartition)8 ConfigResource (org.apache.kafka.common.config.ConfigResource)8 Map (java.util.Map)7 AdminClient (org.apache.kafka.clients.admin.AdminClient)7 Config (org.apache.kafka.clients.admin.Config)7 TopicMetadataAndConfig (org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig)7 TopicConfig (org.apache.kafka.common.config.TopicConfig)7 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)6