Package org.apache.hadoop.hdfs.client

Examples of org.apache.hadoop.hdfs.client.ClientMmapManager


      fsIn = fs.open(TEST_PATH);
      byte original[] = new byte[TEST_FILE_LENGTH];
      IOUtils.readFully(fsIn, original, 0, TEST_FILE_LENGTH);
      fsIn.close();
      fsIn = fs.open(TEST_PATH);
      final ClientMmapManager mmapManager = fs.getClient().getMmapManager();
      final CountingVisitor countingVisitor = new CountingVisitor();
      mmapManager.visitMmaps(countingVisitor);
      Assert.assertEquals(0, countingVisitor.count);
      mmapManager.visitEvictable(countingVisitor);
      Assert.assertEquals(0, countingVisitor.count);
      results[0] = fsIn.read(null, 4096,
          EnumSet.of(ReadOption.SKIP_CHECKSUMS));
      fsIn.seek(0);
      results[1] = fsIn.read(null, 4096,
          EnumSet.of(ReadOption.SKIP_CHECKSUMS));
      mmapManager.visitMmaps(countingVisitor);
      Assert.assertEquals(1, countingVisitor.count);
      countingVisitor.reset();
      mmapManager.visitEvictable(countingVisitor);
      Assert.assertEquals(0, countingVisitor.count);
      countingVisitor.reset();

      // The mmaps should be of the first block of the file.
      final ExtendedBlock firstBlock = DFSTestUtil.getFirstBlock(fs, TEST_PATH);
      mmapManager.visitMmaps(new ClientMmapManager.ClientMmapVisitor() {
        @Override
        public void accept(ClientMmap mmap) {
          Assert.assertEquals(firstBlock, mmap.getBlock());
        }
      });

      // Read more blocks.
      results[2] = fsIn.read(null, 4096,
          EnumSet.of(ReadOption.SKIP_CHECKSUMS));
      results[3] = fsIn.read(null, 4096,
          EnumSet.of(ReadOption.SKIP_CHECKSUMS));
      try {
        results[4] = fsIn.read(null, 4096,
            EnumSet.of(ReadOption.SKIP_CHECKSUMS));
        Assert.fail("expected UnsupportedOperationException");
      } catch (UnsupportedOperationException e) {
        // expected
      }

      // we should have 3 mmaps, 0 evictable
      mmapManager.visitMmaps(countingVisitor);
      Assert.assertEquals(3, countingVisitor.count);
      countingVisitor.reset();
      mmapManager.visitEvictable(countingVisitor);
      Assert.assertEquals(0, countingVisitor.count);

      // After we close the cursors, the mmaps should be evictable for
      // a brief period of time.  Then, they should be closed (we're
      // using a very quick timeout)
      for (ByteBuffer buffer : results) {
        if (buffer != null) {
          fsIn.releaseBuffer(buffer);
        }
      }
      GenericTestUtils.waitFor(new Supplier<Boolean>() {
        public Boolean get() {
          countingVisitor.reset();
          try {
            mmapManager.visitEvictable(countingVisitor);
          } catch (InterruptedException e) {
            e.printStackTrace();
            return false;
          }
          return (0 == countingVisitor.count);
        }
      }, 10, 10000);
      countingVisitor.reset();
      mmapManager.visitMmaps(countingVisitor);
      Assert.assertEquals(0, countingVisitor.count);
    } finally {
      if (fsIn != null) fsIn.close();
      if (fs != null) fs.close();
      if (cluster != null) cluster.shutdown();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.client.ClientMmapManager

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.