Skip to content

Instantly share code, notes, and snippets.

@KMax
Created June 30, 2014 14:49
Show Gist options
  • Save KMax/64bbc5b2fd521f62091b to your computer and use it in GitHub Desktop.
Save KMax/64bbc5b2fd521f62091b to your computer and use it in GitHub Desktop.
CQELS: Stop and close everything
package org.deri.cqels;
import com.hp.hpl.jena.tdb.StoreConnection;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import org.deri.cqels.engine.ExecContext;
import org.junit.Test;
import static org.junit.Assert.*;
public class ResetTest {
private static final String CQELS_HOME = "cqels_home";
@Test
public void test() {
final File HOME = new File(CQELS_HOME);
if(!HOME.exists()) {
HOME.mkdir();
}
final ExecContext context = new ExecContext(CQELS_HOME, true);
context.env().close();
context.getDataset().close();
context.getARQExCtx().getDataset().close();
context.dictionary().close();
try {
Files.walkFileTree(new File(CQELS_HOME).toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException ex) {
fail(ex.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment