use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamThreadTest method shouldOnlyShutdownOnce.
@Test
public void shouldOnlyShutdownOnce() {
final Consumer<byte[], byte[]> consumer = EasyMock.createNiceMock(Consumer.class);
final ConsumerGroupMetadata consumerGroupMetadata = mock(ConsumerGroupMetadata.class);
expect(consumer.groupMetadata()).andStubReturn(consumerGroupMetadata);
expect(consumerGroupMetadata.groupInstanceId()).andReturn(Optional.empty());
EasyMock.replay(consumerGroupMetadata);
final TaskManager taskManager = EasyMock.createNiceMock(TaskManager.class);
expect(taskManager.producerClientIds()).andStubReturn(Collections.emptySet());
taskManager.shutdown(true);
EasyMock.expectLastCall();
EasyMock.replay(taskManager, consumer);
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, StreamsConfig.METRICS_LATEST, mockTime);
final TopologyMetadata topologyMetadata = new TopologyMetadata(internalTopologyBuilder, config);
topologyMetadata.buildAndRewriteTopology();
final StreamThread thread = buildStreamThread(consumer, taskManager, config, topologyMetadata).updateThreadMetadata(getSharedAdminClientId(CLIENT_ID));
thread.shutdown();
// Execute the run method. Verification of the mock will check that shutdown was only done once
thread.run();
verify(taskManager);
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldSendOffsetToTxOnEosCommit.
@Test
public void shouldSendOffsetToTxOnEosCommit() {
eosAlphaStreamsProducer.commitTransaction(offsetsAndMetadata, new ConsumerGroupMetadata("appId"));
assertThat(eosAlphaMockProducer.sentOffsets(), is(true));
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldCommitTxOnEosCommit.
@Test
public void shouldCommitTxOnEosCommit() {
eosAlphaStreamsProducer.send(record, null);
assertThat(eosAlphaMockProducer.transactionInFlight(), is(true));
eosAlphaStreamsProducer.commitTransaction(offsetsAndMetadata, new ConsumerGroupMetadata("appId"));
assertThat(eosAlphaMockProducer.transactionInFlight(), is(false));
assertThat(eosAlphaMockProducer.uncommittedRecords().isEmpty(), is(true));
assertThat(eosAlphaMockProducer.uncommittedOffsets().isEmpty(), is(true));
assertThat(eosAlphaMockProducer.history().size(), is(1));
assertThat(eosAlphaMockProducer.history().get(0), is(record));
assertThat(eosAlphaMockProducer.consumerGroupOffsetsHistory().size(), is(1));
assertThat(eosAlphaMockProducer.consumerGroupOffsetsHistory().get(0).get("appId"), is(offsetsAndMetadata));
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldCommitTxWithApplicationIdOnEosAlphaCommit.
@Test
public void shouldCommitTxWithApplicationIdOnEosAlphaCommit() {
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);
eosAlphaStreamsProducerWithMock.initTransaction();
// call `send()` to start a transaction
eosAlphaStreamsProducerWithMock.send(record, null);
eosAlphaStreamsProducerWithMock.commitTransaction(null, new ConsumerGroupMetadata("appId"));
verify(mockedProducer);
}
use of org.apache.kafka.clients.consumer.ConsumerGroupMetadata in project kafka by apache.
the class StreamsProducerTest method shouldThrowStreamsExceptionOnEosSendOffsetError.
@Test
public void shouldThrowStreamsExceptionOnEosSendOffsetError() {
eosAlphaMockProducer.sendOffsetsToTransactionException = new KafkaException("KABOOM!");
final StreamsException thrown = assertThrows(StreamsException.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("Error encountered trying to commit a transaction [test]"));
}
Aggregations