public void TestWait()
        {
            var future = new SettableFuture <string>();

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

            var result = future.Result;
        }
    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));
      }
    }
 /// <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));
         }
     }
 }
Esempio n. 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);
            }
        }
        public void TestGetResult_WhenException()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Exception = new Exception("Failed"));
            Assert.AreEqual("done", future.GetResult(100));
        }
Esempio n. 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));
        }
Esempio n. 8
0
        public void TestSetResult_WhenExceptionSet()
        {
            var future = new SettableFuture <string>();

            future.Exception = new Exception();
            future.Result    = "done";
        }
Esempio n. 9
0
        public void TestSetException_WhenExceptionSet()
        {
            var future = new SettableFuture <string>();

            future.Exception = new Exception();
            future.Exception = new Exception();
        }
Esempio n. 10
0
        public void TestSetResult_WhenResultSet()
        {
            var future = new SettableFuture <string>();

            future.Result = "done";
            future.Result = "done";
        }
Esempio n. 11
0
 public RMAppMoveEvent(ApplicationId id, string newQueue, SettableFuture <object> resultFuture
                       )
     : base(id, RMAppEventType.Move)
 {
     this.targetQueue = newQueue;
     this.result      = resultFuture;
 }
        public void TestGetResult()
        {
            var future = new SettableFuture <string>();

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

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.AreEqual("done", future.GetResult(100));
        }
Esempio n. 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)));
            }
        }
Esempio n. 15
0
        public void TestResult_WhenException()
        {
            var future = new SettableFuture <string>();

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

            var result = future.Result;
        }
        public void TestSetException()
        {
            var future = new SettableFuture<string>();
            var exception = new Exception();
            Task.Factory.StartNew(() => future.Exception = exception);

            Assert.AreEqual(exception, future.Exception);
        }
 public void TestSetException_WhenExceptionSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var future       = new SettableFuture <string>();
         future.Exception = new Exception();
         future.Exception = new Exception();
     });
 }
        public void TestGetResult_WhenResultNotSet()
        {
            Assert.Throws <TimeoutException>(() =>
            {
                var future = new SettableFuture <string>();

                Assert.AreEqual("done", future.GetResult(100));
            });
        }
        public void TestToTask_WhenResultIsSet()
        {
            var future = new SettableFuture <String>();
            var task   = future.ToTask();

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

            Assert.AreEqual("done", task.Result);
        }
        public void TestIsComplete()
        {
            var future = new SettableFuture<String>();
            Assert.IsFalse(future.IsComplete);

            future.Result = "done";

            Assert.IsTrue(future.IsComplete);
        }
        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);
        }
        public void TestSetException()
        {
            var future    = new SettableFuture <string>();
            var exception = new Exception();

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

            Assert.AreEqual(exception, future.Exception);
        }
        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);
        }
 public void TestSetResult_WhenResultSet()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var future    = new SettableFuture <string>();
         future.Result = "done";
         future.Result = "done";
     });
 }
        public void TestIsComplete()
        {
            var future = new SettableFuture <String>();

            Assert.IsFalse(future.IsComplete);

            future.Result = "done";

            Assert.IsTrue(future.IsComplete);
        }
        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);
            }
        }
Esempio n. 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();
            }
        }
        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);
        }
        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);
        }
        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;
        }
        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);
        }
 public ClientInvocation(IClientMessage message)
 {
     _message = message;
     _future = new SettableFuture<IClientMessage>();
     _invocationTimeMillis = Clock.CurrentTimeMillis();
 }
        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();
            }
        }
 public ClientInvocation(IClientMessage message)
 {
     _message = message;
     _future = new SettableFuture<IClientMessage>();
 }
Esempio n. 35
0
        /// <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)
            {
            }
        }
 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);
     }
 }
Esempio n. 37
0
        public void TestGetResult_WhenResultNotSet()
        {
            var future = new SettableFuture <string>();

            Assert.AreEqual("done", future.GetResult(100));
        }
 public void TestSetResult_WhenExceptionSet()
 {
     var future = new SettableFuture<string>();
     future.Exception = new Exception();
     future.Result = "done";
 }
 public void setFuture(SettableFuture<PullMessageResultCommandV2> future)
 {
     m_future = future;
 }
        public void TestToTask_WhenResultIsSet()
        {
            var future = new SettableFuture<String>();
            var task = future.ToTask();

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

            Assert.AreEqual("done", task.Result);
        }
 public void TestSetResult_WhenResultSet()
 {
     var future = new SettableFuture<string>();
     future.Result = "done";
     future.Result = "done";
 }
        public void TestWait_WhenResultNotSet()
        {
            var future = new SettableFuture <string>();

            Assert.IsFalse(future.Wait(100));
        }
        public void TestWait()
        {
            var future = new SettableFuture<string>();

            Task.Factory.StartNew(() => future.Result = "done");
            Assert.IsTrue(future.Wait());
        }
 public void TestSetException_WhenExceptionSet()
 {
     var future = new SettableFuture<string>();
     future.Exception = new Exception();
     future.Exception = new Exception();
 }
        public void TestWait_WhenResultNotSet()
        {
            var future = new SettableFuture<string>();

            Assert.IsFalse(future.Wait(100));
        }
        public void TestGetResult_WhenResultNotSet()
        {
            var future = new SettableFuture<string>();

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