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());
}
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);
}
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]"));
}
}
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)));
}
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))));
}
Aggregations