Search in sources :

Example 6 with TopologyConfig

use of org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig in project kafka by apache.

the class InternalTopologyBuilderTest method shouldOverrideGlobalStreamsConfigWhenGivenNamedTopologyProps.

@Test
public void shouldOverrideGlobalStreamsConfigWhenGivenNamedTopologyProps() {
    final Properties topologyOverrides = new Properties();
    topologyOverrides.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 12345L);
    topologyOverrides.put(StreamsConfig.MAX_TASK_IDLE_MS_CONFIG, 500L);
    topologyOverrides.put(StreamsConfig.TASK_TIMEOUT_MS_CONFIG, 1000L);
    topologyOverrides.put(StreamsConfig.BUFFERED_RECORDS_PER_PARTITION_CONFIG, 15);
    topologyOverrides.put(StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, MockTimestampExtractor.class);
    topologyOverrides.put(StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG, LogAndContinueExceptionHandler.class);
    final StreamsConfig config = new StreamsConfig(StreamsTestUtils.getStreamsConfig());
    final InternalTopologyBuilder topologyBuilder = new InternalTopologyBuilder(new TopologyConfig("my-topology", config, topologyOverrides));
    assertThat(topologyBuilder.topologyConfigs().cacheSize, is(12345L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().maxTaskIdleMs, equalTo(500L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().taskTimeoutMs, equalTo(1000L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().maxBufferedSize, equalTo(15));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().timestampExtractor.getClass(), equalTo(MockTimestampExtractor.class));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().deserializationExceptionHandler.getClass(), equalTo(LogAndContinueExceptionHandler.class));
}
Also used : MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) Utils.mkProperties(org.apache.kafka.common.utils.Utils.mkProperties) Properties(java.util.Properties) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 7 with TopologyConfig

use of org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig in project kafka by apache.

the class InternalTopologyBuilderTest method shouldNotOverrideGlobalStreamsConfigWhenGivenUnnamedTopologyProps.

@Test
public void shouldNotOverrideGlobalStreamsConfigWhenGivenUnnamedTopologyProps() {
    final Properties streamsProps = StreamsTestUtils.getStreamsConfig();
    streamsProps.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 12345L);
    streamsProps.put(StreamsConfig.MAX_TASK_IDLE_MS_CONFIG, 500L);
    streamsProps.put(StreamsConfig.TASK_TIMEOUT_MS_CONFIG, 1000L);
    streamsProps.put(StreamsConfig.BUFFERED_RECORDS_PER_PARTITION_CONFIG, 15);
    streamsProps.put(StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, MockTimestampExtractor.class);
    streamsProps.put(StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG, LogAndContinueExceptionHandler.class);
    final StreamsConfig config = new StreamsConfig(streamsProps);
    final InternalTopologyBuilder topologyBuilder = new InternalTopologyBuilder(new TopologyConfig("my-topology", config, new Properties()));
    assertThat(topologyBuilder.topologyConfigs().cacheSize, is(12345L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().maxTaskIdleMs, is(500L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().taskTimeoutMs, is(1000L));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().maxBufferedSize, is(15));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().timestampExtractor.getClass(), is(MockTimestampExtractor.class));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().deserializationExceptionHandler.getClass(), is(LogAndContinueExceptionHandler.class));
}
Also used : MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) Utils.mkProperties(org.apache.kafka.common.utils.Utils.mkProperties) Properties(java.util.Properties) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 8 with TopologyConfig

use of org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig in project kafka by apache.

the class InternalTopologyBuilder method setStreamsConfig.

public final synchronized void setStreamsConfig(final StreamsConfig applicationConfig) {
    Objects.requireNonNull(applicationConfig, "config can't be null");
    topologyConfigs = new TopologyConfig(applicationConfig);
}
Also used : TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)

Example 9 with TopologyConfig

use of org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig in project kafka by apache.

the class InternalTopologyBuilderTest method shouldSetTopologyConfigOnRewriteTopology.

@Test
public void shouldSetTopologyConfigOnRewriteTopology() {
    final Properties globalProps = StreamsTestUtils.getStreamsConfig();
    globalProps.put(StreamsConfig.MAX_TASK_IDLE_MS_CONFIG, 100L);
    final StreamsConfig globalStreamsConfig = new StreamsConfig(globalProps);
    final InternalTopologyBuilder topologyBuilder = builder.rewriteTopology(globalStreamsConfig);
    assertThat(topologyBuilder.topologyConfigs(), equalTo(new TopologyConfig(null, globalStreamsConfig, new Properties())));
    assertThat(topologyBuilder.topologyConfigs().getTaskConfig().maxTaskIdleMs, equalTo(100L));
}
Also used : Utils.mkProperties(org.apache.kafka.common.utils.Utils.mkProperties) Properties(java.util.Properties) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 10 with TopologyConfig

use of org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig in project kafka by apache.

the class ActiveTaskCreatorTest method createTasks.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void createTasks() {
    final TaskId task00 = new TaskId(0, 0);
    final TaskId task01 = new TaskId(0, 1);
    final ProcessorTopology topology = mock(ProcessorTopology.class);
    final SourceNode sourceNode = mock(SourceNode.class);
    reset(builder, stateDirectory);
    expect(builder.topologyConfigs()).andStubReturn(new TopologyConfig(new StreamsConfig(properties)));
    expect(builder.buildSubtopology(0)).andReturn(topology).anyTimes();
    expect(stateDirectory.getOrCreateDirectoryForTask(task00)).andReturn(mock(File.class));
    expect(stateDirectory.checkpointFileFor(task00)).andReturn(mock(File.class));
    expect(stateDirectory.getOrCreateDirectoryForTask(task01)).andReturn(mock(File.class));
    expect(stateDirectory.checkpointFileFor(task01)).andReturn(mock(File.class));
    expect(topology.storeToChangelogTopic()).andReturn(Collections.emptyMap()).anyTimes();
    expect(topology.source("topic")).andReturn(sourceNode).anyTimes();
    expect(sourceNode.getTimestampExtractor()).andReturn(mock(TimestampExtractor.class)).anyTimes();
    expect(topology.globalStateStores()).andReturn(Collections.emptyList()).anyTimes();
    expect(topology.terminalNodes()).andStubReturn(Collections.singleton(sourceNode.name()));
    expect(topology.sources()).andStubReturn(Collections.singleton(sourceNode));
    replay(builder, stateDirectory, topology, sourceNode);
    final StreamsConfig config = new StreamsConfig(properties);
    activeTaskCreator = new ActiveTaskCreator(new TopologyMetadata(builder, config), config, streamsMetrics, stateDirectory, changeLogReader, new ThreadCache(new LogContext(), 0L, streamsMetrics), new MockTime(), mockClientSupplier, "clientId-StreamThread-0", uuid, new LogContext().logger(ActiveTaskCreator.class));
    assertThat(activeTaskCreator.createTasks(mockClientSupplier.consumer, mkMap(mkEntry(task00, Collections.singleton(new TopicPartition("topic", 0))), mkEntry(task01, Collections.singleton(new TopicPartition("topic", 1))))).stream().map(Task::id).collect(Collectors.toSet()), equalTo(mkSet(task00, task01)));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) LogContext(org.apache.kafka.common.utils.LogContext) TopicPartition(org.apache.kafka.common.TopicPartition) ThreadCache(org.apache.kafka.streams.state.internals.ThreadCache) File(java.io.File) TopologyConfig(org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig)

Aggregations

TopologyConfig (org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)17 Properties (java.util.Properties)14 Utils.mkProperties (org.apache.kafka.common.utils.Utils.mkProperties)13 StreamsConfig (org.apache.kafka.streams.StreamsConfig)7 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)5 Test (org.junit.Test)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 LogContext (org.apache.kafka.common.utils.LogContext)3 MockKeyValueStore (org.apache.kafka.test.MockKeyValueStore)3 MockTime (org.apache.kafka.common.utils.MockTime)2 LogAndContinueExceptionHandler (org.apache.kafka.streams.errors.LogAndContinueExceptionHandler)2 TaskId (org.apache.kafka.streams.processor.TaskId)2 ThreadCache (org.apache.kafka.streams.state.internals.ThreadCache)2 MockTimestampExtractor (org.apache.kafka.test.MockTimestampExtractor)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1