コード例 #1
0
        public void TestWait()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.IsTrue(future.Wait());
        }
コード例 #2
0
        public void TestResult_WhenException()
        {
            var future = new SettableFuture<string>();
            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));

            var result = future.Result;
        }
コード例 #3
0
    public IFuture<HttpQueryResponse> ProcessQuery(string name,
      IDictionary<string, string> options, AsyncCallback callback, object state) {
      QueryRequestMessage request = new QueryRequestMessage.Builder()
        .SetName(name)
        .AddRangeOptions(GetQueryOptions(options))
        .Build();

      RubyMessagePacket packet = GetMessagePacket(GetNextRequestId(),
        request.ToByteString());
      try {
        QueryFuture future = new SettableFuture<HttpQueryResponse>(state);
        Tuple<AsyncCallback, QueryFuture> tuple = Tuple.Create(callback, future);
        futures_.Add(request_id_, tuple);

        // Send the request and wait for the response. The request should
        // follow the REQ/REP pattern, which contains the following parts:
        //   1. [EMPTY FRAME]
        //   2. [MESSAGE]
        // 
        socket_.SendMore();
        socket_.Send(packet.ToByteArray());
        return future;
      } catch (ZMQ.Exception zmqe) {
        return
          Futures.ImmediateFuture(
            GetExceptionResponse(name, HttpStatusCode.InternalServerError, zmqe));
      } catch (System.Exception e) {
        return
          Futures.ImmediateFuture(
            GetExceptionResponse(name, HttpStatusCode.InternalServerError, e));
      }
    }
コード例 #4
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 public virtual void MoveAllApps(string sourceQueue, string destQueue)
 {
     lock (this)
     {
         // check if destination queue is a valid leaf queue
         try
         {
             GetQueueInfo(destQueue, false, false);
         }
         catch (IOException e)
         {
             Log.Warn(e);
             throw new YarnException(e);
         }
         // check if source queue is a valid
         IList <ApplicationAttemptId> apps = GetAppsInQueue(sourceQueue);
         if (apps == null)
         {
             string errMsg = "The specified Queue: " + sourceQueue + " doesn't exist";
             Log.Warn(errMsg);
             throw new YarnException(errMsg);
         }
         // generate move events for each pending/running app
         foreach (ApplicationAttemptId app in apps)
         {
             SettableFuture <object> future = SettableFuture.Create();
             this.rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppMoveEvent(app.GetApplicationId
                                                                                            (), destQueue, future));
         }
     }
 }
コード例 #5
0
        void ProcessResponse(byte[] response)
        {
            try {
                var packet = RubyMessagePacket.ParseFrom(response);
                Tuple <AsyncCallback, QueryFuture> tuple;
                int request_id = packet.Message.Id.ToByteArray().AsInt();
                if (futures_.TryGetValue(request_id, out tuple))
                {
                    SettableFuture <HttpQueryResponse> future = tuple.Item2;
                    switch (packet.Message.Type)
                    {
                    case (int)MessageType.kQueryResponseMessage:
                        future.Set(GetQueryResponse(packet.Message), false);
                        break;

                    case (int)NodeMessageType.kNodeError:
                        future.Set(GetError(packet.Message), false);
                        break;
                    }
                    tuple.Item1(tuple.Item2);
                    futures_.Remove(request_id_);
                }
            } catch (System.Exception exception) {
                logger_.Error(
                    string.Format(StringResources.Log_MethodThrowsException,
                                  "ProcessResponse", kClassName), exception);
            }
        }
コード例 #6
0
        public void TestGetResult_WhenException()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            Assert.AreEqual("done", future.GetResult(100));
        }
コード例 #7
0
        public void TestGetResult_WhenException()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            Assert.AreEqual("done", future.GetResult(100));
        }
コード例 #8
0
        public void TestSetResult_WhenExceptionSet()
        {
            var future = new SettableFuture <string>();

            future.Exception = new Exception();
            future.Result    = "done";
        }
コード例 #9
0
        public void TestSetException_WhenExceptionSet()
        {
            var future = new SettableFuture <string>();

            future.Exception = new Exception();
            future.Exception = new Exception();
        }
コード例 #10
0
        public void TestSetResult_WhenResultSet()
        {
            var future = new SettableFuture <string>();

            future.Result = "done";
            future.Result = "done";
        }
コード例 #11
0
ファイル: RMAppMoveEvent.cs プロジェクト: orf53975/hadoop.net
 public RMAppMoveEvent(ApplicationId id, string newQueue, SettableFuture <object> resultFuture
                       )
     : base(id, RMAppEventType.Move)
 {
     this.targetQueue = newQueue;
     this.result      = resultFuture;
 }
コード例 #12
0
        public void TestGetResult()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.AreEqual("done", future.GetResult(100));
        }
コード例 #13
0
        public void TestGetResult()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.AreEqual("done", future.GetResult(100));
        }
コード例 #14
0
        public IFuture <HttpQueryResponse> ProcessQuery(string name,
                                                        IDictionary <string, string> options, AsyncCallback callback, object state)
        {
            QueryRequestMessage request = new QueryRequestMessage.Builder()
                                          .SetName(name)
                                          .AddRangeOptions(GetQueryOptions(options))
                                          .Build();

            RubyMessagePacket packet = GetMessagePacket(GetNextRequestId(),
                                                        request.ToByteString());

            try {
                QueryFuture future = new SettableFuture <HttpQueryResponse>(state);
                Tuple <AsyncCallback, QueryFuture> tuple = Tuple.Create(callback, future);
                futures_.Add(request_id_, tuple);

                // Send the request and wait for the response. The request should
                // follow the REQ/REP pattern, which contains the following parts:
                //   1. [EMPTY FRAME]
                //   2. [MESSAGE]
                //
                socket_.SendMore();
                socket_.Send(packet.ToByteArray());
                return(future);
            } catch (ZMQ.Exception zmqe) {
                return
                    (Futures.ImmediateFuture(
                         GetExceptionResponse(name, HttpStatusCode.InternalServerError, zmqe)));
            } catch (System.Exception e) {
                return
                    (Futures.ImmediateFuture(
                         GetExceptionResponse(name, HttpStatusCode.InternalServerError, e)));
            }
        }
コード例 #15
0
        public void TestResult_WhenException()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));

            var result = future.Result;
        }
コード例 #16
0
        public void TestSetException()
        {
            var future = new SettableFuture<string>();
            var exception = new Exception();
            Task.Factory.StartNew(() => future.Exception = exception);

            Assert.AreEqual(exception, future.Exception);
        }
コード例 #17
0
 public void TestSetException_WhenExceptionSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var future       = new SettableFuture <string>();
         future.Exception = new Exception();
         future.Exception = new Exception();
     });
 }
コード例 #18
0
        public void TestGetResult_WhenResultNotSet()
        {
            Assert.Throws <TimeoutException>(() =>
            {
                var future = new SettableFuture <string>();

                Assert.AreEqual("done", future.GetResult(100));
            });
        }
コード例 #19
0
        public void TestToTask_WhenResultIsSet()
        {
            var future = new SettableFuture <String>();
            var task   = future.ToTask();

            Task.Factory.StartNew(() => future.Result = "done");

            Assert.AreEqual("done", task.Result);
        }
コード例 #20
0
        public void TestIsComplete()
        {
            var future = new SettableFuture<String>();
            Assert.IsFalse(future.IsComplete);

            future.Result = "done";

            Assert.IsTrue(future.IsComplete);
        }
コード例 #21
0
        public void TestCompleted_checkExceptiont()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.AreEqual("done", future.Result);
            Assert.True(future.IsComplete);
            Assert.Null(future.Exception);
        }
コード例 #22
0
        public void TestSetException()
        {
            var future    = new SettableFuture <string>();
            var exception = new Exception();

            Task.Factory.StartNew(() => future.Exception = exception);

            Assert.AreEqual(exception, future.Exception);
        }
コード例 #23
0
        public void TestCompleted_checkExceptiont()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.AreEqual("done", future.Result);
            Assert.True(future.IsComplete);
            Assert.Null(future.Exception);
        }
コード例 #24
0
 public void TestSetResult_WhenResultSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var future    = new SettableFuture <string>();
         future.Result = "done";
         future.Result = "done";
     });
 }
コード例 #25
0
        public void TestIsComplete()
        {
            var future = new SettableFuture <String>();

            Assert.IsFalse(future.IsComplete);

            future.Result = "done";

            Assert.IsTrue(future.IsComplete);
        }
コード例 #26
0
        public void TestResult_WhenException_withContinue()
        {
            var future = new SettableFuture <string>();

            future.ToTask().ContinueWith(t => { Assert.NotNull(t.Exception); });
            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            try
            {
                var result = future.Result;
            }
            catch (Exception e)
            {
                Assert.NotNull(e);
                Assert.NotNull(future.Exception);
            }
        }
コード例 #27
0
        public void TestToTask_WhenExceptionIsSet()
        {
            var future = new SettableFuture <String>();
            var task   = future.ToTask();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));

            try
            {
                var result = task.Result;
            }
            catch (AggregateException e)
            {
                throw e.InnerExceptions.First();
            }
        }
コード例 #28
0
        public void TestCompleted_checkResult()
        {
            var future = new SettableFuture <string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            try
            {
                future.GetResult(100);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Failed", e.Message);
            }

            Assert.NotNull(future.Exception);
            Assert.True(future.IsComplete);
        }
コード例 #29
0
        public void TestCompleted_checkResult()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            try
            {
                future.GetResult(100);
            }
            catch (Exception e)
            {
                Assert.AreEqual("Failed", e.Message);
            }

            Assert.NotNull(future.Exception);
            Assert.True(future.IsComplete);
        }
コード例 #30
0
        public void AddMessage(ProducerMessage message, SettableFuture<SendResult> future)
        {
            Validate(message);
            message.SequenceNo = msgCounter.AtomicIncrementAndGet();
            if (message.IsPriority)
            {
                messages.TryAdd(0, new List<ProducerMessage>());
                messages[0].Add(message);
            }
            else
            {
                messages.TryAdd(1, new List<ProducerMessage>());
                messages[1].Add(message);
            }

            futures[message.SequenceNo] = future;
        }
コード例 #31
0
        public virtual void TestWriteEditsOneSlow()
        {
            EditLogOutputStream stm = CreateLogSegment();

            QJMTestUtil.WriteOp(stm, 1);
            stm.SetReadyToFlush();
            // Make the first two logs respond immediately
            FutureReturns(null).When(spyLoggers[0]).SendEdits(Matchers.AnyLong(), Matchers.Eq
                                                                  (1L), Matchers.Eq(1), Org.Mockito.Mockito.Any <byte[]>());
            FutureReturns(null).When(spyLoggers[1]).SendEdits(Matchers.AnyLong(), Matchers.Eq
                                                                  (1L), Matchers.Eq(1), Org.Mockito.Mockito.Any <byte[]>());
            // And the third log not respond
            SettableFuture <Void> slowLog = SettableFuture.Create();

            Org.Mockito.Mockito.DoReturn(slowLog).When(spyLoggers[2]).SendEdits(Matchers.AnyLong
                                                                                    (), Matchers.Eq(1L), Matchers.Eq(1), Org.Mockito.Mockito.Any <byte[]>());
            stm.Flush();
            Org.Mockito.Mockito.Verify(spyLoggers[0]).SetCommittedTxId(1L);
        }
コード例 #32
0
 public ClientInvocation(IClientMessage message)
 {
     _message = message;
     _future = new SettableFuture<IClientMessage>();
     _invocationTimeMillis = Clock.CurrentTimeMillis();
 }
コード例 #33
0
        public void TestToTask_WhenExceptionIsSet()
        {
            var future = new SettableFuture<String>();
            var task = future.ToTask();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));

            try
            {
                var result = task.Result;
            }
            catch (AggregateException e)
            {
                throw e.InnerExceptions.First();
            }
        }
コード例 #34
0
 public ClientInvocation(IClientMessage message)
 {
     _message = message;
     _future = new SettableFuture<IClientMessage>();
 }
コード例 #35
0
ファイル: TestQuorumCall.cs プロジェクト: orf53975/hadoop.net
        /// <exception cref="System.Exception"/>
        public virtual void TestQuorums()
        {
            IDictionary <string, SettableFuture <string> > futures = ImmutableMap.Of("f1", SettableFuture
                                                                                     .Create <string>(), "f2", SettableFuture.Create <string>(), "f3", SettableFuture.Create
                                                                                     <string>());
            QuorumCall <string, string> q = QuorumCall.Create(futures);

            NUnit.Framework.Assert.AreEqual(0, q.CountResponses());
            futures["f1"].Set("first future");
            q.WaitFor(1, 0, 0, 100000, "test");
            // wait for 1 response
            q.WaitFor(0, 1, 0, 100000, "test");
            // wait for 1 success
            NUnit.Framework.Assert.AreEqual(1, q.CountResponses());
            futures["f2"].SetException(new Exception("error"));
            NUnit.Framework.Assert.AreEqual(2, q.CountResponses());
            futures["f3"].Set("second future");
            q.WaitFor(3, 0, 100, 100000, "test");
            // wait for 3 responses
            q.WaitFor(0, 2, 100, 100000, "test");
            // 2 successes
            NUnit.Framework.Assert.AreEqual(3, q.CountResponses());
            NUnit.Framework.Assert.AreEqual("f1=first future,f3=second future", Joiner.On(","
                                                                                          ).WithKeyValueSeparator("=").Join(new SortedDictionary <string, string>(q.GetResults
                                                                                                                                                                      ())));
            try
            {
                q.WaitFor(0, 4, 100, 10, "test");
                NUnit.Framework.Assert.Fail("Didn't time out waiting for more responses than came back"
                                            );
            }
            catch (TimeoutException)
            {
            }
        }
コード例 #36
0
 public void TestResult_WhenException_withContinue()
 {
     var future = new SettableFuture<string>();
     future.ToTask().ContinueWith(t =>
     {
         Assert.NotNull(t.Exception);
     });
     Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
     try
     {
         var result = future.Result;
     }
     catch (Exception e)
     {
         Assert.NotNull(e);
         Assert.NotNull(future.Exception);
     }
 }
コード例 #37
0
        public void TestGetResult_WhenResultNotSet()
        {
            var future = new SettableFuture <string>();

            Assert.AreEqual("done", future.GetResult(100));
        }
コード例 #38
0
 public void TestSetResult_WhenExceptionSet()
 {
     var future = new SettableFuture<string>();
     future.Exception = new Exception();
     future.Result = "done";
 }
コード例 #39
0
 public void setFuture(SettableFuture<PullMessageResultCommandV2> future)
 {
     m_future = future;
 }
コード例 #40
0
        public void TestToTask_WhenResultIsSet()
        {
            var future = new SettableFuture<String>();
            var task = future.ToTask();

            Task.Factory.StartNew(() => future.Result = "done");

            Assert.AreEqual("done", task.Result);
        }
コード例 #41
0
 public void TestSetResult_WhenResultSet()
 {
     var future = new SettableFuture<string>();
     future.Result = "done";
     future.Result = "done";
 }
コード例 #42
0
        public void TestWait_WhenResultNotSet()
        {
            var future = new SettableFuture <string>();

            Assert.IsFalse(future.Wait(100));
        }
コード例 #43
0
        public void TestWait()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.IsTrue(future.Wait());
        }
コード例 #44
0
 public void TestSetException_WhenExceptionSet()
 {
     var future = new SettableFuture<string>();
     future.Exception = new Exception();
     future.Exception = new Exception();
 }
コード例 #45
0
        public void TestWait_WhenResultNotSet()
        {
            var future = new SettableFuture<string>();

            Assert.IsFalse(future.Wait(100));
        }
コード例 #46
0
        public void TestGetResult_WhenResultNotSet()
        {
            var future = new SettableFuture<string>();

            Assert.AreEqual("done", future.GetResult(100));
        }