Represents the collection of result information for a Riak operation that has no specific return value.
コード例 #1
0
        internal static new RiakResult <TResult> FromException(ResultCode code, Exception exception, bool nodeOffline)
        {
            var riakResult = new RiakResult <TResult>(exception, code);

            riakResult.NodeOffline = nodeOffline;
            return(riakResult);
        }
コード例 #2
0
        public void SetUp()
        {
            var result = RiakResult.Success();
            Cluster.ConnectionMock.Setup(m => m.PbcWriteRead(It.IsAny<RpbSetBucketReq>(), MessageCode.RpbSetBucketResp)).Returns(result);

            Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true));
        }
コード例 #3
0
        internal static RiakResult FromException(ResultCode code, Exception ex, bool nodeOffline)
        {
            var riakResult = new RiakResult(code, ex);

            riakResult.NodeOffline = nodeOffline;
            return(riakResult);
        }
コード例 #4
0
        internal static new RiakResult <TResult> FromError(ResultCode code, string message, bool nodeOffline)
        {
            var riakResult = new RiakResult <TResult>(default(TResult), false, message, code);

            riakResult.NodeOffline = nodeOffline;
            return(riakResult);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: vixletadmin/taste-of-riak
 private static void CheckResult(RiakResult<RiakObject> result)
 {
     if (!result.IsSuccess)
     {
         Console.Error.WriteLine("Error: {0}", result.ErrorMessage);
         Environment.Exit(1);
     }
 }
コード例 #6
0
        public static bool OnePhaseWith_M_ResultsFound(RiakResult<RiakMapReduceResult> result, int numResults)
        {
            if (!result.IsSuccess || result.Value == null)
            {
                return false;
            }

            var phaseResults = result.Value.PhaseResults.ToList();

            if (phaseResults.Count != 1)
            {
                return false;
            }

            var phase1Results = phaseResults[0].Values;

            return phase1Results.Count == numResults;
        }
コード例 #7
0
        /// <summary>
        /// Executes a delegate function using a <see cref="IRiakConnection"/>, and returns the results.
        /// Can retry up to "<paramref name="retryAttempts"/>" times for <see cref="ResultCode.NoRetries"/> and <see cref="ResultCode.ShuttingDown"/> error states.
        /// This method is used over <see cref="RiakEndPoint.UseConnection"/> to keep a connection open to receive streaming results.
        /// </summary>
        /// <typeparam name="TResult">The type of the result from the <paramref name="useFun"/> parameter.</typeparam>
        /// <param name="useFun">
        /// The delegate function to execute. Takes an <see cref="IRiakConnection"/> and an <see cref="Action"/> continuation as input, and returns a
        /// <see cref="RiakResult{T}"/> containing an <see cref="IEnumerable{TResult}"/> as the results of the operation.
        /// </param>
        /// <param name="retryAttempts">The number of times to retry an operation.</param>
        /// <returns>The results of the <paramref name="useFun"/> delegate.</returns>
        public override RiakResult <IEnumerable <TResult> > UseDelayedConnection <TResult>(Func <IRiakConnection, Action, RiakResult <IEnumerable <TResult> > > useFun, int retryAttempts)
        {
            if (retryAttempts < 0)
            {
                return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.NoRetries, "Unable to access a connection on the cluster (no more retries).", false));
            }

            if (disposing)
            {
                return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.ShuttingDown, "System currently shutting down", true));
            }

            var errorMessages = new List <string>();
            var node          = loadBalancer.SelectNode();

            if (node != null)
            {
                var result = node.UseDelayedConnection(useFun);
                if (!result.IsSuccess)
                {
                    errorMessages.Add(result.ErrorMessage);

                    if (result.ResultCode == ResultCode.NoConnections)
                    {
                        Thread.Sleep(RetryWaitTime);
                        return(UseDelayedConnection(useFun, retryAttempts - 1));
                    }

                    if (result.ResultCode == ResultCode.CommunicationError)
                    {
                        MaybeDeactivateNode(result.NodeOffline, node);
                        Thread.Sleep(RetryWaitTime);
                        return(UseDelayedConnection(useFun, retryAttempts - 1));
                    }
                }

                return(result);
            }

            string msg = string.Format("Unable to access functioning Riak node, error(s): {0}", string.Join(", ", errorMessages));

            return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.ClusterOffline, msg, true));
        }
コード例 #8
0
        /// <summary>
        /// Executes a delegate function using a <see cref="IRiakConnection"/>, and returns the results.
        /// Can retry up to "<paramref name="retryAttempts"/>" times for <see cref="ResultCode.NoRetries"/> and <see cref="ResultCode.ShuttingDown"/> error states.
        /// This method is used over <see cref="RiakEndPoint.UseConnection"/> to keep a connection open to receive streaming results.
        /// </summary>
        /// <typeparam name="TResult">The type of the result from the <paramref name="useFun"/> parameter.</typeparam>
        /// <param name="useFun">
        /// The delegate function to execute. Takes an <see cref="IRiakConnection"/> and an <see cref="Action"/> continuation as input, and returns a
        /// <see cref="RiakResult{T}"/> containing an <see cref="IEnumerable{TResult}"/> as the results of the operation.
        /// </param>
        /// <param name="retryAttempts">The number of times to retry an operation.</param>
        /// <returns>The results of the <paramref name="useFun"/> delegate.</returns>
        public override RiakResult <IEnumerable <TResult> > UseDelayedConnection <TResult>(Func <IRiakConnection, Action, RiakResult <IEnumerable <TResult> > > useFun, int retryAttempts)
        {
            if (retryAttempts < 0)
            {
                return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.NoRetries, "Unable to access a connection on the cluster.", false));
            }

            if (disposing)
            {
                return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.ShuttingDown, "System currently shutting down", true));
            }

            var node = loadBalancer.SelectNode();

            if (node != null)
            {
                var result = node.UseDelayedConnection(useFun);
                if (!result.IsSuccess)
                {
                    if (result.ResultCode == ResultCode.NoConnections)
                    {
                        Thread.Sleep(RetryWaitTime);
                        return(UseDelayedConnection(useFun, retryAttempts - 1));
                    }

                    if (result.ResultCode == ResultCode.CommunicationError)
                    {
                        if (result.NodeOffline)
                        {
                            DeactivateNode(node);
                        }

                        Thread.Sleep(RetryWaitTime);
                        return(UseDelayedConnection(useFun, retryAttempts - 1));
                    }
                }

                return(result);
            }

            return(RiakResult <IEnumerable <TResult> > .FromError(ResultCode.ClusterOffline, "Unable to access functioning Riak node", true));
        }
コード例 #9
0
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        /// <param name="other">The object to compare with the current object.</param>
        /// <returns><b>true</b> if the specified object is equal to the current object, otherwise, <b>false</b>.</returns>
        public bool Equals(RiakResult <TResult> other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Equals(other.Value, Value) &&
                   Equals(other.IsSuccess, IsSuccess) &&
                   Equals(other.ResultCode, ResultCode) &&
                   Equals(other.NodeOffline, NodeOffline) &&
                   Equals(other.Continuation, Continuation) &&
                   (other.Done.HasValue &&
                    Done.HasValue &&
                    Equals(other.Done.Value && Done.Value)));
        }
        private static void CheckThatResultContainAllKeys(RiakResult<RiakMapReduceResult> result)
        {
            var phaseResults = result.Value.PhaseResults.ToList();
            phaseResults.Count.ShouldEqual(1);

            var searchResults = phaseResults[0];
            searchResults.Values.ShouldNotBeNull();
            searchResults.Values.Count.ShouldEqual(2);

            foreach (var searchResult in searchResults.Values)
            {
                var s = searchResult.FromRiakString();
                if (!(s.Contains(RiakSearchKey) || s.Contains(RiakSearchKey2)))
                    Assert.Fail("Results did not contain either \"{0}\" or \"{1}\". \r\nResult was:\"{2}\"", RiakSearchKey,
                        RiakSearchKey2, s);
            }
        }
コード例 #11
0
 public RiakResult(RiakResult result)
     : base(result.IsSuccess, result.ResultCode, result.Exception, result.ErrorMessage)
 {
     this.value = default(TResult);
 }
コード例 #12
0
 internal static RiakResult FromError(ResultCode code, string message, bool nodeOffline)
 {
     var riakResult = new RiakResult(false, message, code);
     riakResult.NodeOffline = nodeOffline;
     return riakResult;
 }
コード例 #13
0
 public static bool OnePhaseWithTwelveResultsFound(RiakResult<RiakMapReduceResult> result)
 {
     return OnePhaseWith_M_ResultsFound(result, 12);
 }
コード例 #14
0
 internal static RiakResult FromException(ResultCode code, Exception ex, bool nodeOffline)
 {
     var riakResult = new RiakResult(code, ex);
     riakResult.NodeOffline = nodeOffline;
     return riakResult;
 }
コード例 #15
0
        private static void AssertThatResultContainsAllKeys(RiakResult<RiakMapReduceResult> mapReduceResult)
        {
            var phaseResults = mapReduceResult.Value.PhaseResults.ToList();
            phaseResults.Count.ShouldEqual(1);

            var searchResults = phaseResults[0];
            searchResults.Values.ShouldNotBeNull();
            searchResults.Values.Count.ShouldEqual(2);

            var allKeys = new List<string> { HackerKey, PublicKey };
            var solrResults = searchResults.Values.Select(searchResult => searchResult.FromRiakString());

            var usedKeys = solrResults.SelectMany(result => allKeys.Where(result.Contains));
            var unusedKeys = allKeys.Except(usedKeys).ToList();

            Assert.AreEqual(0, unusedKeys.Count, "Results did not contain the following keys: {0}",
                string.Join(", ", allKeys));
        }
コード例 #16
0
 protected void CheckResult(RiakResult riakResult, bool errorIsOK = false)
 {
     if (errorIsOK && !riakResult.IsSuccess)
     {
         Console.WriteLine("Error: {0}", riakResult.ErrorMessage);
     }
     else
     {
         Assert.IsTrue(riakResult.IsSuccess, "Error: {0}", riakResult.ErrorMessage);
     }
 }
コード例 #17
0
 public RiakResult(RiakResult result)
     : base(result.IsSuccess, result.ResultCode, result.Exception, result.ErrorMessage, result.NodeOffline)
 {
     value = default(TResult);
 }