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));
}
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);
}
}
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());
}
}
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));
}
}
Aggregations