Package org.apache.hadoop.fs.DU

Examples of org.apache.hadoop.fs.DU.NamespaceSliceDU


    Configuration conf = new Configuration();

    Thread.sleep(5000); // let the metadata updater catch up
   
    DU du = new DU(file, 1000);
    NamespaceSliceDU nsdu0 = du.addNamespace(0, file0, conf);
    NamespaceSliceDU nsdu1 = du.addNamespace(1, file1, conf);
    du.start();
    long duSize0 = nsdu0.getUsed();
    long duSize1 = nsdu1.getUsed();
    assertEquals(writtenSize, duSize0);
    assertEquals(writtenSize, duSize1);
    // delete the file, expect it throws exception
    file0.delete();
    file1.delete();
    Thread.sleep(2000);
    try {
      duSize0 = nsdu0.getUsed();
      assertTrue(false);
    } catch (IOException ex) {
    }
    try {
      duSize1 = nsdu1.getUsed();
      assertTrue(false);
    } catch (IOException ex) {
    }
    //change the size
    createFile(file0, writtenSize - 4096);
    createFile(file1, writtenSize + 4096);
    Thread.sleep(5000);
    duSize0 = nsdu0.getUsed();
    duSize1 = nsdu1.getUsed();
    du.shutdown();

    assertEquals(writtenSize - 4096, duSize0);
    assertEquals(writtenSize + 4096, duSize1);
   
    //test with 0 interval, will not launch thread
    du = new DU(file, 0);
    nsdu0 = du.addNamespace(0, file0, conf);
    nsdu1 = du.addNamespace(1, file1, conf);
    du.start();
    duSize0 = nsdu0.getUsed();
    duSize1 = nsdu1.getUsed();
    du.shutdown();
   
    assertEquals(writtenSize - 4096, duSize0)
    assertEquals(writtenSize + 4096, duSize1)
   
    //test without launching thread
    du = new DU(file, 10000);
    nsdu0 = du.addNamespace(0, file0, new Configuration());
    duSize0 = nsdu0.getUsed();
   
    assertEquals(writtenSize - 4096, duSize0);
   
    // test processErrorOutput
    Field namespaceSliceDUMapField = DU.class.getDeclaredField("namespaceSliceDUMap");
    namespaceSliceDUMapField.setAccessible(true);
    ConcurrentMap<Integer, NamespaceSliceDU> namespaceSliceDUMap = (ConcurrentMap<Integer, NamespaceSliceDU>) namespaceSliceDUMapField
        .get(du);
    NamespaceSliceDU nssd = namespaceSliceDUMap.get(0);

    // Throw when exit code is not 1
    boolean thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a1.txt': No such file or directory"));
    } catch(ExitCodeException ece) {
      thrown = true;
    }
    TestCase.assertTrue(thrown);
   
    Field exitCodeField = Shell.class.getDeclaredField("exitCode");
    exitCodeField.setAccessible(true);
    exitCodeField.set(nssd, 1);
   
    // One single file fails to be accessed.
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a1.txt': No such file or directory"));

    // Two files fail to be accessed
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a2.txt': No such file or directory\ndu: cannot access `a3.txt': No such file or directory"));

    // Two files fail to be accessed, one is the same as the previous one
    thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(
          1,
          "du: cannot access `a4.txt': No such file or directory\ndu: cannot access `a3.txt': No such file or directory"));
    } catch (IOException ioe) {
      thrown = true;
    }
    TestCase.assertTrue(thrown);

    // Two files fail to be accessed, one is the same as a previous one
    thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(
          1,
          "du: cannot access `a2.txt': No such file or directory\ndu: cannot access `a5.txt': No such file or directory"));
    } catch (IOException ioe) {
      thrown = true;
    }
    TestCase.assertTrue(thrown)

    // Two files fail to be accessed
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a6.txt': No such file or directory"));
  }
View Full Code Here


    Configuration conf = new Configuration();

    Thread.sleep(5000); // let the metadata updater catch up
   
    DU du = new DU(file, 1000);
    NamespaceSliceDU nsdu0 = du.addNamespace(0, file0, conf);
    NamespaceSliceDU nsdu1 = du.addNamespace(1, file1, conf);
    du.start();
    long duSize0 = nsdu0.getUsed();
    long duSize1 = nsdu1.getUsed();
    assertEquals(writtenSize, duSize0);
    assertEquals(writtenSize, duSize1);
    // delete the file, expect it throws exception
    file0.delete();
    file1.delete();
    Thread.sleep(2000);
    try {
      duSize0 = nsdu0.getUsed();
      assertTrue(false);
    } catch (IOException ex) {
    }
    try {
      duSize1 = nsdu1.getUsed();
      assertTrue(false);
    } catch (IOException ex) {
    }
    //change the size
    createFile(file0, writtenSize - 4096);
    createFile(file1, writtenSize + 4096);
    Thread.sleep(5000);
    duSize0 = nsdu0.getUsed();
    duSize1 = nsdu1.getUsed();
    du.shutdown();

    assertEquals(writtenSize - 4096, duSize0);
    assertEquals(writtenSize + 4096, duSize1);
   
    //test with 0 interval, will not launch thread
    du = new DU(file, 0);
    nsdu0 = du.addNamespace(0, file0, conf);
    nsdu1 = du.addNamespace(1, file1, conf);
    du.start();
    duSize0 = nsdu0.getUsed();
    duSize1 = nsdu1.getUsed();
    du.shutdown();
   
    assertEquals(writtenSize - 4096, duSize0)
    assertEquals(writtenSize + 4096, duSize1)
   
    //test without launching thread
    du = new DU(file, 10000);
    nsdu0 = du.addNamespace(0, file0, new Configuration());
    duSize0 = nsdu0.getUsed();
   
    assertEquals(writtenSize - 4096, duSize0);
   
    // test processErrorOutput
    Field namespaceSliceDUMapField = DU.class.getDeclaredField("namespaceSliceDUMap");
    namespaceSliceDUMapField.setAccessible(true);
    ConcurrentMap<Integer, NamespaceSliceDU> namespaceSliceDUMap = (ConcurrentMap<Integer, NamespaceSliceDU>) namespaceSliceDUMapField
        .get(du);
    NamespaceSliceDU nssd = namespaceSliceDUMap.get(0);

    // Throw when exit code is not 1
    boolean thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a1.txt': No such file or directory"));
    } catch(ExitCodeException ece) {
      thrown = true;
    }
    TestCase.assertTrue(thrown);
   
    Field exitCodeField = Shell.class.getDeclaredField("exitCode");
    exitCodeField.setAccessible(true);
    exitCodeField.set(nssd, 1);
   
    // One single file fails to be accessed.
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a1.txt': No such file or directory"));

    // Two files fail to be accessed
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a2.txt': No such file or directory\ndu: cannot access `a3.txt': No such file or directory"));

    // Two files fail to be accessed, one is the same as the previous one
    thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(
          1,
          "du: cannot access `a4.txt': No such file or directory\ndu: cannot access `a3.txt': No such file or directory"));
    } catch (IOException ioe) {
      thrown = true;
    }
    TestCase.assertTrue(thrown);

    // Two files fail to be accessed, one is the same as a previous one
    thrown = false;
    try {
      nssd.processErrorOutput(new ExitCodeException(
          1,
          "du: cannot access `a2.txt': No such file or directory\ndu: cannot access `a5.txt': No such file or directory"));
    } catch (IOException ioe) {
      thrown = true;
    }
    TestCase.assertTrue(thrown)

    // Two files fail to be accessed
    nssd.processErrorOutput(new ExitCodeException(1, "du: cannot access `a6.txt': No such file or directory"));
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.fs.DU.NamespaceSliceDU

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.