Esempio n. 1
0
  // @Test
  // Check the file API's
  public void testFiles() throws Exception {
    Path subDir1 = new Path("dir.1");
    Path file1 = new Path("dir.1/foo.1");
    Path file2 = new Path("dir.1/foo.2");

    kosmosFileSystem.mkdirs(baseDir);
    assertTrue(kosmosFileSystem.isDirectory(baseDir));
    kosmosFileSystem.setWorkingDirectory(baseDir);

    kosmosFileSystem.mkdirs(subDir1);

    FSDataOutputStream s1 =
        kosmosFileSystem.create(file1, true, 4096, (short) 1, (long) 4096, null);
    FSDataOutputStream s2 =
        kosmosFileSystem.create(file2, true, 4096, (short) 1, (long) 4096, null);

    s1.close();
    s2.close();

    FileStatus[] p = kosmosFileSystem.listStatus(subDir1);
    assertEquals(p.length, 2);

    kosmosFileSystem.delete(file1, true);
    p = kosmosFileSystem.listStatus(subDir1);
    assertEquals(p.length, 1);

    kosmosFileSystem.delete(file2, true);
    p = kosmosFileSystem.listStatus(subDir1);
    assertEquals(p.length, 0);

    kosmosFileSystem.delete(baseDir, true);
    assertFalse(kosmosFileSystem.exists(baseDir));
  }
Esempio n. 2
0
  // @Test
  // Check all the directory API's in KFS
  public void testDirs() throws Exception {
    Path subDir1 = new Path("dir.1");

    // make the dir
    kosmosFileSystem.mkdirs(baseDir);
    assertTrue(kosmosFileSystem.isDirectory(baseDir));
    kosmosFileSystem.setWorkingDirectory(baseDir);

    kosmosFileSystem.mkdirs(subDir1);
    assertTrue(kosmosFileSystem.isDirectory(subDir1));

    assertFalse(kosmosFileSystem.exists(new Path("test1")));
    assertFalse(kosmosFileSystem.isDirectory(new Path("test/dir.2")));

    FileStatus[] p = kosmosFileSystem.listStatus(baseDir);
    assertEquals(p.length, 1);

    kosmosFileSystem.delete(baseDir, true);
    assertFalse(kosmosFileSystem.exists(baseDir));
  }