Ejemplo n.º 1
0
            Answer(InvocationOnMock invocation)
            {
                object[] args = invocation.GetArguments();
                NUnit.Framework.Assert.AreEqual(2, args.Length);
                ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto req = (ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto
                                                                                        )args[1];
                ICollection <TokenIdentifier> tokenIds = UserGroupInformation.GetCurrentUser().GetTokenIdentifiers
                                                             ();

                NUnit.Framework.Assert.AreEqual("Only one BlockTokenIdentifier expected", 1, tokenIds
                                                .Count);
                long result = 0;

                foreach (TokenIdentifier tokenId in tokenIds)
                {
                    BlockTokenIdentifier id = (BlockTokenIdentifier)tokenId;
                    Log.Info("Got: " + id.ToString());
                    NUnit.Framework.Assert.IsTrue("Received BlockTokenIdentifier is wrong", ident.Equals
                                                      (id));
                    sm.CheckAccess(id, null, PBHelper.Convert(req.GetBlock()), BlockTokenSecretManager.AccessMode
                                   .Write);
                    result = id.GetBlockId();
                }
                return((ClientDatanodeProtocolProtos.GetReplicaVisibleLengthResponseProto)ClientDatanodeProtocolProtos.GetReplicaVisibleLengthResponseProto
                       .NewBuilder().SetLength(result).Build());
            }
Ejemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        private BlockTokenIdentifier GenerateTokenId(BlockTokenSecretManager sm, ExtendedBlock
                                                     block, EnumSet <BlockTokenSecretManager.AccessMode> accessModes)
        {
            Org.Apache.Hadoop.Security.Token.Token <BlockTokenIdentifier> token = sm.GenerateToken
                                                                                      (block, accessModes);
            BlockTokenIdentifier id = sm.CreateIdentifier();

            id.ReadFields(new DataInputStream(new ByteArrayInputStream(token.GetIdentifier())
                                              ));
            return(id);
        }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Com.Google.Protobuf.ServiceException"/>
        private static Server CreateMockDatanode(BlockTokenSecretManager sm, Org.Apache.Hadoop.Security.Token.Token
                                                 <BlockTokenIdentifier> token, Configuration conf)
        {
            ClientDatanodeProtocolPB mockDN = Org.Mockito.Mockito.Mock <ClientDatanodeProtocolPB
                                                                        >();
            BlockTokenIdentifier id = sm.CreateIdentifier();

            id.ReadFields(new DataInputStream(new ByteArrayInputStream(token.GetIdentifier())
                                              ));
            Org.Mockito.Mockito.DoAnswer(new TestBlockToken.GetLengthAnswer(sm, id)).When(mockDN
                                                                                          ).GetReplicaVisibleLength(Matchers.Any <RpcController>(), Matchers.Any <ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto
                                                                                                                                                                  >());
            RPC.SetProtocolEngine(conf, typeof(ClientDatanodeProtocolPB), typeof(ProtobufRpcEngine
                                                                                 ));
            BlockingService service = ClientDatanodeProtocolProtos.ClientDatanodeProtocolService
                                      .NewReflectiveBlockingService(mockDN);

            return(new RPC.Builder(conf).SetProtocol(typeof(ClientDatanodeProtocolPB)).SetInstance
                       (service).SetBindAddress(Address).SetPort(0).SetNumHandlers(5).SetVerbose(true).
                   SetSecretManager(sm).Build());
        }
Ejemplo n.º 4
0
 public GetLengthAnswer(BlockTokenSecretManager sm, BlockTokenIdentifier ident)
 {
     this.sm    = sm;
     this.ident = ident;
 }