use of java.nio.file.Path in project GCViewer by chewiebug.
the class TestHttpUrlConnectionHelper method assertInputStreamEqualToFile.
/**
* Compares the content of InputStream "in" with the specified file's content.
*
* @param msg Prefix for all assert messages
* @param file The file to check against
* @param in The input stream to check (closed on exit)
*/
private void assertInputStreamEqualToFile(String msg, String file, InputStream in) throws IOException {
// this test must not be done on byte level, because line endings are platform dependent!
Path path = Paths.get(PARENT_PATH, file);
try (LineNumberReader expectedContentReader = new LineNumberReader(new FileReader(path.toFile()));
LineNumberReader inputStreamReader = new LineNumberReader(new InputStreamReader(in))) {
while (expectedContentReader.ready() && inputStreamReader.ready()) {
String expectedLine = expectedContentReader.readLine();
String line = inputStreamReader.readLine();
assertThat(msg + " (line " + expectedContentReader.getLineNumber() + "): ", expectedLine, equalTo(line));
}
assertThat(msg + ": expectedContentReader must be at EOF", expectedContentReader.ready(), equalTo(false));
assertThat(msg + ": inputStreamReader must be at EOF", inputStreamReader.ready(), equalTo(false));
}
}
use of java.nio.file.Path in project crate by crate.
the class CopyIntegrationTest method testCopyToDirectory.
@Test
public void testCopyToDirectory() throws Exception {
this.setup.groupBySetup();
String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
SQLResponse response = execute("copy characters to DIRECTORY ?", new Object[] { uriTemplate });
assertThat(response.rowCount(), is(7L));
String[] list = folder.getRoot().list();
assertThat(list, is(notNullValue()));
assertThat(list.length, greaterThanOrEqualTo(1));
for (String file : list) {
assertThat(file, startsWith("characters_"));
}
List<String> lines = new ArrayList<>(7);
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json");
for (Path path : stream) {
lines.addAll(Files.readAllLines(path, StandardCharsets.UTF_8));
}
assertThat(lines.size(), is(7));
for (String line : lines) {
assertThat(line, startsWith("{"));
assertThat(line, endsWith("}"));
}
}
use of java.nio.file.Path in project crate by crate.
the class CopyIntegrationTest method testCopyFromSymlinkFolderWithPrefixedWildcard.
@Test
public void testCopyFromSymlinkFolderWithPrefixedWildcard() throws Exception {
Path link = setUpTableAndSymlink("t");
execute("copy t from ? with (shared=true)", new Object[] { link.toUri().toString() + "i*" });
assertThat(response.rowCount(), is(3L));
}
use of java.nio.file.Path in project crate by crate.
the class CopyIntegrationTest method testCopyFromFileInSymlinkFolder.
@Test
public void testCopyFromFileInSymlinkFolder() throws Exception {
Path link = setUpTableAndSymlink("t");
execute("copy t from ? with (shared=true)", new Object[] { link.toUri().toString() + "integers.json" });
assertThat(response.rowCount(), is(3L));
}
use of java.nio.file.Path in project crate by crate.
the class CrateMetaDataUpgradeServiceTest method startUpNodeWithRepoDir.
private Path startUpNodeWithRepoDir() throws IOException {
Settings.Builder settingsBuilder = Settings.builder();
Path repoDir = createTempDir();
try (InputStream stream = Files.newInputStream(getDataPath("/snapshot_repos/snaposhotsrepo_upgrade_required.zip"))) {
TestUtil.unzip(stream, repoDir);
}
assertTrue(Files.exists(repoDir));
settingsBuilder.put("path.repo", repoDir.toAbsolutePath());
Path dataDir = createTempDir().resolve("data");
Files.createDirectory(dataDir);
assertTrue(Files.exists(dataDir));
settingsBuilder.put("path.data", dataDir.toAbsolutePath());
internalCluster().startNode(settingsBuilder.build());
ensureYellow();
return repoDir;
}
Aggregations