use of org.apache.kafka.common.errors.LeaderNotAvailableException in project kafka by apache.
the class KafkaBasedLogTest method testProducerError.
@Test
public void testProducerError() throws Exception {
expectStart();
TestFuture<RecordMetadata> tp0Future = new TestFuture<>();
ProducerRecord<String, String> tp0Record = new ProducerRecord<>(TOPIC, TP0_KEY, TP0_VALUE);
Capture<org.apache.kafka.clients.producer.Callback> callback0 = EasyMock.newCapture();
EasyMock.expect(producer.send(EasyMock.eq(tp0Record), EasyMock.capture(callback0))).andReturn(tp0Future);
expectStop();
PowerMock.replayAll();
Map<TopicPartition, Long> endOffsets = new HashMap<>();
endOffsets.put(TP0, 0L);
endOffsets.put(TP1, 0L);
consumer.updateEndOffsets(endOffsets);
store.start();
assertEquals(CONSUMER_ASSIGNMENT, consumer.assignment());
assertEquals(0L, consumer.position(TP0));
assertEquals(0L, consumer.position(TP1));
final AtomicReference<Throwable> setException = new AtomicReference<>();
store.send(TP0_KEY, TP0_VALUE, (metadata, exception) -> {
// Should only be invoked once
assertNull(setException.get());
setException.set(exception);
});
KafkaException exc = new LeaderNotAvailableException("Error");
tp0Future.resolve(exc);
callback0.getValue().onCompletion(null, exc);
assertNotNull(setException.get());
store.stop();
assertFalse(Whitebox.<Thread>getInternalState(store, "thread").isAlive());
assertTrue(consumer.closed());
PowerMock.verifyAll();
}
use of org.apache.kafka.common.errors.LeaderNotAvailableException in project kafka by apache.
the class KafkaBasedLogTest method testReadEndOffsetsUsingAdminThatFailsWithRetriable.
@Test
public void testReadEndOffsetsUsingAdminThatFailsWithRetriable() throws Exception {
// Create a log that uses the admin supplier
setupWithAdmin();
expectProducerAndConsumerCreate();
Set<TopicPartition> tps = new HashSet<>(Arrays.asList(TP0, TP1));
Map<TopicPartition, Long> endOffsets = new HashMap<>();
endOffsets.put(TP0, 0L);
endOffsets.put(TP1, 0L);
// Getting end offsets upon startup should work fine
admin.endOffsets(EasyMock.eq(tps));
PowerMock.expectLastCall().andReturn(endOffsets).times(1);
// Getting end offsets using the admin client should fail with leader not available
admin.endOffsets(EasyMock.eq(tps));
PowerMock.expectLastCall().andThrow(new LeaderNotAvailableException("retry"));
PowerMock.replayAll();
store.start();
assertThrows(LeaderNotAvailableException.class, () -> store.readEndOffsets(tps));
}
Aggregations