How to use testKafkaFunctionality method of com.example.kafkacluster.KafkaContainerClusterTest class

Best Testcontainers-java code snippet using com.example.kafkacluster.KafkaContainerClusterTest.testKafkaFunctionality

Source:KafkaContainerClusterTest.java Github

copy

Full Screen

...29 ) {30 cluster.start();31 String bootstrapServers = cluster.getBootstrapServers();32 assertThat(cluster.getBrokers()).hasSize(3);33 testKafkaFunctionality(bootstrapServers, 3, 2);34 }35 }36 protected void testKafkaFunctionality(String bootstrapServers, int partitions, int rf) throws Exception {37 try (38 AdminClient adminClient = AdminClient.create(ImmutableMap.of(39 AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers40 ));41 KafkaProducer<String, String> producer = new KafkaProducer<>(42 ImmutableMap.of(43 ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers,44 ProducerConfig.CLIENT_ID_CONFIG, UUID.randomUUID().toString()45 ),46 new StringSerializer(),47 new StringSerializer()48 );49 KafkaConsumer<String, String> consumer = new KafkaConsumer<>(50 ImmutableMap.of(...

Full Screen

Full Screen

testKafkaFunctionality

Using AI Code Generation

copy

Full Screen

1 public void testKafkaCluster() throws Exception {2 testKafkaFunctionality();3 }4}5package com.example.kafkacluster;6import org.apache.kafka.clients.consumer.Consumer;7import org.apache.kafka.clients.consumer.ConsumerConfig;8import org.apache.kafka.clients.consumer.ConsumerRecords;9import org.apache.kafka.clients.consumer.KafkaConsumer;10import org.apache.kafka.clients.producer.KafkaProducer;11import org.apache.kafka.clients.producer.Producer;12import org.apache.kafka.clients.producer.ProducerConfig;13import org.apache.kafka.clients.producer.ProducerRecord;14import org.apache.kafka.common.serialization.StringDeserializer;15import org.apache.kafka.common.serialization.StringSerializer;16import org.junit.Test;17import org.slf4j.Logger;18import org.slf4j.LoggerFactory;19import org.testcontainers.containers.KafkaContainer;20import org.testcontainers.containers.Network;21import org.testcontainers.containers.output.Slf4jLogConsumer;22import org.testcontainers.utility.DockerImageName;23import java.time.Duration;24import java.util.Collections;25import java.util.Properties;26import java.util.concurrent.ExecutionException;27public class KafkaContainerClusterTest {28 private static final Logger logger = LoggerFactory.getLogger(KafkaContainerClusterTest.class);29 public void testKafkaFunctionality() throws ExecutionException, InterruptedException {30 Network network = Network.newNetwork();31 KafkaContainer zookeeperContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-zookeeper:5.5.1"));32 zookeeperContainer.withNetwork(network);33 zookeeperContainer.withNetworkAliases("zookeeper");34 zookeeperContainer.start();35 KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.5.1"));36 kafkaContainer.withNetwork(network);37 kafkaContainer.withNetworkAliases("kafka");38 kafkaContainer.start();39 Properties producerProperties = new Properties();40 producerProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaContainer.getBootstrapServers());41 producerProperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());42 producerProperties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in KafkaContainerClusterTest

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful