Search in sources :

Example 1 with MockAdminClient

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

the class ConnectUtilsTest method testLookupKafkaClusterIdTimeout.

@Test(expected = ConnectException.class)
public void testLookupKafkaClusterIdTimeout() {
    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);
    adminClient.timeoutNextRequest(1);
    ConnectUtils.lookupKafkaClusterId(adminClient);
}
Also used : Node(org.apache.kafka.common.Node) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) Test(org.junit.Test)

Example 2 with MockAdminClient

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

the class TopicAdminTest method shouldCreateTopicWhenItDoesNotExist.

@Test
public void shouldCreateTopicWhenItDoesNotExist() {
    NewTopic newTopic = 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);
        assertTrue(admin.createTopic(newTopic));
    }
}
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 3 with MockAdminClient

use of org.apache.kafka.clients.admin.MockAdminClient 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 4 with MockAdminClient

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

the class InternalTopicManagerTest method init.

@Before
public void init() {
    mockAdminClient = new MockAdminClient(cluster, broker1);
    internalTopicManager = new InternalTopicManager(mockAdminClient, new StreamsConfig(config));
}
Also used : MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 5 with MockAdminClient

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

the class ConnectUtilsTest method testLookupKafkaClusterId.

@Test
public void testLookupKafkaClusterId() {
    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);
    assertEquals(MockAdminClient.DEFAULT_CLUSTER_ID, ConnectUtils.lookupKafkaClusterId(adminClient));
}
Also used : Node(org.apache.kafka.common.Node) 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