private void verifyCachedBlocksResult(CachedLocatedBlocks cachedBlocks, FSNamesystem namesystem, String file, INode f, int cachedReads) throws IOException{ long len = namesystem.getFileInfo(file).getLen(); List<LocatedBlock> res1 = namesystem.getBlockLocations(file, 0L, len).getLocatedBlocks(); List<LocatedBlock> res2 = policy.getLocatedBlocks(file, f); for (int i = 0; i < res1.size(); i++) { Assert.assertEquals(res1.get(i).getBlock(), res2.get(i).getBlock()); } Assert.assertEquals(cachedReads, h.events.get(InjectionEvent.BLOCKPLACEMENTPOLICYRAID_CACHED_BLOCKS).intValue()); }
private void verifyCachedBlocksResult(CachedLocatedBlocks cachedBlocks, FSNamesystem namesystem, String file) throws IOException{ long len = namesystem.getFileInfo(file).getLen(); List<LocatedBlock> res1 = namesystem.getBlockLocations(file, 0L, len).getLocatedBlocks(); List<LocatedBlock> res2 = cachedBlocks.get(file); for (int i = 0; i < res1.size(); i++) { Assert.assertEquals(res1.get(i).getBlock(), res2.get(i).getBlock()); } }
/** * Test BlockPlacementPolicyRaid.CachedLocatedBlocks * Verify that the results obtained from cache is the same as * the results obtained directly */ @Test public void testCachedBlocks() throws IOException { setupCluster(); try { String file1 = "/dir/file1"; String file2 = "/dir/file2"; DFSTestUtil.createFile(fs, new Path(file1), 3, (short)1, 0L); DFSTestUtil.createFile(fs, new Path(file2), 4, (short)1, 0L); // test blocks cache CachedLocatedBlocks cachedBlocks = new CachedLocatedBlocks(namesystem); verifyCachedBlocksResult(cachedBlocks, namesystem, file1); verifyCachedBlocksResult(cachedBlocks, namesystem, file1); verifyCachedBlocksResult(cachedBlocks, namesystem, file2); verifyCachedBlocksResult(cachedBlocks, namesystem, file2); try { Thread.sleep(1200L); } catch (InterruptedException e) { } verifyCachedBlocksResult(cachedBlocks, namesystem, file2); verifyCachedBlocksResult(cachedBlocks, namesystem, file1); } finally { if (cluster != null) { cluster.shutdown(); } } }
private void verifyCachedBlocksResult(CachedLocatedBlocks cachedBlocks, FSNamesystem namesystem, String file) throws IOException{ long len = namesystem.getFileInfo(file, true).getLen(); List<LocatedBlock> res1 = namesystem.getBlockLocations( file, 0L, len, false, false).getLocatedBlocks(); List<LocatedBlock> res2 = cachedBlocks.get(file); for (int i = 0; i < res1.size(); i++) { LOG.info("Actual block: " + res1.get(i).getBlock()); LOG.info("Cached block: " + res2.get(i).getBlock()); Assert.assertEquals(res1.get(i).getBlock(), res2.get(i).getBlock()); } }