Exemplo n.º 1
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocationOnMock)
            {
                Path dest = (Path)invocationOnMock.GetArguments()[1];

                if (dest.ToString().Contains(firstDir.ToString()))
                {
                    throw new IOException("No space on this drive " + dest.ToString());
                }
                else
                {
                    DataOutputStream tokenOut = null;
                    try
                    {
                        Credentials credentials = new Credentials();
                        tokenOut = mockLfs.Create(dest, EnumSet.Of(CreateFlag.Create, CreateFlag.Overwrite
                                                                   ));
                        credentials.WriteTokenStorageToStream(tokenOut);
                    }
                    finally
                    {
                        if (tokenOut != null)
                        {
                            tokenOut.Close();
                        }
                    }
                }
                return(null);
            }
Exemplo n.º 2
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());
            }
Exemplo n.º 3
0
            /// <exception cref="System.Exception"/>
            public virtual T Answer(InvocationOnMock invocation)
            {
                // Don't want to inject an error on close() since that isn't
                // actually an IPC call!
                if (!typeof(IDisposable).Equals(invocation.GetMethod().DeclaringType))
                {
                    BeforeCall(invocation);
                }
                bool success = false;

                try
                {
                    T ret = (T)invocation.GetMethod().Invoke(realObj, invocation.GetArguments());
                    success = true;
                    return(ret);
                }
                catch (TargetInvocationException ite)
                {
                    throw ite.InnerException;
                }
                finally
                {
                    AfterCall(invocation, success);
                }
            }
 /// <exception cref="System.Exception"/>
 public Void Answer(InvocationOnMock invocation)
 {
     object[] args = invocation.GetArguments();
     journalSet.SelectInputStreams((ICollection <EditLogInputStream>)args[0], (long)args
                                   [1], (bool)args[2]);
     return(null);
 }
Exemplo n.º 5
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocation)
            {
                object[]     args = invocation.GetArguments();
                FsPermission perm = (FsPermission)args[0];

                return(new PermissionStatus(TestFSPermissionChecker.Superuser, TestFSPermissionChecker
                                            .Supergroup, perm));
            }
Exemplo n.º 6
0
 public DatanodeProtocolProtos.BlockReportResponseProto Answer(InvocationOnMock invocation
                                                               )
 {
     object[] args = invocation.GetArguments();
     request.Set((DatanodeProtocolProtos.BlockReportRequestProto)args[1]);
     return((DatanodeProtocolProtos.BlockReportResponseProto)DatanodeProtocolProtos.BlockReportResponseProto
            .NewBuilder().Build());
 }
Exemplo n.º 7
0
            public Org.Apache.Hadoop.Security.Token.Token <object>[] Answer(InvocationOnMock invocation
                                                                            )
            {
                Credentials creds = (Credentials)invocation.GetArguments()[1];

                creds.AddToken(service, t);
                return(new Org.Apache.Hadoop.Security.Token.Token <object>[] { t });
            }
Exemplo n.º 8
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocationOnMock)
            {
                string diagnostics = (string)invocationOnMock.GetArguments()[0];

                NUnit.Framework.Assert.IsTrue("Invalid Diagnostics message: " + diagnostics, diagnostics
                                              .Contains("No such file or directory"));
                return(null);
            }
Exemplo n.º 9
0
            public Void Answer(InvocationOnMock invocation)
            {
                object[]        args = invocation.GetArguments();
                DataInputBuffer key  = (DataInputBuffer)args[0];

                key.Reset(Sharpen.Runtime.GetBytesForString(("Segment Value " + segmentName + this
                                                             .i)), 20);
                return(null);
            }
            /// <exception cref="System.Exception"/>
            public Void Answer(InvocationOnMock invocation)
            {
                FSImageStorageInspector inspector = (FSImageStorageInspector)invocation.GetArguments
                                                        ()[0];

                foreach (Storage.StorageDirectory sd in mockDirs)
                {
                    inspector.InspectDirectory(sd);
                }
                return(null);
            }
                /// <exception cref="System.Exception"/>
                public Void Answer(InvocationOnMock invocation)
                {
                    object[] args = invocation.GetArguments();
                    System.Diagnostics.Debug.Assert(args.Length == 1);
                    long txId = (long)args[0];

                    foreach (JournalManager jm in jms)
                    {
                        jm.PurgeLogsOlderThan(txId);
                    }
                    return(null);
                }
Exemplo n.º 12
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocationOnMock)
            {
                Path p = (Path)invocationOnMock.GetArguments()[0];

                if (p.ToString().Contains(firstDir.ToString()))
                {
                    return(new FsStatus(2000, 2000, 0));
                }
                else
                {
                    return(new FsStatus(1000, 0, 1000));
                }
            }
Exemplo n.º 13
0
            /// <exception cref="System.Exception"/>
            public FSDataInputStream Answer(InvocationOnMock args)
            {
                Path src = (Path)args.GetArguments()[0];

                if ("file.txt".Equals(src.GetName()))
                {
                    return(@in);
                }
                else
                {
                    throw new FileNotFoundException(src + " not supported by mocking");
                }
            }
Exemplo n.º 14
0
            /// <exception cref="System.Exception"/>
            public FileStatus Answer(InvocationOnMock args)
            {
                Path p = (Path)args.GetArguments()[0];

                if ("file.txt".Equals(p.GetName()))
                {
                    return(new FileStatus(201, false, 1, 500, 101, 101, FsPermission.GetDefault(), "me"
                                          , "me", filePath));
                }
                else
                {
                    throw new FileNotFoundException(p + " not supported by mocking");
                }
            }
Exemplo n.º 15
0
 /// <exception cref="System.Exception"/>
 public virtual object Answer(InvocationOnMock invocation)
 {
     try
     {
         if (log != null)
         {
             log.Info("Call to " + invocation + " on " + delegate_, new Exception("TRACE"));
         }
         return(invocation.GetMethod().Invoke(delegate_, invocation.GetArguments()));
     }
     catch (TargetInvocationException ite)
     {
         throw ite.InnerException;
     }
 }
Exemplo n.º 16
0
            public bool Answer(InvocationOnMock invocation)
            {
                if (this.i++ == 3)
                {
                    return(false);
                }
                IFile.Reader <Text, Text> mock = (IFile.Reader <Text, Text>)invocation.GetMock();
                int multiplier = isCompressedInput ? 100 : 1;

                mock.bytesRead += 10 * multiplier;
                object[]        args = invocation.GetArguments();
                DataInputBuffer key  = (DataInputBuffer)args[0];

                key.Reset(Sharpen.Runtime.GetBytesForString(("Segment Key " + segmentName + this.
                                                             i)), 20);
                return(true);
            }
Exemplo n.º 17
0
            /// <exception cref="System.Exception"/>
            public Void Answer(InvocationOnMock invocation)
            {
                SchedulerEvent @event = (SchedulerEvent)(invocation.GetArguments()[0]);

                this._enclosing.eventType = @event.GetType();
                if (this._enclosing.eventType == SchedulerEventType.NodeUpdate)
                {
                    IList <UpdatedContainerInfo> lastestContainersInfoList = ((NodeUpdateSchedulerEvent
                                                                               )@event).GetRMNode().PullContainerUpdates();
                    foreach (UpdatedContainerInfo lastestContainersInfo in lastestContainersInfoList)
                    {
                        Sharpen.Collections.AddAll(this._enclosing.completedContainers, lastestContainersInfo
                                                   .GetCompletedContainers());
                    }
                }
                return(null);
            }
Exemplo n.º 18
0
 /// <exception cref="System.Exception"/>
 public DatanodeRegistration Answer(InvocationOnMock invocation)
 {
     this.i++;
     if (this.i > 1 && this.i < 5)
     {
         TestDatanodeProtocolRetryPolicy.Log.Info("mockito exception " + this.i);
         throw new EOFException("TestDatanodeProtocolRetryPolicy");
     }
     else
     {
         DatanodeRegistration dr = (DatanodeRegistration)invocation.GetArguments()[0];
         TestDatanodeProtocolRetryPolicy.datanodeRegistration = new DatanodeRegistration(dr
                                                                                         .GetDatanodeUuid(), dr);
         TestDatanodeProtocolRetryPolicy.Log.Info("mockito succeeded " + TestDatanodeProtocolRetryPolicy
                                                  .datanodeRegistration);
         return(TestDatanodeProtocolRetryPolicy.datanodeRegistration);
     }
 }
Exemplo n.º 19
0
            public GetDelegationTokenResponse Answer(InvocationOnMock invocation)
            {
                GetDelegationTokenRequest request = (GetDelegationTokenRequest)invocation.GetArguments
                                                        ()[0];

                NUnit.Framework.Assert.AreEqual(masterPrincipal, request.GetRenewer());
                Org.Apache.Hadoop.Yarn.Api.Records.Token token = TestYARNRunner.recordFactory.NewRecordInstance
                                                                 <Org.Apache.Hadoop.Yarn.Api.Records.Token>();
                token.SetKind(string.Empty);
                token.SetService(string.Empty);
                token.SetIdentifier(ByteBuffer.Allocate(0));
                token.SetPassword(ByteBuffer.Allocate(0));
                GetDelegationTokenResponse tokenResponse = TestYARNRunner.recordFactory.NewRecordInstance
                                                           <GetDelegationTokenResponse>();

                tokenResponse.SetDelegationToken(token);
                return(tokenResponse);
            }
Exemplo n.º 20
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocationOnMock)
            {
                object[] args = invocationOnMock.GetArguments();
                Assert.Equal("authentication", args[0]);
                Assert.Equal(typeof(AuthenticationFilter).FullName, args[1]);
                IDictionary <string, string> conf = (IDictionary <string, string>)args[2];

                Assert.Equal("/", conf["cookie.path"]);
                Assert.Equal("simple", conf["type"]);
                Assert.Equal("36000", conf["token.validity"]);
                NUnit.Framework.Assert.IsNull(conf["cookie.domain"]);
                Assert.Equal("true", conf["simple.anonymous.allowed"]);
                Assert.Equal("HTTP/barhost@LOCALHOST", conf["kerberos.principal"
                             ]);
                Assert.Equal(Runtime.GetProperty("user.home") + "/hadoop.keytab"
                             , conf["kerberos.keytab"]);
                Assert.Equal("bar", conf["foo"]);
                return(null);
            }
Exemplo n.º 21
0
 /// <exception cref="System.Exception"/>
 public virtual Void Answer(InvocationOnMock invocation)
 {
     object[] args = invocation.GetArguments();
     Storage.StorageDirectory sd = (Storage.StorageDirectory)args[1];
     if (count++ == 1)
     {
         Log.Info("Injecting fault for sd: " + sd);
         if (throwRTE)
         {
             throw new RuntimeException("Injected fault: saveFSImage second time");
         }
         else
         {
             throw new IOException("Injected fault: saveFSImage second time");
         }
     }
     Log.Info("Not injecting fault for sd: " + sd);
     return((Void)invocation.CallRealMethod());
 }
Exemplo n.º 22
0
            public object Answer(InvocationOnMock invocation)
            {
                object[]      args = invocation.GetArguments();
                StringBuilder sb   = new StringBuilder();

                foreach (object o in args)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(o.ToString());
                }
                string methodName = invocation.GetMethod().Name;

                MetricsAsserts.Log.Debug(methodName + ": " + sb);
                return(methodName.Equals("parent") || methodName.Equals("endRecord") ? mc : invocation
                       .GetMock());
            }
Exemplo n.º 23
0
                /// <exception cref="System.Exception"/>
                internal override void BeforeCall(InvocationOnMock invocation)
                {
                    this._enclosing.rpcCount++;
                    string callStr = "[" + this._enclosing.addr + "] " + invocation.GetMethod().Name
                                     + "(" + Joiner.On(", ").Join(invocation.GetArguments()) + ")";
                    Callable <Void> inject = this._enclosing.injections[this._enclosing.rpcCount];

                    if (inject != null)
                    {
                        TestQJMWithFaults.Log.Info("Injecting code before IPC #" + this._enclosing.rpcCount
                                                   + ": " + callStr);
                        inject.Call();
                    }
                    else
                    {
                        TestQJMWithFaults.Log.Info("IPC call #" + this._enclosing.rpcCount + ": " + callStr
                                                   );
                    }
                }
Exemplo n.º 24
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="System.Exception"/>
 public object Answer(InvocationOnMock invocation)
 {
     Sharpen.Thread.Sleep(1000);
     data.FinalizeBlock((ExtendedBlock)invocation.GetArguments()[0]);
     return(null);
 }
 /// <exception cref="System.Exception"/>
 public Resource Answer(InvocationOnMock invocation)
 {
     object[] args = invocation.GetArguments();
     return((Resource)args[1]);
 }
Exemplo n.º 26
0
 /// <exception cref="System.Exception"/>
 public Path Answer(InvocationOnMock args)
 {
     return((Path)args.GetArguments()[0]);
 }
Exemplo n.º 27
0
            /// <exception cref="System.Exception"/>
            public FSDataInputStream Answer(InvocationOnMock args)
            {
                Path src = (Path)args.GetArguments()[0];

                throw new FileNotFoundException(src + " not supported by mocking");
            }
Exemplo n.º 28
0
            /// <exception cref="System.Exception"/>
            public FileStatus Answer(InvocationOnMock args)
            {
                Path p = (Path)args.GetArguments()[0];

                throw new FileNotFoundException(p + " not supported by mocking");
            }
Exemplo n.º 29
0
            /// <exception cref="System.Exception"/>
            public object Answer(InvocationOnMock invocationOnMock)
            {
                ContainerDiagnosticsUpdateEvent @event = (ContainerDiagnosticsUpdateEvent)invocationOnMock
                                                         .GetArguments()[0];

                NUnit.Framework.Assert.IsTrue("Invalid Diagnostics message: " + @event.GetDiagnosticsUpdate
                                                  (), @event.GetDiagnosticsUpdate().Contains("No such file or directory"));
                return(null);
            }
Exemplo n.º 30
0
            /// <exception cref="System.Exception"/>
            public Future <Path> Answer(InvocationOnMock invoc)
            {
                Future <Path> done = Org.Mockito.Mockito.Mock <Future>();

                Org.Mockito.Mockito.When(done.IsDone()).ThenReturn(true);
                TestContainerLocalizer.FakeDownload d = (TestContainerLocalizer.FakeDownload)invoc
                                                        .GetArguments()[0];
                Org.Mockito.Mockito.When(done.Get()).ThenReturn(d.Call());
                return(done);
            }