use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method testThrowTaskMigrateExceptionOnEosSendOffset.
private void testThrowTaskMigrateExceptionOnEosSendOffset(final RuntimeException exception) {
// cannot use `eosMockProducer.fenceProducer()` because this would already trigger in `beginTransaction()`
eosAlphaMockProducer.sendOffsetsToTransactionException = exception;
final TaskMigratedException thrown = assertThrows(TaskMigratedException.class, // `sendOffsetsToTransaction()` would throw an NPE on `null` offsets
() -> eosAlphaStreamsProducer.commitTransaction(null, new ConsumerGroupMetadata("appId")));
assertThat(thrown.getCause(), is(eosAlphaMockProducer.sendOffsetsToTransactionException));
assertThat(thrown.getMessage(), is("Producer got fenced trying to commit a transaction [test];" + " it means all tasks belonging to this thread should be migrated."));
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldCommitTxWithConsumerGroupMetadataOnEosBetaCommit.
@Test
public void shouldCommitTxWithConsumerGroupMetadataOnEosBetaCommit() {
mockedProducer.initTransactions();
expectLastCall();
mockedProducer.beginTransaction();
expectLastCall();
expect(mockedProducer.send(record, null)).andReturn(null);
mockedProducer.sendOffsetsToTransaction(null, new ConsumerGroupMetadata("appId"));
expectLastCall();
mockedProducer.commitTransaction();
expectLastCall();
replay(mockedProducer);
final StreamsProducer streamsProducer = new StreamsProducer(eosBetaConfig, "threadId-StreamThread-0", clientSupplier, null, UUID.randomUUID(), logContext, mockTime);
streamsProducer.initTransaction();
// call `send()` to start a transaction
streamsProducer.send(record, null);
streamsProducer.commitTransaction(null, new ConsumerGroupMetadata("appId"));
verify(mockedProducer);
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldThrowStreamsExceptionOnEosCommitTxError.
@Test
public void shouldThrowStreamsExceptionOnEosCommitTxError() {
eosAlphaMockProducer.commitTransactionException = new KafkaException("KABOOM!");
final StreamsException thrown = assertThrows(StreamsException.class, () -> eosAlphaStreamsProducer.commitTransaction(offsetsAndMetadata, new ConsumerGroupMetadata("appId")));
assertThat(eosAlphaMockProducer.sentOffsets(), is(true));
assertThat(thrown.getCause(), is(eosAlphaMockProducer.commitTransactionException));
assertThat(thrown.getMessage(), is("Error encountered trying to commit a transaction [test]"));
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldBeginTxOnEosCommit.
@Test
public void shouldBeginTxOnEosCommit() {
mockedProducer.initTransactions();
mockedProducer.beginTransaction();
mockedProducer.sendOffsetsToTransaction(offsetsAndMetadata, new ConsumerGroupMetadata("appId"));
mockedProducer.commitTransaction();
expectLastCall();
replay(mockedProducer);
eosAlphaStreamsProducerWithMock.initTransaction();
eosAlphaStreamsProducerWithMock.commitTransaction(offsetsAndMetadata, new ConsumerGroupMetadata("appId"));
verify(mockedProducer);
}
Aggregations