use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StreamThreadTest method runAndVerifyFailedStreamThreadRecording.
public void runAndVerifyFailedStreamThreadRecording(final boolean shouldFail) {
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(consumer, consumerGroupMetadata);
final TaskManager taskManager = EasyMock.createNiceMock(TaskManager.class);
expect(taskManager.producerClientIds()).andStubReturn(Collections.emptySet());
final StreamsMetricsImpl streamsMetrics = new StreamsMetricsImpl(metrics, CLIENT_ID, StreamsConfig.METRICS_LATEST, mockTime);
final TopologyMetadata topologyMetadata = new TopologyMetadata(internalTopologyBuilder, config);
topologyMetadata.buildAndRewriteTopology();
final StreamThread thread = new StreamThread(mockTime, config, null, consumer, consumer, null, null, taskManager, streamsMetrics, topologyMetadata, CLIENT_ID, new LogContext(""), new AtomicInteger(), new AtomicLong(Long.MAX_VALUE), new LinkedList<>(), null, (e, b) -> {
}, null) {
@Override
void runOnce() {
setState(StreamThread.State.PENDING_SHUTDOWN);
if (shouldFail) {
throw new StreamsException(Thread.currentThread().getName());
}
}
};
EasyMock.replay(taskManager);
thread.updateThreadMetadata("metadata");
thread.run();
final Metric failedThreads = StreamsTestUtils.getMetricByName(metrics.metrics(), "failed-stream-threads", "stream-metrics");
assertThat(failedThreads.metricValue(), is(shouldFail ? 1.0 : 0.0));
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StoreChangelogReaderTest method shouldThrowIfEndOffsetsFail.
@Test
public void shouldThrowIfEndOffsetsFail() {
EasyMock.expect(storeMetadata.offset()).andReturn(10L).anyTimes();
EasyMock.replay(activeStateManager, storeMetadata, store);
final MockAdminClient adminClient = new MockAdminClient() {
@Override
public ListOffsetsResult listOffsets(final Map<TopicPartition, OffsetSpec> topicPartitionOffsets, final ListOffsetsOptions options) {
throw kaboom;
}
};
adminClient.updateEndOffsets(Collections.singletonMap(tp, 0L));
final StoreChangelogReader changelogReader = new StoreChangelogReader(time, config, logContext, adminClient, consumer, callback);
changelogReader.register(tp, activeStateManager);
final StreamsException thrown = assertThrows(StreamsException.class, () -> changelogReader.restore(Collections.emptyMap()));
assertEquals(kaboom, thrown.getCause());
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StoreChangelogReaderTest method shouldThrowIfPositionFail.
@Test
public void shouldThrowIfPositionFail() {
final TaskId taskId = new TaskId(0, 0);
EasyMock.expect(activeStateManager.taskId()).andReturn(taskId);
EasyMock.expect(storeMetadata.offset()).andReturn(10L).anyTimes();
EasyMock.replay(activeStateManager, storeMetadata, store);
final MockConsumer<byte[], byte[]> consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {
@Override
public long position(final TopicPartition partition) {
throw kaboom;
}
};
adminClient.updateEndOffsets(Collections.singletonMap(tp, 10L));
final StoreChangelogReader changelogReader = new StoreChangelogReader(time, config, logContext, adminClient, consumer, callback);
changelogReader.register(tp, activeStateManager);
final StreamsException thrown = assertThrows(StreamsException.class, () -> changelogReader.restore(Collections.singletonMap(taskId, mock(Task.class))));
assertEquals(kaboom, thrown.getCause());
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StoreChangelogReaderTest method shouldThrowIfUnsubscribeFail.
@Test
public void shouldThrowIfUnsubscribeFail() {
EasyMock.replay(stateManager, storeMetadata, store);
final MockConsumer<byte[], byte[]> consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {
@Override
public void unsubscribe() {
throw kaboom;
}
};
final StoreChangelogReader changelogReader = new StoreChangelogReader(time, config, logContext, adminClient, consumer, callback);
final StreamsException thrown = assertThrows(StreamsException.class, changelogReader::clear);
assertEquals(kaboom, thrown.getCause());
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StoreChangelogReaderTest method shouldThrowIfCommittedOffsetsFail.
@Test
public void shouldThrowIfCommittedOffsetsFail() {
final TaskId taskId = new TaskId(0, 0);
EasyMock.expect(stateManager.taskId()).andReturn(taskId);
EasyMock.expect(stateManager.changelogAsSource(tp)).andReturn(true).anyTimes();
EasyMock.expect(storeMetadata.offset()).andReturn(10L).anyTimes();
EasyMock.replay(stateManager, storeMetadata, store);
final MockConsumer<byte[], byte[]> consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {
@Override
public Map<TopicPartition, OffsetAndMetadata> committed(final Set<TopicPartition> partitions) {
throw kaboom;
}
};
adminClient.updateEndOffsets(Collections.singletonMap(tp, 10L));
final StoreChangelogReader changelogReader = new StoreChangelogReader(time, config, logContext, adminClient, consumer, callback);
changelogReader.setMainConsumer(consumer);
changelogReader.register(tp, stateManager);
final StreamsException thrown = assertThrows(StreamsException.class, () -> changelogReader.restore(Collections.singletonMap(taskId, mock(Task.class))));
assertEquals(kaboom, thrown.getCause());
}
Aggregations