Search in sources :

Example 1 with LOCAL_COMMANDS_PROCESSED_SUFFIX

use of io.confluent.ksql.rest.server.LocalCommands.LOCAL_COMMANDS_PROCESSED_SUFFIX in project ksql by confluentinc.

the class LocalCommandsTest method shouldWriteAppIdToCommandFile.

@Test
public void shouldWriteAppIdToCommandFile() throws IOException {
    // Given
    final File dir = commandsDir.newFolder();
    LocalCommands localCommands = LocalCommands.open(ksqlEngine, dir);
    File processedFile = localCommands.getCurrentLocalCommandsFile();
    // When
    localCommands.write(metadata1);
    localCommands.write(metadata2);
    // Then
    // Need to create a new local commands in order not to skip the "current" file we just wrote.
    localCommands = LocalCommands.open(ksqlEngine, dir);
    localCommands.write(metadata3);
    localCommands.processLocalCommandFiles(serviceContext);
    verify(ksqlEngine).cleanupOrphanedInternalTopics(any(), eq(ImmutableSet.of(QUERY_APP_ID1, QUERY_APP_ID2)));
    List<Path> paths = Files.list(dir.toPath()).collect(Collectors.toList());
    String expectedProcessedFileName = processedFile.getAbsolutePath() + LOCAL_COMMANDS_PROCESSED_SUFFIX;
    assertThat(paths.size(), is(2));
    assertThat(paths.stream().anyMatch(path -> path.toFile().getAbsolutePath().equals(expectedProcessedFileName)), is(true));
}
Also used : Path(java.nio.file.Path) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) ServiceContext(io.confluent.ksql.services.ServiceContext) RunWith(org.junit.runner.RunWith) Mockito.doThrow(org.mockito.Mockito.doThrow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) KsqlTestFolder(io.confluent.ksql.test.util.KsqlTestFolder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Path(java.nio.file.Path) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Files(java.nio.file.Files) LOCAL_COMMANDS_PROCESSED_SUFFIX(io.confluent.ksql.rest.server.LocalCommands.LOCAL_COMMANDS_PROCESSED_SUFFIX) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) KsqlServerException(io.confluent.ksql.util.KsqlServerException) List(java.util.List) Rule(org.junit.Rule) Paths(java.nio.file.Paths) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) TemporaryFolder(org.junit.rules.TemporaryFolder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 LOCAL_COMMANDS_PROCESSED_SUFFIX (io.confluent.ksql.rest.server.LocalCommands.LOCAL_COMMANDS_PROCESSED_SUFFIX)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 KsqlTestFolder (io.confluent.ksql.test.util.KsqlTestFolder)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 TransientQueryMetadata (io.confluent.ksql.util.TransientQueryMetadata)1 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 PosixFilePermissions (java.nio.file.attribute.PosixFilePermissions)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.is (org.hamcrest.Matchers.is)1 Assert.assertThrows (org.junit.Assert.assertThrows)1 Before (org.junit.Before)1