コード例 #1
1
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Creates a directory which can not be deleted completely.
   *
   * <p>Directory structure. The naming is important in that {@link MyFile} is used to return them
   * in alphabetical order when listed.
   *
   * <p>del(+w) | .---------------------------------------, | | | | file1(!w) xSubDir(-rwx)
   * ySubDir(+w) zlink | | | | file2(-rwx) file3 | xSubSubDir(-rwx) | file22(-rwx)
   *
   * @throws IOException
   */
  private void setupDirsAndNonWritablePermissions() throws IOException {
    Assert.assertFalse("The directory del should not have existed!", del.exists());
    del.mkdirs();
    new MyFile(del, file1Name).createNewFile();

    // "file1" is non-deletable by default, see MyFile.delete().

    xSubDir.mkdirs();
    file2.createNewFile();

    xSubSubDir.mkdirs();
    file22.createNewFile();

    revokePermissions(file22);
    revokePermissions(xSubSubDir);

    revokePermissions(file2);
    revokePermissions(xSubDir);

    ySubDir.mkdirs();
    file3.createNewFile();

    Assert.assertFalse("The directory tmp should not have existed!", tmp.exists());
    tmp.mkdirs();
    File tmpFile = new File(tmp, FILE);
    tmpFile.createNewFile();
    FileUtil.symLink(tmpFile.toString(), zlink.toString());
  }
コード例 #2
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Creates multiple directories for testing.
   *
   * <p>Contents of them are dir:tmp: file: x dir:del: file: x dir: dir1 : file:x dir: dir2 : file:x
   * link: y to tmp/x link: tmpDir to tmp dir:partitioned: file: part-r-00000, contents: "foo" file:
   * part-r-00001, contents: "bar"
   */
  private void setupDirs() throws IOException {
    Assert.assertFalse(del.exists());
    Assert.assertFalse(tmp.exists());
    Assert.assertFalse(partitioned.exists());
    del.mkdirs();
    tmp.mkdirs();
    partitioned.mkdirs();
    new File(del, FILE).createNewFile();
    File tmpFile = new File(tmp, FILE);
    tmpFile.createNewFile();

    // create directories
    dir1.mkdirs();
    dir2.mkdirs();
    new File(dir1, FILE).createNewFile();
    new File(dir2, FILE).createNewFile();

    // create a symlink to file
    File link = new File(del, LINK);
    FileUtil.symLink(tmpFile.toString(), link.toString());

    // create a symlink to dir
    File linkDir = new File(del, "tmpDir");
    FileUtil.symLink(tmp.toString(), linkDir.toString());
    Assert.assertEquals(5, del.listFiles().length);

    // create files in partitioned directories
    createFile(partitioned, "part-r-00000", "foo");
    createFile(partitioned, "part-r-00001", "bar");

    // create a cycle using symlinks. Cycles should be handled
    FileUtil.symLink(del.toString(), dir1.toString() + "/cycle");
  }
コード例 #3
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Tests if fullyDelete deletes (a) dangling symlink to file properly (b) dangling symlink to
   * directory properly
   *
   * @throws IOException
   */
  @Test(timeout = 30000)
  public void testFullyDeleteDanglingSymlinks() throws IOException {
    setupDirs();
    // delete the directory tmp to make tmpDir a dangling link to dir tmp and
    // to make y as a dangling link to file tmp/x
    boolean ret = FileUtil.fullyDelete(tmp);
    Assert.assertTrue(ret);
    Assert.assertFalse(tmp.exists());

    // dangling symlink to file
    File link = new File(del, LINK);
    Assert.assertEquals(5, del.list().length);
    // Even though 'y' is dangling symlink to file tmp/x, fullyDelete(y)
    // should delete 'y' properly.
    ret = FileUtil.fullyDelete(link);
    Assert.assertTrue(ret);
    Assert.assertEquals(4, del.list().length);

    // dangling symlink to directory
    File linkDir = new File(del, "tmpDir");
    // Even though tmpDir is dangling symlink to tmp, fullyDelete(tmpDir) should
    // delete tmpDir properly.
    ret = FileUtil.fullyDelete(linkDir);
    Assert.assertTrue(ret);
    Assert.assertEquals(3, del.list().length);
  }
コード例 #4
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  private void doUntarAndVerify(File tarFile, File untarDir) throws IOException {
    if (untarDir.exists() && !FileUtil.fullyDelete(untarDir)) {
      throw new IOException("Could not delete directory '" + untarDir + "'");
    }
    FileUtil.unTar(tarFile, untarDir);

    String parentDir = untarDir.getCanonicalPath() + Path.SEPARATOR + "name";
    File testFile = new File(parentDir + Path.SEPARATOR + "version");
    Assert.assertTrue(testFile.exists());
    Assert.assertTrue(testFile.length() == 0);
    String imageDir = parentDir + Path.SEPARATOR + "image";
    testFile = new File(imageDir + Path.SEPARATOR + "fsimage");
    Assert.assertTrue(testFile.exists());
    Assert.assertTrue(testFile.length() == 157);
    String currentDir = parentDir + Path.SEPARATOR + "current";
    testFile = new File(currentDir + Path.SEPARATOR + "fsimage");
    Assert.assertTrue(testFile.exists());
    Assert.assertTrue(testFile.length() == 4331);
    testFile = new File(currentDir + Path.SEPARATOR + "edits");
    Assert.assertTrue(testFile.exists());
    Assert.assertTrue(testFile.length() == 1033);
    testFile = new File(currentDir + Path.SEPARATOR + "fstime");
    Assert.assertTrue(testFile.exists());
    Assert.assertTrue(testFile.length() == 8);
  }
コード例 #5
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testListAPI() throws IOException {
    setupDirs();
    // Test existing files case
    String[] files = FileUtil.list(partitioned);
    Assert.assertEquals("Unexpected number of pre-existing files", 2, files.length);

    // Test existing directory with no files case
    File newDir = new File(tmp.getPath(), "test");
    newDir.mkdir();
    Assert.assertTrue("Failed to create test dir", newDir.exists());
    files = FileUtil.list(newDir);
    Assert.assertEquals("New directory unexpectedly contains files", 0, files.length);
    newDir.delete();
    Assert.assertFalse("Failed to delete test dir", newDir.exists());

    // Test non-existing directory case, this throws
    // IOException
    try {
      files = FileUtil.list(newDir);
      Assert.fail("IOException expected on list() for non-existent dir " + newDir.toString());
    } catch (IOException ioe) {
      // Expected an IOException
    }
  }
コード例 #6
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  private void cleanupImpl() throws IOException {
    FileUtil.fullyDelete(del, true);
    Assert.assertTrue(!del.exists());

    FileUtil.fullyDelete(tmp, true);
    Assert.assertTrue(!tmp.exists());

    FileUtil.fullyDelete(partitioned, true);
    Assert.assertTrue(!partitioned.exists());
  }
コード例 #7
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  /*
   * Test method copy(FileSystem srcFS, Path src, File dst, boolean deleteSource, Configuration conf)
   */
  public void testCopy5() throws IOException {
    setupDirs();

    URI uri = tmp.toURI();
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.newInstance(uri, conf);
    final String content = "some-content";
    File srcFile = createFile(tmp, "src", content);
    Path srcPath = new Path(srcFile.toURI());

    // copy regular file:
    final File dest = new File(del, "dest");
    boolean result = FileUtil.copy(fs, srcPath, dest, false, conf);
    assertTrue(result);
    assertTrue(dest.exists());
    assertEquals(
        content.getBytes().length + System.getProperty("line.separator").getBytes().length,
        dest.length());
    assertTrue(srcFile.exists()); // should not be deleted

    // copy regular file, delete src:
    dest.delete();
    assertTrue(!dest.exists());
    result = FileUtil.copy(fs, srcPath, dest, true, conf);
    assertTrue(result);
    assertTrue(dest.exists());
    assertEquals(
        content.getBytes().length + System.getProperty("line.separator").getBytes().length,
        dest.length());
    assertTrue(!srcFile.exists()); // should be deleted

    // copy a dir:
    dest.delete();
    assertTrue(!dest.exists());
    srcPath = new Path(partitioned.toURI());
    result = FileUtil.copy(fs, srcPath, dest, true, conf);
    assertTrue(result);
    assertTrue(dest.exists() && dest.isDirectory());
    File[] files = dest.listFiles();
    assertTrue(files != null);
    assertEquals(2, files.length);
    for (File f : files) {
      assertEquals(3 + System.getProperty("line.separator").getBytes().length, f.length());
    }
    assertTrue(!partitioned.exists()); // should be deleted
  }
コード例 #8
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Test that getDU is able to handle cycles caused due to symbolic links and that directory sizes
   * are not added to the final calculated size
   *
   * @throws IOException
   */
  @Test(timeout = 30000)
  public void testGetDU() throws Exception {
    setupDirs();

    long du = FileUtil.getDU(TEST_DIR);
    // Only two files (in partitioned).  Each has 3 characters + system-specific
    // line separator.
    final long expected = 2 * (3 + System.getProperty("line.separator").length());
    Assert.assertEquals(expected, du);

    // target file does not exist:
    final File doesNotExist = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
    long duDoesNotExist = FileUtil.getDU(doesNotExist);
    assertEquals(0, duDoesNotExist);

    // target file is not a directory:
    File notADirectory = new File(partitioned, "part-r-00000");
    long duNotADirectoryActual = FileUtil.getDU(notADirectory);
    long duNotADirectoryExpected = 3 + System.getProperty("line.separator").length();
    assertEquals(duNotADirectoryExpected, duNotADirectoryActual);

    try {
      // one of target files is not accessible, but the containing directory
      // is accessible:
      try {
        FileUtil.chmod(notADirectory.getAbsolutePath(), "0000");
      } catch (InterruptedException ie) {
        // should never happen since that method never throws InterruptedException.
        assertNull(ie);
      }
      assertFalse(FileUtil.canRead(notADirectory));
      final long du3 = FileUtil.getDU(partitioned);
      assertEquals(expected, du3);

      // some target files and containing directory are not accessible:
      try {
        FileUtil.chmod(partitioned.getAbsolutePath(), "0000");
      } catch (InterruptedException ie) {
        // should never happen since that method never throws InterruptedException.
        assertNull(ie);
      }
      assertFalse(FileUtil.canRead(partitioned));
      final long du4 = FileUtil.getDU(partitioned);
      assertEquals(0, du4);
    } finally {
      // Restore the permissions so that we can delete the folder
      // in @After method:
      FileUtil.chmod(partitioned.getAbsolutePath(), "0777", true /*recursive*/);
    }
  }
コード例 #9
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
 @Test(timeout = 30000)
 public void testCreateLocalTempFile() throws IOException {
   setupDirs();
   final File baseFile = new File(tmp, "base");
   File tmp1 = FileUtil.createLocalTempFile(baseFile, "foo", false);
   File tmp2 = FileUtil.createLocalTempFile(baseFile, "foo", true);
   assertFalse(tmp1.getAbsolutePath().equals(baseFile.getAbsolutePath()));
   assertFalse(tmp2.getAbsolutePath().equals(baseFile.getAbsolutePath()));
   assertTrue(tmp1.exists() && tmp2.exists());
   assertTrue(tmp1.canWrite() && tmp2.canWrite());
   assertTrue(tmp1.canRead() && tmp2.canRead());
   tmp1.delete();
   tmp2.delete();
   assertTrue(!tmp1.exists() && !tmp2.exists());
 }
コード例 #10
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testSymlink() throws Exception {
    Assert.assertFalse(del.exists());
    del.mkdirs();

    byte[] data = "testSymLink".getBytes();

    File file = new File(del, FILE);
    File link = new File(del, "_link");

    // write some data to the file
    FileOutputStream os = new FileOutputStream(file);
    os.write(data);
    os.close();

    // create the symlink
    FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

    // ensure that symlink length is correctly reported by Java
    Assert.assertEquals(data.length, file.length());
    Assert.assertEquals(data.length, link.length());

    // ensure that we can read from link.
    FileInputStream in = new FileInputStream(link);
    long len = 0;
    while (in.read() > 0) {
      len++;
    }
    in.close();
    Assert.assertEquals(data.length, len);
  }
コード例 #11
0
  @Test
  public void testExampleJson() throws Exception {
    String json = FileUtil.readFileFromClasspath("json-examples/agreement-updated-example.json");
    JsonMessage jsonMessage = new JsonMessage(json);
    ServiceResult serviceResult = new ServiceResult();
    serviceResult.setRawData(jsonMessage);

    ServiceResult result = (ServiceResult) transformer.doTransform(serviceResult, "UTF-8");
    AgreementUpdated agreementUpdated =
        (AgreementUpdated) result.getIntegrationMessage().getDomainObject();

    Agreement agreement = agreementUpdated.getAgreement();

    collector.checkThat(agreement.getCurrencyCode().getCurrencyCode(), is("SEK"));
    collector.checkThat(
        agreement.getDocumentLink(), is("\\\\someserver\\somefolder\\somefile.pdf"));
    collector.checkThat(agreement.getClientId(), is("Cl42824050"));
    collector.checkThat(agreement.getDescription(), is("Agreement Name Example"));
    collector.checkThat(agreement.getSourceSystemAgreementId(), is("1-1234567896"));
    collector.checkThat(
        agreement.getValidFrom().getTimestamp(), is("2012-06-25T15:30:01.999+02:00"));
    collector.checkThat(agreement.getValidTo(), nullValue());
    collector.checkThat(
        agreement.getInvoicingRuleId().getGuid(), is("3f2504e0-4f89-11d3-9a0c-0305e82c3401"));
    collector.checkThat(agreement.getMarketId().getOrganizationId(), is(51));
    collector.checkThat(agreement.getProductType().getValue(), is(3));
  }
コード例 #12
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
 @Test(timeout = 30000)
 public void testFailFullyDeleteContentsGrantPermissions() throws IOException {
   setupDirsAndNonWritablePermissions();
   boolean ret = FileUtil.fullyDeleteContents(new MyFile(del), true);
   // this time the directories with revoked permissions *should* be deleted:
   validateAndSetWritablePermissions(false, ret);
 }
コード例 #13
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /** Test that rename on a symlink works as expected. */
  @Test(timeout = 30000)
  public void testSymlinkRenameTo() throws Exception {
    Assert.assertFalse(del.exists());
    del.mkdirs();

    File file = new File(del, FILE);
    file.createNewFile();
    File link = new File(del, "_link");

    // create the symlink
    FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

    Assert.assertTrue(file.exists());
    Assert.assertTrue(link.exists());

    File link2 = new File(del, "_link2");

    // Rename the symlink
    Assert.assertTrue(link.renameTo(link2));

    // Make sure the file still exists
    // (NOTE: this would fail on Java6 on Windows if we didn't
    // copy the file in FileUtil#symlink)
    Assert.assertTrue(file.exists());

    Assert.assertTrue(link2.exists());
    Assert.assertFalse(link.exists());
  }
コード例 #14
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
 @Test(timeout = 30000)
 public void testFullyDelete() throws IOException {
   setupDirs();
   boolean ret = FileUtil.fullyDelete(del);
   Assert.assertTrue(ret);
   Assert.assertFalse(del.exists());
   validateTmpDir();
 }
コード例 #15
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
 @Test(timeout = 30000)
 public void testFullyDeleteContents() throws IOException {
   setupDirs();
   boolean ret = FileUtil.fullyDeleteContents(del);
   Assert.assertTrue(ret);
   Assert.assertTrue(del.exists());
   Assert.assertEquals(0, del.listFiles().length);
   validateTmpDir();
 }
コード例 #16
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testStat2Paths1() {
    assertNull(FileUtil.stat2Paths(null));

    FileStatus[] fileStatuses = new FileStatus[0];
    Path[] paths = FileUtil.stat2Paths(fileStatuses);
    assertEquals(0, paths.length);

    Path path1 = new Path("file://foo");
    Path path2 = new Path("file://moo");
    fileStatuses =
        new FileStatus[] {
          new FileStatus(3, false, 0, 0, 0, path1), new FileStatus(3, false, 0, 0, 0, path2)
        };
    paths = FileUtil.stat2Paths(fileStatuses);
    assertEquals(2, paths.length);
    assertEquals(paths[0], path1);
    assertEquals(paths[1], path2);
  }
コード例 #17
0
  private void runImportCnaData() throws DaoException, IOException {

    DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance();
    DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();

    // the largest current true Entrez gene ID counts 8 digits
    daoGene.addGene(new CanonicalGene(999999207, "TESTAKT1"));
    daoGene.addGene(new CanonicalGene(999999208, "TESTAKT2"));
    daoGene.addGene(new CanonicalGene(999910000, "TESTAKT3"));
    daoGene.addGene(new CanonicalGene(999999369, "TESTARAF"));
    daoGene.addGene(new CanonicalGene(999999472, "TESTATM"));
    daoGene.addGene(new CanonicalGene(999999673, "TESTBRAF"));
    daoGene.addGene(new CanonicalGene(999999672, "TESTBRCA1"));
    daoGene.addGene(new CanonicalGene(999999675, "TESTBRCA2"));

    ProgressMonitor.setConsoleMode(false);
    // TBD: change this to use getResourceAsStream()
    File file = new File("src/test/resources/cna_test.txt");
    ImportTabDelimData parser = new ImportTabDelimData(file, "Barry", geneticProfileId, null);
    int numLines = FileUtil.getNumLines(file);
    parser.importData(numLines);

    String value = dao.getGeneticAlteration(geneticProfileId, sample1, 999999207);
    assertEquals("0", value);
    value = dao.getGeneticAlteration(geneticProfileId, sample4, 999999207);
    assertEquals("-1", value);
    value = dao.getGeneticAlteration(geneticProfileId, sample2, 999999207);
    assertEquals("0", value);
    value = dao.getGeneticAlteration(geneticProfileId, sample2, 999910000);
    assertEquals("2", value);
    value = dao.getGeneticAlteration(geneticProfileId, sample3, 999910000);
    assertEquals("2", value);

    int cnaStatus =
        Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample3, 999910000));
    assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus);
    cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample2, 999910000));
    assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus);
    cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample4, 999999207));
    assertEquals(CopyNumberStatus.HEMIZYGOUS_DELETION, cnaStatus);

    Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SB");
    Sample sample =
        DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SB-01");
    assertTrue(
        DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId));

    patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SJ");
    sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SJ-01");
    assertTrue(
        DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId));

    ArrayList caseIds = DaoSampleProfile.getAllSampleIdsInProfile(geneticProfileId);
    assertEquals(14, caseIds.size());
  }
コード例 #18
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
 @Test(timeout = 30000)
 public void testFailFullyDeleteContents() throws IOException {
   if (Shell.WINDOWS) {
     // windows Dir.setWritable(false) does not work for directories
     return;
   }
   LOG.info("Running test to verify failure of fullyDeleteContents()");
   setupDirsAndNonWritablePermissions();
   boolean ret = FileUtil.fullyDeleteContents(new MyFile(del));
   validateAndSetWritablePermissions(true, ret);
 }
コード例 #19
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testReplaceFile() throws IOException {
    setupDirs();
    final File srcFile = new File(tmp, "src");

    // src exists, and target does not exist:
    srcFile.createNewFile();
    assertTrue(srcFile.exists());
    final File targetFile = new File(tmp, "target");
    assertTrue(!targetFile.exists());
    FileUtil.replaceFile(srcFile, targetFile);
    assertTrue(!srcFile.exists());
    assertTrue(targetFile.exists());

    // src exists and target is a regular file:
    srcFile.createNewFile();
    assertTrue(srcFile.exists());
    FileUtil.replaceFile(srcFile, targetFile);
    assertTrue(!srcFile.exists());
    assertTrue(targetFile.exists());

    // src exists, and target is a non-empty directory:
    srcFile.createNewFile();
    assertTrue(srcFile.exists());
    targetFile.delete();
    targetFile.mkdirs();
    File obstacle = new File(targetFile, "obstacle");
    obstacle.createNewFile();
    assertTrue(obstacle.exists());
    assertTrue(targetFile.exists() && targetFile.isDirectory());
    try {
      FileUtil.replaceFile(srcFile, targetFile);
      assertTrue(false);
    } catch (IOException ioe) {
      // okay
    }
    // check up the post-condition: nothing is deleted:
    assertTrue(srcFile.exists());
    assertTrue(targetFile.exists() && targetFile.isDirectory());
    assertTrue(obstacle.exists());
  }
コード例 #20
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testUnZip() throws IOException {
    // make sa simple zip
    setupDirs();

    // make a simple tar:
    final File simpleZip = new File(del, FILE);
    OutputStream os = new FileOutputStream(simpleZip);
    ZipOutputStream tos = new ZipOutputStream(os);
    try {
      ZipEntry ze = new ZipEntry("foo");
      byte[] data = "some-content".getBytes("UTF-8");
      ze.setSize(data.length);
      tos.putNextEntry(ze);
      tos.write(data);
      tos.closeEntry();
      tos.flush();
      tos.finish();
    } finally {
      tos.close();
    }

    // successfully untar it into an existing dir:
    FileUtil.unZip(simpleZip, tmp);
    // check result:
    assertTrue(new File(tmp, "foo").exists());
    assertEquals(12, new File(tmp, "foo").length());

    final File regularFile = new File(tmp, "QuickBrownFoxJumpsOverTheLazyDog");
    regularFile.createNewFile();
    assertTrue(regularFile.exists());
    try {
      FileUtil.unZip(simpleZip, regularFile);
      assertTrue("An IOException expected.", false);
    } catch (IOException ioe) {
      // okay
    }
  }
コード例 #21
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Tests if fullyDelete deletes (a) symlink to file only and not the file pointed to by symlink.
   * (b) symlink to dir only and not the dir pointed to by symlink.
   *
   * @throws IOException
   */
  @Test(timeout = 30000)
  public void testFullyDeleteSymlinks() throws IOException {
    setupDirs();

    File link = new File(del, LINK);
    Assert.assertEquals(5, del.list().length);
    // Since tmpDir is symlink to tmp, fullyDelete(tmpDir) should not
    // delete contents of tmp. See setupDirs for details.
    boolean ret = FileUtil.fullyDelete(link);
    Assert.assertTrue(ret);
    Assert.assertFalse(link.exists());
    Assert.assertEquals(4, del.list().length);
    validateTmpDir();

    File linkDir = new File(del, "tmpDir");
    // Since tmpDir is symlink to tmp, fullyDelete(tmpDir) should not
    // delete contents of tmp. See setupDirs for details.
    ret = FileUtil.fullyDelete(linkDir);
    Assert.assertTrue(ret);
    Assert.assertFalse(linkDir.exists());
    Assert.assertEquals(3, del.list().length);
    validateTmpDir();
  }
コード例 #22
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  @Test(timeout = 30000)
  public void testStat2Paths2() {
    Path defaultPath = new Path("file://default");
    Path[] paths = FileUtil.stat2Paths(null, defaultPath);
    assertEquals(1, paths.length);
    assertEquals(defaultPath, paths[0]);

    paths = FileUtil.stat2Paths(null, null);
    assertTrue(paths != null);
    assertEquals(1, paths.length);
    assertEquals(null, paths[0]);

    Path path1 = new Path("file://foo");
    Path path2 = new Path("file://moo");
    FileStatus[] fileStatuses =
        new FileStatus[] {
          new FileStatus(3, false, 0, 0, 0, path1), new FileStatus(3, false, 0, 0, 0, path2)
        };
    paths = FileUtil.stat2Paths(fileStatuses, defaultPath);
    assertEquals(2, paths.length);
    assertEquals(paths[0], path1);
    assertEquals(paths[1], path2);
  }
コード例 #23
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /**
   * Calls FileUtil.copyMerge using the specified source and destination paths. Both source and
   * destination are assumed to be on the local file system. The call will not delete source on
   * completion and will not add an additional string between files.
   *
   * @param src String non-null source path.
   * @param dst String non-null destination path.
   * @return boolean true if the call to FileUtil.copyMerge was successful.
   * @throws IOException if an I/O error occurs.
   */
  private boolean copyMerge(String src, String dst) throws IOException {
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.getLocal(conf);
    final boolean result;

    try {
      Path srcPath = new Path(TEST_ROOT_DIR, src);
      Path dstPath = new Path(TEST_ROOT_DIR, dst);
      boolean deleteSource = false;
      String addString = null;
      result = FileUtil.copyMerge(fs, srcPath, fs, dstPath, deleteSource, conf, addString);
    } finally {
      fs.close();
    }

    return result;
  }
コード例 #24
0
  private void runImportRnaData1() throws DaoException, IOException {

    DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
    DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance();

    daoGene.addGene(new CanonicalGene(999999780, "A"));
    daoGene.addGene(new CanonicalGene(999995982, "B"));
    daoGene.addGene(new CanonicalGene(999993310, "C"));
    daoGene.addGene(new CanonicalGene(999997849, "D"));
    daoGene.addGene(new CanonicalGene(999992978, "E"));
    daoGene.addGene(new CanonicalGene(999997067, "F"));
    daoGene.addGene(new CanonicalGene(999911099, "G"));
    daoGene.addGene(new CanonicalGene(999999675, "6352"));

    GeneticProfile geneticProfile = new GeneticProfile();

    geneticProfile.setCancerStudyId(studyId);
    geneticProfile.setStableId("gbm_mrna");
    geneticProfile.setGeneticAlterationType(GeneticAlterationType.MRNA_EXPRESSION);
    geneticProfile.setDatatype("CONTINUOUS");
    geneticProfile.setProfileName("MRNA Data");
    geneticProfile.setProfileDescription("mRNA Data");
    DaoGeneticProfile.addGeneticProfile(geneticProfile);

    int newGeneticProfileId =
        DaoGeneticProfile.getGeneticProfileByStableId("gbm_mrna").getGeneticProfileId();

    ProgressMonitor.setConsoleMode(true);
    // TBD: change this to use getResourceAsStream()
    File file = new File("src/test/resources/mrna_test.txt");
    ImportTabDelimData parser = new ImportTabDelimData(file, newGeneticProfileId, null);
    int numLines = FileUtil.getNumLines(file);
    parser.importData(numLines);
    ConsoleUtil.showMessages();

    int sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "DD639").getInternalId();
    String value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999992978);
    assertEquals("2.01", value);

    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "DD638").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997849);
    assertEquals("0.55", value);
  }
コード例 #25
0
  private void runImportCnaData2() throws DaoException, IOException {

    DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance();

    ProgressMonitor.setConsoleMode(false);
    // TBD: change this to use getResourceAsStream()
    File file = new File("src/test/resources/cna_test2.txt");
    ImportTabDelimData parser = new ImportTabDelimData(file, geneticProfileId, null);
    int numLines = FileUtil.getNumLines(file);
    parser.importData(numLines);

    String value = dao.getGeneticAlteration(geneticProfileId, sample1, 207);
    assertEquals(value, "0");
    value = dao.getGeneticAlteration(geneticProfileId, sample4, 207);
    assertEquals(value, "-1");
    value = dao.getGeneticAlteration(geneticProfileId, sample2, 207);
    assertEquals(value, "0");
    value = dao.getGeneticAlteration(geneticProfileId, sample2, 10000);
    assertEquals(value, "2");
    value = dao.getGeneticAlteration(geneticProfileId, sample3, 10000);
    assertEquals(value, "2");

    int cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample3, 10000));
    assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus);
    cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample2, 10000));
    assertEquals(CopyNumberStatus.COPY_NUMBER_AMPLIFICATION, cnaStatus);
    cnaStatus = Integer.parseInt(dao.getGeneticAlteration(geneticProfileId, sample4, 207));
    assertEquals(CopyNumberStatus.HEMIZYGOUS_DELETION, cnaStatus);

    Patient patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SB");
    Sample sample =
        DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SB-01");
    assertTrue(
        DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId));

    patient = DaoPatient.getPatientByCancerStudyAndPatientId(studyId, "TCGA-A1-A0SJ");
    sample = DaoSample.getSampleByPatientAndSampleId(patient.getInternalId(), "TCGA-A1-A0SJ-01");
    assertTrue(
        DaoSampleProfile.sampleExistsInGeneticProfile(sample.getInternalId(), geneticProfileId));
    ArrayList sampleIds = DaoSampleProfile.getAllSampleIdsInProfile(geneticProfileId);
    assertEquals(14, sampleIds.size());
  }
コード例 #26
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /** Test that deletion of a symlink works as expected. */
  @Test(timeout = 30000)
  public void testSymlinkDelete() throws Exception {
    Assert.assertFalse(del.exists());
    del.mkdirs();

    File file = new File(del, FILE);
    file.createNewFile();
    File link = new File(del, "_link");

    // create the symlink
    FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

    Assert.assertTrue(file.exists());
    Assert.assertTrue(link.exists());

    // make sure that deleting a symlink works properly
    Assert.assertTrue(link.delete());
    Assert.assertFalse(link.exists());
    Assert.assertTrue(file.exists());
  }
コード例 #27
0
ファイル: TestFileUtil.java プロジェクト: JoeChien23/hadoop
  /** Test that length on a symlink works as expected. */
  @Test(timeout = 30000)
  public void testSymlinkLength() throws Exception {
    Assert.assertFalse(del.exists());
    del.mkdirs();

    byte[] data = "testSymLinkData".getBytes();

    File file = new File(del, FILE);
    File link = new File(del, "_link");

    // write some data to the file
    FileOutputStream os = new FileOutputStream(file);
    os.write(data);
    os.close();

    Assert.assertEquals(0, link.length());

    // create the symlink
    FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

    // ensure that File#length returns the target file and link size
    Assert.assertEquals(data.length, file.length());
    Assert.assertEquals(data.length, link.length());

    file.delete();
    Assert.assertFalse(file.exists());

    if (Shell.WINDOWS && !Shell.isJava7OrAbove()) {
      // On Java6 on Windows, we copied the file
      Assert.assertEquals(data.length, link.length());
    } else {
      // Otherwise, the target file size is zero
      Assert.assertEquals(0, link.length());
    }

    link.delete();
    Assert.assertFalse(link.exists());
  }
コード例 #28
0
  @Test
  public void testExampleJson() throws Exception {
    String json =
        FileUtil.readFileFromClasspath("json-examples/invoicing-rule-updated-example.json");
    JsonMessage jsonMessage = new JsonMessage(json);
    ServiceResult serviceResult = new ServiceResult();
    serviceResult.setRawData(jsonMessage);

    ServiceResult result = (ServiceResult) transformer.doTransform(serviceResult, "UTF-8");
    InvoicingRuleUpdated invoicingRuleCreated =
        (InvoicingRuleUpdated) result.getIntegrationMessage().getDomainObject();

    MetaData metaData = invoicingRuleCreated.getMetaData();

    InvoicingRule invoicingRule = invoicingRuleCreated.getInvoicingRule();

    List<InvoiceRecipient> invoiceRecipients = invoicingRule.getInvoiceRecipients();
    collector.checkThat(invoiceRecipients.size(), is(3));

    InvoiceRecipient invoiceRecipient = invoiceRecipients.get(0);

    Address registeredAddressInvoiceRecipient = invoiceRecipient.getRegisteredAddress();

    List<SplittingRule> splittingRules = invoiceRecipients.get(2).getSplittingRules();
    collector.checkThat(splittingRules.size(), is(3));
    SplittingRule splittingRule = splittingRules.get(0);

    List<PurchaseOrder> purchaseOrders = invoicingRule.getPurchaseOrders();
    collector.checkThat(purchaseOrders.size(), is(3));
    PurchaseOrder purchaseOrder = purchaseOrders.get(0);

    List<InvoicingRuleMessageRule> invoiceMessageRules = invoicingRule.getInvoiceMessageRules();
    collector.checkThat(invoiceMessageRules.size(), is(1));
    InvoicingRuleMessageRule invoiceMessageRule = invoiceMessageRules.get(0);

    collector.checkThat(metaData.getMessageType(), is("UpdateInvoicingRule"));
    collector.checkThat(
        metaData.getMessageId().getGuid(), is("28b62635-15a0-b15e-c5f4-5442b66d1059"));
    collector.checkThat(
        metaData.getCreationTime().getTimestamp(), is("2012-07-05T13:21:00.000+02:00"));
    collector.checkThat(metaData.getVersion(), is("1.0"));
    collector.checkThat(metaData.getSourceSystem(), is("CRM"));

    collector.checkThat(invoicingRule.getClientId(), is("TELIA"));
    collector.checkThat(invoicingRule.getMarketId().getOrganizationId(), is(51));
    collector.checkThat(
        invoicingRule.getInvoicingRuleId().getGuid(), is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(invoicingRule.getInvoicingRuleName(), is("Volvo - do not edit"));
    collector.checkThat(invoicingRule.getDescription(), is("Used in unit tests - do not edit"));
    collector.checkThat(invoicingRule.getIssuerReference(), is("Maria Lind"));
    collector.checkThat(invoicingRule.getClientReference(), is("Lasse Volvosson"));
    collector.checkThat(invoicingRule.getCurrencyCode().getCurrencyCode(), is("EUR"));
    collector.checkThat(invoicingRule.getDistributionMode().getValue(), is(1));
    collector.checkThat(invoicingRule.getTermsOfPayment().getDays(), is(30));
    collector.checkThat(invoicingRule.getPostingProfile().getValue(), is(1));
    collector.checkThat(invoicingRule.isDisplayTradeDoublerCommission(), is(true));
    collector.checkThat(invoicingRule.getRevenueType().getValue(), is(1));
    collector.checkThat(invoicingRule.getPaymentMethod().getValue(), is(2));
    collector.checkThat(invoicingRule.isDeviatingExchangeRate(), is(false));

    collector.checkThat(
        invoiceRecipient.getInvoiceRecipientId().getGuid(),
        is("703b123f-6329-4d79-bfaa-60762a5f6cf4"));
    collector.checkThat(
        invoiceRecipient.getInvoicingRuleId().getGuid(),
        is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(invoiceRecipient.getAttentionRow1(), is("Attention of default recipient!"));
    collector.checkThat(invoiceRecipient.getAttentionRow2(), nullValue());
    collector.checkThat(invoiceRecipient.getEmailAddress(), nullValue());
    collector.checkThat(invoiceRecipient.isDefaultRecipient(), is(true));

    collector.checkThat(registeredAddressInvoiceRecipient.getLine1(), is("AVD. 50090 HB3S"));
    collector.checkThat(registeredAddressInvoiceRecipient.getLine2(), nullValue());
    collector.checkThat(registeredAddressInvoiceRecipient.getCity(), is("Göteborg"));
    collector.checkThat(registeredAddressInvoiceRecipient.getCounty(), nullValue());
    collector.checkThat(registeredAddressInvoiceRecipient.getPostalCode(), is("40531"));
    collector.checkThat(registeredAddressInvoiceRecipient.getCountryCode().getValue(), is("SE"));
    collector.checkThat(registeredAddressInvoiceRecipient.getAddressType().getValue(), is(1));

    collector.checkThat(
        splittingRule.getSplittingRuleId().getGuid(), is("8f756919-c9ed-e111-8b5b-005056b45da6"));
    collector.checkThat(
        splittingRule.getInvoiceRecipientId().getGuid(),
        is("3ac9520d-c9ed-e111-8b5b-005056b45da6"));
    collector.checkThat(splittingRule.getSplitter(), is("kjhh567855"));

    collector.checkThat(
        purchaseOrder.getInvoicingRuleId().getGuid(), is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(purchaseOrder.getPoNumber(), is("234 - do not edit"));
    collector.checkThat(
        purchaseOrder.getPurchaseOrderId().getGuid(), is("00000000-0000-0000-4000-100000000001"));
    collector.checkThat(
        purchaseOrder.getValidFrom().getTimestamp(), is("2012-08-15T00:00:00.000+02:00"));
    collector.checkThat(
        purchaseOrder.getValidTo().getTimestamp(), is("2012-08-17T00:00:00.000+02:00"));

    collector.checkThat(
        invoiceMessageRule.getInvoiceMessageRuleId().getGuid(),
        is("00000000-0000-0000-3000-100000000001"));
    collector.checkThat(
        invoiceMessageRule.getInvoicingRuleId().getGuid(),
        is("3f2504e0-4f89-11d3-9a0c-0305e82c3405"));
    collector.checkThat(
        invoiceMessageRule.getMessageText(),
        is("This is a text to be printed on all invoices for this invoicing rule"));
    collector.checkThat(
        invoiceMessageRule.getValidFrom().getTimestamp(), is("2012-08-13T00:00:00.000+02:00"));
    collector.checkThat(
        invoiceMessageRule.getValidTo().getTimestamp(), is("2012-08-30T00:00:00.000+02:00"));
  }
コード例 #29
0
  /**
   * Test importing of data_rppa file.
   *
   * @throws Exception All Errors.
   */
  @Test
  public void testImportRppaData() throws Exception {
    MySQLbulkLoader.bulkLoadOn();

    DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
    DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance();

    // Genes with alias:
    daoGene.addGene(makeGeneWithAlias(999999931, "TESTACACA", "TESTACC1"));
    daoGene.addGene(makeGeneWithAlias(999999207, "TESTAKT1", "TESTAKT"));
    daoGene.addGene(makeGeneWithAlias(999999597, "TESTSANDER", "TESTACC1"));
    daoGene.addGene(makeGeneWithAlias(999997158, "TESTTP53BP1", "TEST53BP1"));
    // test for NA being a special case in RPPA, and not the usual alias
    daoGene.addGene(makeGeneWithAlias(999997504, "XK", "NA"));
    // Other genes:
    daoGene.addGene(new CanonicalGene(999999932, "TESTACACB"));
    daoGene.addGene(new CanonicalGene(999999208, "TESTAKT2"));
    daoGene.addGene(new CanonicalGene(999999369, "TESTARAF"));
    daoGene.addGene(new CanonicalGene(999991978, "TESTEIF4EBP1"));
    daoGene.addGene(new CanonicalGene(999995562, "TESTPRKAA1"));
    daoGene.addGene(new CanonicalGene(999997531, "TESTYWHAE"));
    daoGene.addGene(new CanonicalGene(999910000, "TESTAKT3"));
    daoGene.addGene(new CanonicalGene(999995578, "TESTPRKCA"));

    GeneticProfile geneticProfile = new GeneticProfile();

    geneticProfile.setCancerStudyId(studyId);
    geneticProfile.setStableId("gbm_rppa");
    geneticProfile.setGeneticAlterationType(GeneticAlterationType.PROTEIN_LEVEL);
    geneticProfile.setDatatype("LOG2-VALUE");
    geneticProfile.setProfileName("RPPA Data");
    geneticProfile.setProfileDescription("RPPA Data");
    DaoGeneticProfile.addGeneticProfile(geneticProfile);

    int newGeneticProfileId =
        DaoGeneticProfile.getGeneticProfileByStableId("gbm_rppa").getGeneticProfileId();

    ProgressMonitor.setConsoleMode(true);
    // TBD: change this to use getResourceAsStream()
    File file = new File("src/test/resources/tabDelimitedData/data_rppa.txt");
    ImportTabDelimData parser = new ImportTabDelimData(file, newGeneticProfileId, null);
    int numLines = FileUtil.getNumLines(file);
    parser.importData(numLines);
    ConsoleUtil.showMessages();

    int sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE1").getInternalId();
    String value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997531);
    assertEquals("1.5", value);

    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE4").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997531);
    assertEquals("2", value);

    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE4").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997504);
    assertEquals(
        "NaN",
        value); // "NA" is not expected to be stored because of workaround for bug in firehose. See
                // also https://github.com/cBioPortal/cbioportal/issues/839#issuecomment-203523078

    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE1").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999995578);
    assertEquals("1.5", value);
  }
コード例 #30
0
  /**
   * Test importing of data_expression file.
   *
   * @throws Exception All Errors.
   */
  @Test
  public void testImportmRnaData2() throws Exception {
    MySQLbulkLoader.bulkLoadOn();

    DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance();
    DaoGeneticAlteration dao = DaoGeneticAlteration.getInstance();

    // Gene with alias:
    daoGene.addGene(makeGeneWithAlias(999997504, "TESTXK", "NA"));
    // Other genes:
    daoGene.addGene(new CanonicalGene(999999999, "TESTNAT1"));

    daoGene.addGene(new CanonicalGene(999997124, "TESTTNF"));
    daoGene.addGene(new CanonicalGene(999991111, "TESTCHEK1"));
    daoGene.addGene(new CanonicalGene(999999919, "TESTABCA1"));
    // will get generated negative id:
    daoGene.addGene(new CanonicalGene(-1, "TESTphosphoprotein"));

    GeneticProfile geneticProfile = new GeneticProfile();

    geneticProfile.setCancerStudyId(studyId);
    geneticProfile.setStableId("gbm_mrna");
    geneticProfile.setGeneticAlterationType(GeneticAlterationType.MRNA_EXPRESSION);
    geneticProfile.setDatatype("CONTINUOUS");
    geneticProfile.setProfileName("MRNA Data");
    geneticProfile.setProfileDescription("mRNA Data");
    DaoGeneticProfile.addGeneticProfile(geneticProfile);

    int newGeneticProfileId =
        DaoGeneticProfile.getGeneticProfileByStableId("gbm_mrna").getGeneticProfileId();

    ProgressMonitor.setConsoleMode(true);
    // TBD: change this to use getResourceAsStream()
    File file = new File("src/test/resources/tabDelimitedData/data_expression2.txt");
    ImportTabDelimData parser = new ImportTabDelimData(file, newGeneticProfileId, null);
    int numLines = FileUtil.getNumLines(file);
    parser.importData(numLines);

    // check if expected warnings are given:
    ArrayList<String> warnings = ProgressMonitor.getWarnings();
    int countDuplicatedRowWarnings = 0;
    int countInvalidEntrez = 0;
    int countSkippedWarnings = 0;
    for (String warning : warnings) {
      if (warning.contains("Duplicated row")) {
        countDuplicatedRowWarnings++;
      }
      if (warning.contains("invalid Entrez_Id")) {
        // invalid Entrez
        countInvalidEntrez++;
      }
      if (warning.contains("Record will be skipped")) {
        // Entrez is a valid number, but not found
        countSkippedWarnings++;
      }
    }
    // check that we have 11 warning messages:
    assertEquals(2, countDuplicatedRowWarnings);
    assertEquals(3, countInvalidEntrez);
    assertEquals(6, countSkippedWarnings);

    Set<Long> entrezGeneIds = DaoGeneticAlteration.getGenesIdInProfile(newGeneticProfileId);
    // data will be loaded for 5 of the genes
    assertEquals(5, entrezGeneIds.size());
    HashMap<Long, HashMap<Integer, String>> dataMap =
        dao.getGeneticAlterationMap(newGeneticProfileId, entrezGeneIds);
    assertEquals(5, dataMap.entrySet().size());

    int sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE1").getInternalId();
    String value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997124);
    assertEquals("770", value);

    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE3").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997124);
    assertEquals("220", value);

    // gene should also be loaded via its alias "NA" as defined above:
    sampleId = DaoSample.getSampleByCancerStudyAndSampleId(studyId, "SAMPLE3").getInternalId();
    value = dao.getGeneticAlteration(newGeneticProfileId, sampleId, 999997504);
    assertEquals("9940", value);
  }