Search in sources :

Example 76 with StreamsConfig

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

the class StateDirectoryTest method shouldReturnEmptyArrayIfListFilesReturnsNull.

@Test
public void shouldReturnEmptyArrayIfListFilesReturnsNull() throws IOException {
    stateDir = new File(TestUtils.IO_TMP_DIR, "kafka-" + TestUtils.randomString(5));
    directory = new StateDirectory(new StreamsConfig(new Properties() {

        {
            put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId);
            put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
            put(StreamsConfig.STATE_DIR_CONFIG, stateDir.getPath());
        }
    }), time, true, false);
    appDir = new File(stateDir, applicationId);
    // make sure the File#listFiles returns null and StateDirectory#listAllTaskDirectories is able to handle null
    Utils.delete(appDir);
    assertTrue(appDir.createNewFile());
    assertTrue(appDir.exists());
    assertNull(appDir.listFiles());
    assertEquals(0, directory.listAllTaskDirectories().size());
}
Also used : Properties(java.util.Properties) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 77 with StreamsConfig

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

the class StateDirectoryTest method initializeStateDirectory.

private void initializeStateDirectory(final boolean createStateDirectory, final boolean hasNamedTopology) throws IOException {
    stateDir = new File(TestUtils.IO_TMP_DIR, "kafka-" + TestUtils.randomString(5));
    if (!createStateDirectory) {
        cleanup();
    }
    directory = new StateDirectory(new StreamsConfig(new Properties() {

        {
            put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId);
            put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
            put(StreamsConfig.STATE_DIR_CONFIG, stateDir.getPath());
        }
    }), time, createStateDirectory, hasNamedTopology);
    appDir = new File(stateDir, applicationId);
}
Also used : Properties(java.util.Properties) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig)

Example 78 with StreamsConfig

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

the class StateDirectoryTest method shouldLogTempDirMessage.

@Test
public void shouldLogTempDirMessage() {
    try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister(StateDirectory.class)) {
        new StateDirectory(new StreamsConfig(mkMap(mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, ""), mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, ""))), new MockTime(), true, false);
        assertThat(appender.getMessages(), hasItem("Using an OS temp directory in the state.dir property can cause failures with writing the" + " checkpoint file due to the fact that this directory can be cleared by the OS." + " Resolved state.dir: [" + System.getProperty("java.io.tmpdir") + "/kafka-streams]"));
    }
}
Also used : LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) MockTime(org.apache.kafka.common.utils.MockTime) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 79 with StreamsConfig

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

the class InternalTopicManagerTest method shouldThrowWhenDescribeTopicsThrowsUnexpectedExceptionDuringValidation.

@Test
public void shouldThrowWhenDescribeTopicsThrowsUnexpectedExceptionDuringValidation() {
    final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
    final InternalTopicManager topicManager = new InternalTopicManager(time, admin, new StreamsConfig(config));
    final KafkaFutureImpl<TopicDescription> topicDescriptionFailFuture = new KafkaFutureImpl<>();
    topicDescriptionFailFuture.completeExceptionally(new IllegalStateException("Nobody expects the Spanish inquisition"));
    EasyMock.expect(admin.describeTopics(Collections.singleton(topic1))).andStubAnswer(() -> new MockDescribeTopicsResult(mkMap(mkEntry(topic1, topicDescriptionFailFuture))));
    EasyMock.replay(admin);
    final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
    assertThrows(Throwable.class, () -> topicManager.validate(Collections.singletonMap(topic1, internalTopicConfig)));
}
Also used : TopicDescription(org.apache.kafka.clients.admin.TopicDescription) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) AdminClient(org.apache.kafka.clients.admin.AdminClient) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 80 with StreamsConfig

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

the class InternalTopicManagerTest method shouldThrowWhenCreateTopicsThrowsUnexpectedException.

@Test
public void shouldThrowWhenCreateTopicsThrowsUnexpectedException() {
    final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
    final StreamsConfig streamsConfig = new StreamsConfig(config);
    final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
    final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
    final KafkaFutureImpl<TopicMetadataAndConfig> createTopicFailFuture = new KafkaFutureImpl<>();
    createTopicFailFuture.completeExceptionally(new IllegalStateException("Nobody expects the Spanish inquisition"));
    final NewTopic newTopic = newTopic(topic1, internalTopicConfig, streamsConfig);
    EasyMock.expect(admin.createTopics(mkSet(newTopic))).andStubAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic1, createTopicFailFuture))));
    EasyMock.replay(admin);
    assertThrows(StreamsException.class, () -> topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig))));
}
Also used : TopicMetadataAndConfig(org.apache.kafka.clients.admin.CreateTopicsResult.TopicMetadataAndConfig) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) AdminClient(org.apache.kafka.clients.admin.AdminClient) MockAdminClient(org.apache.kafka.clients.admin.MockAdminClient) 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