philipnee commented on code in PR #12149:
URL: https://github.com/apache/kafka/pull/12149#discussion_r980725833
##########
clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java:
##########
@@ -1237,6 +1238,35 @@ public void testInitTransactionWhileThrottled() {
}
}
+ @Test
+ public void testClusterAuthorizationFailure() throws Exception {
+ int maxBlockMs = 500;
+
+ Map<String, Object> configs = new HashMap<>();
+ configs.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, maxBlockMs);
+ configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000");
+ configs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
+ configs.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "some-txn");
+
+ Time time = new MockTime(1);
+ MetadataResponse initialUpdateResponse =
RequestTestUtils.metadataUpdateWith(1, singletonMap("topic", 1));
+ ProducerMetadata metadata = newMetadata(0, Long.MAX_VALUE);
+
+ MockClient client = new MockClient(time, metadata);
+ client.updateMetadata(initialUpdateResponse);
+
+
client.prepareResponse(FindCoordinatorResponse.prepareResponse(Errors.NONE,
"some-txn", NODE));
+ client.prepareResponse(initProducerIdResponse(1L, (short) 5,
Errors.CLUSTER_AUTHORIZATION_FAILED));
+
+ try (Producer<String, String> producer = kafkaProducer(configs, new
StringSerializer(),
+ new StringSerializer(), metadata, client, null, time)) {
+ assertThrows(ClusterAuthorizationException.class, () ->
producer.initTransactions());
+ // retry initTransactions after the ClusterAuthorizationException
not being thrown
+ client.prepareResponse(initProducerIdResponse(1L, (short) 5,
Errors.NONE));
+ producer.initTransactions();
Review Comment:
hmm... consistently having issue to get a Errors.NONE response. I can
sometimes get a ClusterAuthorizationException. Not sure why is it
##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java:
##########
@@ -607,6 +608,14 @@ public synchronized void
handleCompletedBatch(ProducerBatch batch, ProduceRespon
removeInFlightBatch(batch);
}
+ public synchronized void transitionToUninitialized(RuntimeException
exception) {
+ transitionTo(State.UNINITIALIZED);
+ lastError = null;
+ if (pendingTransition != null) {
Review Comment:
I'm actually not sure if this is needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]