use of org.apache.hadoop.hdfs.protocol.Block in project hadoop by apache.
the class TestReadStripedFileWithDecoding method testInvalidateBlock.
@Test
public void testInvalidateBlock() throws IOException {
final Path file = new Path("/invalidate");
final int length = 10;
final byte[] bytes = StripedFileTestUtil.generateBytes(length);
DFSTestUtil.writeFile(fs, file, bytes);
int dnIndex = findFirstDataNode(file, cellSize * dataBlocks);
Assert.assertNotEquals(-1, dnIndex);
LocatedStripedBlock slb = (LocatedStripedBlock) fs.getClient().getLocatedBlocks(file.toString(), 0, cellSize * dataBlocks).get(0);
final LocatedBlock[] blks = StripedBlockUtil.parseStripedBlockGroup(slb, cellSize, dataBlocks, parityBlocks);
final Block b = blks[0].getBlock().getLocalBlock();
DataNode dn = cluster.getDataNodes().get(dnIndex);
// disable the heartbeat from DN so that the invalidated block record is kept
// in NameNode until heartbeat expires and NN mark the dn as dead
DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, true);
try {
// delete the file
fs.delete(file, true);
// check the block is added to invalidateBlocks
final FSNamesystem fsn = cluster.getNamesystem();
final BlockManager bm = fsn.getBlockManager();
DatanodeDescriptor dnd = NameNodeAdapter.getDatanode(fsn, dn.getDatanodeId());
Assert.assertTrue(bm.containsInvalidateBlock(blks[0].getLocations()[0], b) || dnd.containsInvalidateBlock(b));
} finally {
DataNodeTestUtils.setHeartbeatsDisabledForTests(dn, false);
}
}
use of org.apache.hadoop.hdfs.protocol.Block in project hadoop by apache.
the class TestPBHelper method getBlockWithLocations.
private static BlockWithLocations getBlockWithLocations(int bid, boolean isStriped) {
final String[] datanodeUuids = { "dn1", "dn2", "dn3" };
final String[] storageIDs = { "s1", "s2", "s3" };
final StorageType[] storageTypes = { StorageType.DISK, StorageType.DISK, StorageType.DISK };
final byte[] indices = { 0, 1, 2 };
final short dataBlkNum = 6;
BlockWithLocations blkLocs = new BlockWithLocations(new Block(bid, 0, 1), datanodeUuids, storageIDs, storageTypes);
if (isStriped) {
blkLocs = new StripedBlockWithLocations(blkLocs, indices, dataBlkNum, StripedFileTestUtil.getDefaultECPolicy().getCellSize());
}
return blkLocs;
}
use of org.apache.hadoop.hdfs.protocol.Block in project hadoop by apache.
the class TestPBHelper method testConvertBlock.
@Test
public void testConvertBlock() {
Block b = new Block(1, 100, 3);
BlockProto bProto = PBHelperClient.convert(b);
Block b2 = PBHelperClient.convert(bProto);
assertEquals(b, b2);
}
use of org.apache.hadoop.hdfs.protocol.Block in project hadoop by apache.
the class TestBlockInfoStriped method testWrite.
@Test
public void testWrite() {
long blkID = 1;
long numBytes = 1;
long generationStamp = 1;
ByteBuffer byteBuffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE * 3);
byteBuffer.putLong(blkID).putLong(numBytes).putLong(generationStamp);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(byteStream);
BlockInfoStriped blk = new BlockInfoStriped(new Block(blkID, numBytes, generationStamp), testECPolicy);
try {
blk.write(out);
} catch (Exception ex) {
fail("testWrite error:" + ex.getMessage());
}
assertEquals(byteBuffer.array().length, byteStream.toByteArray().length);
assertArrayEquals(byteBuffer.array(), byteStream.toByteArray());
}
use of org.apache.hadoop.hdfs.protocol.Block in project hadoop by apache.
the class TestBlockInfoStriped method testAddStorageWithDifferentBlockGroup.
@Test(expected = IllegalArgumentException.class)
public void testAddStorageWithDifferentBlockGroup() {
DatanodeStorageInfo storage = DFSTestUtil.createDatanodeStorageInfo("storageID", "127.0.0.1");
BlockInfo diffGroup = new BlockInfoStriped(new Block(BASE_ID + 100), testECPolicy);
info.addStorage(storage, diffGroup);
}
Aggregations