use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.
the class InternalTopicManagerTest method shouldThrowTimeoutExceptionWhenFuturesNeverCompleteDuringCleanUp.
@Test
public void shouldThrowTimeoutExceptionWhenFuturesNeverCompleteDuringCleanUp() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final MockTime time = new MockTime((Integer) config.get(StreamsConfig.consumerPrefix(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG)) / 3);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
setupCleanUpScenario(admin, streamsConfig, internalTopicConfig1, internalTopicConfig2);
final KafkaFutureImpl<Void> deleteTopicFutureThatNeverCompletes = new KafkaFutureImpl<>();
EasyMock.expect(admin.deleteTopics(mkSet(topic1))).andStubAnswer(() -> new MockDeleteTopicsResult(mkMap(mkEntry(topic1, deleteTopicFutureThatNeverCompletes))));
EasyMock.replay(admin);
assertThrows(TimeoutException.class, () -> topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2))));
}
use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.
the class InternalTopicManagerTest method shouldRetryCreateTopicWhenRetriableExceptionIsThrown.
private void shouldRetryCreateTopicWhenRetriableExceptionIsThrown(final Exception retriableException) {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicFailFuture = new KafkaFutureImpl<>();
createTopicFailFuture.completeExceptionally(retriableException);
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicSuccessfulFuture = new KafkaFutureImpl<>();
createTopicSuccessfulFuture.complete(new TopicMetadataAndConfig(Uuid.randomUuid(), 1, 1, new Config(Collections.emptyList())));
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
final NewTopic newTopic = newTopic(topic1, internalTopicConfig, streamsConfig);
EasyMock.expect(admin.createTopics(mkSet(newTopic))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic1, createTopicSuccessfulFuture))));
EasyMock.expect(admin.createTopics(mkSet(newTopic))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic2, createTopicSuccessfulFuture))));
EasyMock.replay(admin);
topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig)));
}
use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.
the class GlobalStreamThreadTest method before.
@Before
public void before() {
final MaterializedInternal<Object, Object, KeyValueStore<Bytes, byte[]>> materialized = new MaterializedInternal<>(Materialized.with(null, null), new InternalNameProvider() {
@Override
public String newProcessorName(final String prefix) {
return "processorName";
}
@Override
public String newStoreName(final String prefix) {
return GLOBAL_STORE_NAME;
}
}, "store-");
final ProcessorSupplier<Object, Object, Void, Void> processorSupplier = () -> new ContextualProcessor<Object, Object, Void, Void>() {
@Override
public void process(final Record<Object, Object> record) {
}
};
builder.addGlobalStore(new TimestampedKeyValueStoreMaterializer<>(materialized).materialize().withLoggingDisabled(), "sourceName", null, null, null, GLOBAL_STORE_TOPIC_NAME, "processorName", processorSupplier);
baseDirectoryName = TestUtils.tempDirectory().getAbsolutePath();
final HashMap<String, Object> properties = new HashMap<>();
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "blah");
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "testAppId");
properties.put(StreamsConfig.STATE_DIR_CONFIG, baseDirectoryName);
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArraySerde.class.getName());
config = new StreamsConfig(properties);
globalStreamThread = new GlobalStreamThread(builder.rewriteTopology(config).buildGlobalStateTopology(), config, mockConsumer, new StateDirectory(config, time, true, false), 0, new StreamsMetricsImpl(new Metrics(), "test-client", StreamsConfig.METRICS_LATEST, time), time, "clientId", stateRestoreListener, e -> {
});
}
use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.
the class StandbyTaskTest method shouldDeleteStateDirOnTaskCreatedAndEosAlphaUncleanClose.
@SuppressWarnings("deprecation")
@Test
public void shouldDeleteStateDirOnTaskCreatedAndEosAlphaUncleanClose() {
stateManager.close();
EasyMock.expectLastCall();
EasyMock.expect(stateManager.baseDir()).andReturn(baseDir);
EasyMock.replay(stateManager);
final MetricName metricName = setupCloseTaskMetric();
config = new StreamsConfig(mkProperties(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, applicationId), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:2171"), mkEntry(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE))));
task = createStandbyTask();
task.suspend();
task.closeDirty();
final double expectedCloseTaskMetric = 1.0;
verifyCloseTaskMetric(expectedCloseTaskMetric, streamsMetrics, metricName);
EasyMock.verify(stateManager);
assertEquals(Task.State.CLOSED, task.state());
}
use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.
the class StandbyTaskTest method shouldDeleteStateDirOnTaskCreatedAndEosV2UncleanClose.
@Test
public void shouldDeleteStateDirOnTaskCreatedAndEosV2UncleanClose() {
stateManager.close();
EasyMock.expectLastCall();
EasyMock.expect(stateManager.baseDir()).andReturn(baseDir);
EasyMock.replay(stateManager);
final MetricName metricName = setupCloseTaskMetric();
config = new StreamsConfig(mkProperties(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, applicationId), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:2171"), mkEntry(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE_V2))));
task = createStandbyTask();
task.suspend();
task.closeDirty();
final double expectedCloseTaskMetric = 1.0;
verifyCloseTaskMetric(expectedCloseTaskMetric, streamsMetrics, metricName);
EasyMock.verify(stateManager);
assertEquals(Task.State.CLOSED, task.state());
}
Aggregations