Search in sources :

Example 6 with MockAdminClient

use of org.apache.kafka.clients.admin.MockAdminClient in project apache-kafka-on-k8s by banzaicloud.

the class ConnectUtilsTest method testLookupNullKafkaClusterId.

@Test
public void testLookupNullKafkaClusterId() {
    final Node broker1 = new Node(0, "dummyHost-1", 1234);
    final Node broker2 = new Node(1, "dummyHost-2", 1234);
    List<Node> cluster = Arrays.asList(broker1, broker2);
    MockAdminClient adminClient = new MockAdminClient(cluster, broker1, null);
    assertNull(ConnectUtils.lookupKafkaClusterId(adminClient));
}
Also used : Node(org.apache.kafka.common.Node) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Example 7 with MockAdminClient

use of org.apache.kafka.clients.admin.MockAdminClient in project apache-kafka-on-k8s by banzaicloud.

the class TopicAdminTest method shouldReturnFalseWhenSuppliedNullTopicDescription.

@Test
public void shouldReturnFalseWhenSuppliedNullTopicDescription() {
    Cluster cluster = createCluster(1);
    try (MockAdminClient mockAdminClient = new MockAdminClient(cluster.nodes(), cluster.nodeById(0))) {
        TopicAdmin admin = new TopicAdmin(null, mockAdminClient);
        boolean created = admin.createTopic(null);
        assertFalse(created);
    }
}
Also used : Cluster(org.apache.kafka.common.Cluster) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Example 8 with MockAdminClient

use of org.apache.kafka.clients.admin.MockAdminClient in project apache-kafka-on-k8s by banzaicloud.

the class TopicAdminTest method shouldCreateOneTopicWhenProvidedMultipleDefinitionsWithSameTopicName.

@Test
public void shouldCreateOneTopicWhenProvidedMultipleDefinitionsWithSameTopicName() {
    NewTopic newTopic1 = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
    NewTopic newTopic2 = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
    Cluster cluster = createCluster(1);
    try (MockAdminClient mockAdminClient = new MockAdminClient(cluster.nodes(), cluster.nodeById(0))) {
        TopicAdmin admin = new TopicAdmin(null, mockAdminClient);
        Set<String> newTopicNames = admin.createTopics(newTopic1, newTopic2);
        assertEquals(1, newTopicNames.size());
        assertEquals(newTopic2.name(), newTopicNames.iterator().next());
    }
}
Also used : Cluster(org.apache.kafka.common.Cluster) NewTopic(org.apache.kafka.clients.admin.NewTopic) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Example 9 with MockAdminClient

use of org.apache.kafka.clients.admin.MockAdminClient in project apache-kafka-on-k8s by banzaicloud.

the class TopicAdminTest method shouldNotCreateTopicWhenItAlreadyExists.

@Test
public void shouldNotCreateTopicWhenItAlreadyExists() {
    NewTopic newTopic = TopicAdmin.defineTopic("myTopic").partitions(1).compacted().build();
    Cluster cluster = createCluster(1);
    try (MockAdminClient mockAdminClient = new MockAdminClient(cluster.nodes(), cluster.nodeById(0))) {
        TopicPartitionInfo topicPartitionInfo = new TopicPartitionInfo(0, cluster.nodeById(0), cluster.nodes(), Collections.<Node>emptyList());
        mockAdminClient.addTopic(false, "myTopic", Collections.singletonList(topicPartitionInfo), null);
        TopicAdmin admin = new TopicAdmin(null, mockAdminClient);
        assertFalse(admin.createTopic(newTopic));
    }
}
Also used : TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Cluster(org.apache.kafka.common.Cluster) NewTopic(org.apache.kafka.clients.admin.NewTopic) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Aggregations

MockAdminClient (org.apache.kafka.clients.admin.MockAdminClient)9 Test (org.junit.Test)8 Cluster (org.apache.kafka.common.Cluster)5 NewTopic (org.apache.kafka.clients.admin.NewTopic)3 Node (org.apache.kafka.common.Node)3 TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)2 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 Before (org.junit.Before)1