@@ -141,6 +141,63 @@ protected void testKafkaFunctionality(
141141 }
142142 }
143143
144+ protected void testKafkaTransactionalFunctionality (String bootstrapServers ) throws Exception {
145+ Properties adminClientProperties = new Properties ();
146+ adminClientProperties .put (AdminClientConfig .BOOTSTRAP_SERVERS_CONFIG , bootstrapServers );
147+
148+ Properties consumerProperties = new Properties ();
149+ consumerProperties .put (ConsumerConfig .BOOTSTRAP_SERVERS_CONFIG , bootstrapServers );
150+ consumerProperties .put (ConsumerConfig .GROUP_ID_CONFIG , "tc-" + UUID .randomUUID ());
151+ consumerProperties .put (ConsumerConfig .AUTO_OFFSET_RESET_CONFIG , "earliest" );
152+ consumerProperties .put (ConsumerConfig .ISOLATION_LEVEL_CONFIG , "read_committed" );
153+
154+ Properties producerProperties = new Properties ();
155+ producerProperties .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , bootstrapServers );
156+ producerProperties .put (ProducerConfig .TRANSACTIONAL_ID_CONFIG , "tc-" + UUID .randomUUID ());
157+ // Fail fast if the transaction state topic can not be created
158+ producerProperties .put (ProducerConfig .MAX_BLOCK_MS_CONFIG , "10000" );
159+
160+ try (
161+ AdminClient adminClient = AdminClient .create (adminClientProperties );
162+ KafkaProducer <String , String > producer = new KafkaProducer <>(
163+ producerProperties ,
164+ new StringSerializer (),
165+ new StringSerializer ()
166+ );
167+ KafkaConsumer <String , String > consumer = new KafkaConsumer <>(
168+ consumerProperties ,
169+ new StringDeserializer (),
170+ new StringDeserializer ()
171+ );
172+ ) {
173+ String topicName = "messages-" + UUID .randomUUID ();
174+
175+ Collection <NewTopic > topics = Collections .singletonList (new NewTopic (topicName , 1 , (short ) 1 ));
176+ adminClient .createTopics (topics ).all ().get (30 , TimeUnit .SECONDS );
177+
178+ consumer .subscribe (Collections .singletonList (topicName ));
179+
180+ producer .initTransactions ();
181+ producer .beginTransaction ();
182+ producer .send (new ProducerRecord <>(topicName , "testcontainers" , "rulezzz" )).get ();
183+ producer .commitTransaction ();
184+
185+ Awaitility
186+ .await ()
187+ .atMost (Duration .ofSeconds (10 ))
188+ .untilAsserted (() -> {
189+ ConsumerRecords <String , String > records = consumer .poll (Duration .ofMillis (100 ));
190+
191+ assertThat (records )
192+ .hasSize (1 )
193+ .extracting (ConsumerRecord ::topic , ConsumerRecord ::key , ConsumerRecord ::value )
194+ .containsExactly (tuple (topicName , "testcontainers" , "rulezzz" ));
195+ });
196+
197+ consumer .unsubscribe ();
198+ }
199+ }
200+
144201 protected static String getJaasConfig () {
145202 String jaasConfig =
146203 "org.apache.kafka.common.security.plain.PlainLoginModule required " +
0 commit comments