Skip to content

Commit

Permalink
chore: do not throw an exception in KsqlTesterTest when copying non-e…
Browse files Browse the repository at this point in the history
…xisting files (#8557)
  • Loading branch information
spena authored Jan 7, 2022
1 parent ea3e6ab commit f82ec0c
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import io.confluent.ksql.util.QueryMetadata;
import java.io.File;
import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
Expand All @@ -93,9 +94,12 @@
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RunWith(Parameterized.class)
public class KsqlTesterTest {
private static final Logger LOG = LoggerFactory.getLogger(KsqlTesterTest.class);

private static final String TEST_DIR = "/sql-tests";

Expand Down Expand Up @@ -294,11 +298,23 @@ private void closeDriver(
final File stateDir = tmpFolder.getRoot().toPath().resolve(appId).toFile();
final File tmp = tmpFolder.getRoot().toPath().resolve("tmp_" + appId).toFile();

try {
if (!deleteState && stateDir.exists()) {
if (!deleteState && stateDir.exists()) {
try {
FileUtils.copyDirectory(stateDir, tmp);
} catch (final IOException e) {
if (!(e instanceof NoSuchFileException)) {
throw new KsqlException(e);
} else {
// Log a warning instead of throwing an exception when the state directory does not
// exist. The file could've been deleted manually by external factors.
LOG.warn("The state or temp directory '{}' do not exist. "
+ "The test will continue closing the driver.",
((NoSuchFileException) e).getFile());
}
}
}

try {
driver.close();

if (tmp.exists()) {
Expand Down

0 comments on commit f82ec0c

Please sign in to comment.