public virtual void TestDatanodeDetect() { AtomicReference <DatanodeProtocolProtos.BlockReportRequestProto> request = new AtomicReference <DatanodeProtocolProtos.BlockReportRequestProto>(); // just capture the outgoing PB DatanodeProtocolPB mockProxy = Org.Mockito.Mockito.Mock <DatanodeProtocolPB>(); Org.Mockito.Mockito.DoAnswer(new _Answer_205(request)).When(mockProxy).BlockReport (Matchers.Any <RpcController>(), Matchers.Any <DatanodeProtocolProtos.BlockReportRequestProto >()); DatanodeProtocolClientSideTranslatorPB nn = new DatanodeProtocolClientSideTranslatorPB (mockProxy); DatanodeRegistration reg = DFSTestUtil.GetLocalDatanodeRegistration(); NamespaceInfo nsInfo = new NamespaceInfo(1, "cluster", "bp", 1); reg.SetNamespaceInfo(nsInfo); Replica r = new FinalizedReplica(new Block(1, 2, 3), null, null); BlockListAsLongs bbl = BlockListAsLongs.Encode(Sharpen.Collections.Singleton(r)); DatanodeStorage storage = new DatanodeStorage("s1"); StorageBlockReport[] sbr = new StorageBlockReport[] { new StorageBlockReport(storage , bbl) }; // check DN sends new-style BR request.Set(null); nsInfo.SetCapabilities(NamespaceInfo.Capability.StorageBlockReportBuffers.GetMask ()); nn.BlockReport(reg, "pool", sbr, new BlockReportContext(1, 0, Runtime.NanoTime()) ); DatanodeProtocolProtos.BlockReportRequestProto proto = request.Get(); NUnit.Framework.Assert.IsNotNull(proto); NUnit.Framework.Assert.IsTrue(proto.GetReports(0).GetBlocksList().IsEmpty()); NUnit.Framework.Assert.IsFalse(proto.GetReports(0).GetBlocksBuffersList().IsEmpty ()); // back up to prior version and check DN sends old-style BR request.Set(null); nsInfo.SetCapabilities(NamespaceInfo.Capability.Unknown.GetMask()); nn.BlockReport(reg, "pool", sbr, new BlockReportContext(1, 0, Runtime.NanoTime()) ); proto = request.Get(); NUnit.Framework.Assert.IsNotNull(proto); NUnit.Framework.Assert.IsFalse(proto.GetReports(0).GetBlocksList().IsEmpty()); NUnit.Framework.Assert.IsTrue(proto.GetReports(0).GetBlocksBuffersList().IsEmpty( )); }