Ejemplo n.º 1
0
        /// <summary>Set up a mock NN with the bare minimum for a DN to register to it.</summary>
        /// <exception cref="System.Exception"/>
        private DatanodeProtocolClientSideTranslatorPB SetupNNMock(int nnIdx)
        {
            DatanodeProtocolClientSideTranslatorPB mock = Org.Mockito.Mockito.Mock <DatanodeProtocolClientSideTranslatorPB
                                                                                    >();

            Org.Mockito.Mockito.DoReturn(new NamespaceInfo(1, FakeClusterid, FakeBpid, 0)).When
                (mock).VersionRequest();
            Org.Mockito.Mockito.DoReturn(DFSTestUtil.GetLocalDatanodeRegistration()).When(mock
                                                                                          ).RegisterDatanode(Org.Mockito.Mockito.Any <DatanodeRegistration>());
            Org.Mockito.Mockito.DoAnswer(new TestBPOfferService.HeartbeatAnswer(this, nnIdx))
            .When(mock).SendHeartbeat(Org.Mockito.Mockito.Any <DatanodeRegistration>(), Org.Mockito.Mockito
                                      .Any <StorageReport[]>(), Org.Mockito.Mockito.AnyLong(), Org.Mockito.Mockito.AnyLong
                                          (), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito
                                      .AnyInt(), Org.Mockito.Mockito.Any <VolumeFailureSummary>());
            mockHaStatuses[nnIdx] = new NNHAStatusHeartbeat(HAServiceProtocol.HAServiceState.
                                                            Standby, 0);
            return(mock);
        }
Ejemplo n.º 2
0
        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(
                                              ));
        }