/// <summary> /// Notifies the cache about a watcher event. /// </summary> /// <param name="rc">The result code.</param> /// <param name="onChange">The watcher event.</param> /// <param name="cachePrefix">The cache prefix to use.</param> /// <returns><c>true</c> if the caller needs to restart the watcher, <c>false</c> otherwise.</returns> public bool NotifyWatcherEvent(RingMasterException.Code rc, WatchedEvent onChange, string cachePrefix) { if (onChange == null) { return(false); } if (onChange.EventType == WatchedEvent.WatchedEventType.WatcherRemoved) { this.Wipe(cachePrefix); return(true); } if (onChange.KeeperState == WatchedEvent.WatchedEventKeeperState.SyncConnected) { if (onChange.EventType == WatchedEvent.WatchedEventType.NodeCreated || onChange.EventType == WatchedEvent.WatchedEventType.NodeDeleted) { this.Invalidate(cachePrefix, PrefixedClientCache.GetParent(onChange.Path)); } this.Invalidate(cachePrefix, onChange.Path); } return(false); }
/// <summary> /// Notifies the request task completion source that the task failed with the given <paramref name="code"/> /// </summary> /// <param name="request">Request to notify of the failure</param> /// <param name="code">The failure code to notify</param> private void NotifyRequestFailed(RequestWrapper request, RingMasterException.Code code) { var response = new RequestResponse() { ResultCode = (int)code, }; this.ProcessRequestResponse(request.CallId, request, response); }
/// <summary> /// Verify that the given task throws an exception of type T. /// </summary> /// <param name "expectedCode">Expected RingMasterException error code</param> /// <param name="task">Task that is expected to throw the exception</param> /// <param name="message">Error message to show if the task did not throw the exception</param> /// <returns>A <see cref="Task"/> that tracks execution of this function</returns> internal static async Task VerifyRingMasterException(RingMasterException.Code expectedCode, Func <Task> task, string message) { try { await task(); } catch (RingMasterException ex) { Assert.AreEqual(expectedCode, ex.ErrorCode); return; } Assert.Fail(message); }
/// <summary> /// Gets the error code of the first failed operation or Ok if all operations have succeeded. /// </summary> /// <param name="results">Results list from which the error code of the first failed operation must be retrieved</param> /// <returns>Error code of the first failed operation or Ok</returns> private static RingMasterException.Code GetFirstError(IEnumerable <OpResult> results) { RingMasterException.Code c = RingMasterException.Code.Ok; foreach (OpResult r in results) { if (c != RingMasterException.Code.Ok) { c = r.ErrCode; break; } } return(c); }
/// <summary> /// Initializes a new instance of the <see cref="OpResult"/> class. /// </summary> /// <param name="resultType">The type of <see cref="Op"/> that is associated with this result</param> /// <param name="errorCode">Error code of the result</param> protected internal OpResult(OpCode resultType, RingMasterException.Code errorCode = RingMasterException.Code.Ok) { this.ResultType = resultType; this.ErrCode = errorCode; }