Search in sources :

Example 36 with Path

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));
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) FileReader(java.io.FileReader) LineNumberReader(java.io.LineNumberReader)

Example 37 with Path

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("}"));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 38 with Path

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));
}
Also used : Path(java.nio.file.Path) Test(org.junit.Test)

Example 39 with Path

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));
}
Also used : Path(java.nio.file.Path) Test(org.junit.Test)

Example 40 with Path

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;
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146