public virtual void TestCommitBlockSynchronization() { INodeFile file = MockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = MakeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, false , newTargets, null); // Repeat the call to make sure it does not throw namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, false , newTargets, null); // Simulate 'completing' the block. BlockInfoContiguous completedBlockInfo = new BlockInfoContiguous(block, (short)1); completedBlockInfo.SetBlockCollection(file); completedBlockInfo.SetGenerationStamp(genStamp); Org.Mockito.Mockito.DoReturn(completedBlockInfo).When(namesystemSpy).GetStoredBlock (Matchers.Any <Block>()); Org.Mockito.Mockito.DoReturn(completedBlockInfo).When(file).GetLastBlock(); // Repeat the call to make sure it does not throw namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, false , newTargets, null); }
public virtual void TestCommitBlockSynchronizationWithCloseAndNonExistantTarget() { INodeFile file = MockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = MakeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[] { new DatanodeID("0.0.0.0", "nonexistantHost" , "1", 0, 0, 0, 0) }; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, true, false , newTargets, null); // Repeat the call to make sure it returns true namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, true, false , newTargets, null); }
public virtual void TestCommitBlockSynchronizationWithDelete() { INodeFile file = MockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = MakeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, true , newTargets, null); // Simulate removing the last block from the file. Org.Mockito.Mockito.DoReturn(false).When(file).RemoveLastBlock(Matchers.Any <Block >()); // Repeat the call to make sure it does not throw namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, true , newTargets, null); }
public virtual void TestCommitBlockSynchronization2() { INodeFile file = MockFileUnderConstruction(); Block block = new Block(blockId, length, genStamp); FSNamesystem namesystemSpy = MakeNameSystemSpy(block, file); DatanodeID[] newTargets = new DatanodeID[0]; ExtendedBlock lastBlock = new ExtendedBlock(); namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp, length, false, false , newTargets, null); // Make sure the call fails if the generation stamp does not match // the block recovery ID. try { namesystemSpy.CommitBlockSynchronization(lastBlock, genStamp - 1, length, false, false, newTargets, null); NUnit.Framework.Assert.Fail("Failed to get expected IOException on generation stamp/" + "recovery ID mismatch"); } catch (IOException) { } }