Search in sources :

Example 91 with StreamsConfig

use of org.apache.kafka.streams.StreamsConfig 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 92 with StreamsConfig

use of org.apache.kafka.streams.StreamsConfig 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 93 with StreamsConfig

use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.

the class InternalTopologyBuilderTest method shouldAddTimestampExtractorPerSource.

@Test
public void shouldAddTimestampExtractorPerSource() {
    builder.addSource(null, "source", new MockTimestampExtractor(), null, null, "topic");
    final ProcessorTopology processorTopology = builder.rewriteTopology(new StreamsConfig(StreamsTestUtils.getStreamsConfig())).buildTopology();
    assertThat(processorTopology.source("topic").getTimestampExtractor(), instanceOf(MockTimestampExtractor.class));
}
Also used : MockTimestampExtractor(org.apache.kafka.test.MockTimestampExtractor) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 94 with StreamsConfig

use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.

the class GlobalStateManagerImplTest method shouldNotRetryWhenPartitionsForThrowsTimeoutExceptionAndTaskTimeoutIsZero.

@Test
public void shouldNotRetryWhenPartitionsForThrowsTimeoutExceptionAndTaskTimeoutIsZero() {
    final AtomicInteger numberOfCalls = new AtomicInteger(0);
    consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {

        @Override
        public List<PartitionInfo> partitionsFor(final String topic) {
            numberOfCalls.incrementAndGet();
            throw new TimeoutException("KABOOM!");
        }
    };
    initializeConsumer(0, 0, t1, t2, t3, t4);
    streamsConfig = new StreamsConfig(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, "appId"), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234"), mkEntry(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath()), mkEntry(StreamsConfig.TASK_TIMEOUT_MS_CONFIG, 0L)));
    stateManager = new GlobalStateManagerImpl(new LogContext("mock"), time, topology, consumer, stateDirectory, stateRestoreListener, streamsConfig);
    processorContext.setStateManger(stateManager);
    stateManager.setGlobalProcessorContext(processorContext);
    final StreamsException expected = assertThrows(StreamsException.class, () -> stateManager.initialize());
    final Throwable cause = expected.getCause();
    assertThat(cause, instanceOf(TimeoutException.class));
    assertThat(cause.getMessage(), equalTo("KABOOM!"));
    assertEquals(numberOfCalls.get(), 1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamsException(org.apache.kafka.streams.errors.StreamsException) LogContext(org.apache.kafka.common.utils.LogContext) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TimeoutException(org.apache.kafka.common.errors.TimeoutException) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 95 with StreamsConfig

use of org.apache.kafka.streams.StreamsConfig in project kafka by apache.

the class GlobalStateManagerImplTest method shouldRetryWhenPartitionsForThrowsTimeoutExceptionUntilTaskTimeoutExpires.

@Test
public void shouldRetryWhenPartitionsForThrowsTimeoutExceptionUntilTaskTimeoutExpires() {
    final AtomicInteger numberOfCalls = new AtomicInteger(0);
    consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {

        @Override
        public List<PartitionInfo> partitionsFor(final String topic) {
            time.sleep(100L);
            numberOfCalls.incrementAndGet();
            throw new TimeoutException("KABOOM!");
        }
    };
    initializeConsumer(0, 0, t1, t2, t3, t4);
    streamsConfig = new StreamsConfig(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, "appId"), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234"), mkEntry(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath()), mkEntry(StreamsConfig.TASK_TIMEOUT_MS_CONFIG, 1000L)));
    stateManager = new GlobalStateManagerImpl(new LogContext("mock"), time, topology, consumer, stateDirectory, stateRestoreListener, streamsConfig);
    processorContext.setStateManger(stateManager);
    stateManager.setGlobalProcessorContext(processorContext);
    final TimeoutException expected = assertThrows(TimeoutException.class, () -> stateManager.initialize());
    assertThat(expected.getMessage(), equalTo("Global task did not make progress to restore state within 1000 ms. Adjust `task.timeout.ms` if needed."));
    assertEquals(numberOfCalls.get(), 11);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogContext(org.apache.kafka.common.utils.LogContext) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TimeoutException(org.apache.kafka.common.errors.TimeoutException) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Aggregations

StreamsConfig (org.apache.kafka.streams.StreamsConfig)219 Test (org.junit.Test)173 Properties (java.util.Properties)84 HashMap (java.util.HashMap)69 TopicPartition (org.apache.kafka.common.TopicPartition)66 TaskId (org.apache.kafka.streams.processor.TaskId)54 MockTime (org.apache.kafka.common.utils.MockTime)53 Set (java.util.Set)36 ArrayList (java.util.ArrayList)33 HashSet (java.util.HashSet)33 Metrics (org.apache.kafka.common.metrics.Metrics)33 File (java.io.File)32 AdminClient (org.apache.kafka.clients.admin.AdminClient)31 MockAdminClient (org.apache.kafka.clients.admin.MockAdminClient)31 LogContext (org.apache.kafka.common.utils.LogContext)31 Map (java.util.Map)30 TimeoutException (org.apache.kafka.common.errors.TimeoutException)30 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)30 Before (org.junit.Before)27 List (java.util.List)22