public void Converting_Failure_to_option_returns_none() { var t = new Failure<string>(new Exception()); var o = t.ToOption(); Assert.IsFalse(o.IsDefined); Assert.AreSame(Option<string>.None, o); }
public void FailureBehaviourTest() { Result<int, Exception> res = new Failure<int, Exception>(new ArgumentException("yay")); Assert.False(res.IsSuccess); Assert.True(res.IsFailure); Assert.Equal(new None<int>(), res.ToOption()); }
public Job(Map map, Reduce reduce, Failure failure, string logName) { _map = map; _reduce = reduce; _failure = failure; LOGNAME = logName; }
public void Can_create_Failure() { var t = new Failure<string>(new Exception("fail")); Assert.IsFalse(t.IsSuccess); Assert.IsTrue(t.IsFailure); Assert.AreEqual("fail", t.Exception.Message); }
public FailureDescriptor(Failure failure, FailureGarbage failureGarbage, int weight, string partInformation, string name) { this.failure = failure; this.failureGarbage = failureGarbage; this.weight = weight; this.partInformation = partInformation; this.name = name; }
public override void TestFailure(Failure failure) { if (Scope == LifecycleScope.TEST) { TestFailed = true; } else { SuiteFailed = true; } PrintDiagnosticsAfterClass = true; }
void Failure_Throws() { Failure<string> fail = new Failure<string>(new TestException()); Assert.Throws<TestException>(() => fail.GetOrThrow()); Assert.IsType<TestException>(fail.Exception); Assert.Equal("TestException :)", fail.Convert((s) => "success? " + s, (e) => "TestException :)")); Try<string> thend = fail.Then((succ) => succ); Assert.Throws<TestException>(() => thend.GetOrThrow()); Assert.Equal("Fail", thend.Convert((s) => "succeeded", (e) => "Fail")); Try<string> successThen = fail.Then((succ) => "S", (e) => "F"); Assert.Equal("F", successThen.GetOrThrow()); Assert.IsType<Success<string>>(successThen); Try<string> kindaFail = fail.Then((succ) => "S", (e) => { throw new TestException2(); }); Assert.Throws<TestException2>(() => kindaFail.GetOrThrow()); }
public static FPSListDataValidationException ThrowSPListDataValidationException(SPFailure[] fieldFailures, SPFailure itemFailure) { var failture = new Failure() { spldvFieldFailures = fieldFailures, spldvItemFailure = itemFailure }; var serializationInfo = new SerializationInfo(failture.GetType(), new FormatterConverter()); serializationInfo.AddValue("spldvFieldFailures", fieldFailures); serializationInfo.AddValue("spldvItemFailure", 1); serializationInfo.AddValue("ClassName", string.Empty); serializationInfo.AddValue("Message", string.Empty); serializationInfo.AddValue("InnerException", new ArgumentException()); serializationInfo.AddValue("HelpURL", string.Empty); serializationInfo.AddValue("StackTraceString", string.Empty); serializationInfo.AddValue("RemoteStackTraceString", string.Empty); serializationInfo.AddValue("RemoteStackIndex", 0); serializationInfo.AddValue("ExceptionMethod", string.Empty); serializationInfo.AddValue("HResult", 1); serializationInfo.AddValue("Source", string.Empty); serializationInfo.AddValue("nativeErrorMessage", string.Empty); serializationInfo.AddValue("nativeStackTrace", string.Empty); return new FPSListDataValidationException(serializationInfo, new StreamingContext()); }
public FailureWhenSendingNotificationDocumentUpdatedEvent(Guid correlationId, User user, Failure <DocumentDto> payload) : base(correlationId, user, payload) { }
public void InitFSM() { StartWith(State.Connecting, new Data(null, null)); When(State.Connecting, @event => { if (@event.FsmEvent is IClientOp) { return(Stay().Replying(new Status.Failure(new IllegalStateException("not connected yet")))); } var connected = @event.FsmEvent as Connected; if (connected != null) { connected.Channel.Write(new Hello(_name.Name, TestConductor.Get(Context.System).Address)); return(GoTo(State.AwaitDone).Using(new Data(connected.Channel, null))); } if (@event.FsmEvent is ConnectionFailure) { return(GoTo(State.Failed)); } if (@event.FsmEvent is StateTimeout) { _log.Error("connect timeout to TestConductor"); return(GoTo(State.Failed)); } return(null); }, _settings.ConnectTimeout); When(State.AwaitDone, @event => { if (@event.FsmEvent is Done) { _log.Debug("received Done: starting test"); return(GoTo(State.Connected)); } if (@event.FsmEvent is INetworkOp) { _log.Error("Received {0} instead of Done", @event.FsmEvent); return(GoTo(State.Failed)); } if (@event.FsmEvent is IServerOp) { return(Stay().Replying(new Failure(new IllegalStateException("not connected yet")))); } if (@event.FsmEvent is StateTimeout) { _log.Error("connect timeout to TestConductor"); return(GoTo(State.Failed)); } return(null); }, _settings.BarrierTimeout); When(State.Connected, @event => { if (@event.FsmEvent is Disconnected) { _log.Info("disconnected from TestConductor"); throw new ConnectionFailure("disconnect"); } if (@event.FsmEvent is ToServer <Done> && @event.StateData.Channel != null && @event.StateData.RunningOp == null) { @event.StateData.Channel.Write(Done.Instance); return(Stay()); } var toServer = @event.FsmEvent as IToServer; if (toServer != null && @event.StateData.Channel != null && @event.StateData.RunningOp == null) { @event.StateData.Channel.Write(toServer.Msg); string token = null; var enterBarrier = @event.FsmEvent as ToServer <EnterBarrier>; if (enterBarrier != null) { token = enterBarrier.Msg.Name; } else { var getAddress = @event.FsmEvent as ToServer <GetAddress>; if (getAddress != null) { token = getAddress.Msg.Node.Name; } } return(Stay().Using(@event.StateData.Copy(runningOp: Tuple.Create(token, Sender)))); } if (toServer != null && @event.StateData.Channel != null && @event.StateData.RunningOp != null) { _log.Error("cannot write {0} while waiting for {1}", toServer.Msg, @event.StateData.RunningOp); return(Stay()); } if (@event.FsmEvent is IClientOp && @event.StateData.Channel != null) { var barrierResult = @event.FsmEvent as BarrierResult; if (barrierResult != null) { if (@event.StateData.RunningOp == null) { _log.Warning("did not expect {1}", @event.FsmEvent); } else { object response; if (barrierResult.Name != @event.StateData.RunningOp.Item1) { response = new Failure( new Exception("wrong barrier " + barrierResult + " received while waiting for " + @event.StateData.RunningOp.Item1)); } else if (!barrierResult.Success) { response = new Failure( new Exception("barrier failed:" + @event.StateData.RunningOp.Item1)); } else { response = barrierResult.Name; } @event.StateData.RunningOp.Item2.Tell(response); } return(Stay().Using(@event.StateData.Copy(runningOp: null))); } var addressReply = @event.FsmEvent as AddressReply; if (addressReply != null) { if (@event.StateData.RunningOp == null) { _log.Warning("did not expect {0}", @event.FsmEvent); } else { @event.StateData.RunningOp.Item2.Tell(addressReply.Addr); } return(Stay().Using(@event.StateData.Copy(runningOp: null))); } var throttleMsg = @event.FsmEvent as ThrottleMsg; if (@event.FsmEvent is ThrottleMsg) { ThrottleMode mode; if (throttleMsg.RateMBit < 0.0f) { mode = Unthrottled.Instance; } else if (throttleMsg.RateMBit < 0.0f) { mode = Blackhole.Instance; } else { mode = new TokenBucket(1000, throttleMsg.RateMBit * 125000, 0, 0); } var cmdTask = TestConductor.Get(Context.System) .Transport.ManagementCommand(new SetThrottle(throttleMsg.Target, throttleMsg.Direction, mode)); cmdTask.ContinueWith(t => { if (t.IsFaulted) { throw new Exception("Throttle was requested from the TestConductor, but no transport " + "adapters available that support throttling. Specify 'testTransport(on=true)' in your MultiNodeConfig"); } Self.Tell(new ToServer <Done>(Done.Instance)); }); return(Stay()); } if (@event.FsmEvent is DisconnectMsg) { return(Stay()); //FIXME is this the right EC for the future below? } // FIXME: Currently ignoring, needs support from Remoting var terminateMsg = @event.FsmEvent as TerminateMsg; if (terminateMsg != null) { if (terminateMsg.ShutdownOrExit.IsLeft && terminateMsg.ShutdownOrExit.ToLeft().Value == false) { Context.System.Shutdown(); return(Stay()); } if (terminateMsg.ShutdownOrExit.IsLeft && terminateMsg.ShutdownOrExit.ToLeft().Value == true) { //TODO: terminate more aggressively with Abort //Context.System.AsInstanceOf<ActorSystemImpl>().Abort(); Context.System.Shutdown(); return(Stay()); } if (terminateMsg.ShutdownOrExit.IsRight) { Environment.Exit(terminateMsg.ShutdownOrExit.ToRight().Value); return(Stay()); } } if (@event.FsmEvent is Done) { return(Stay()); //FIXME what should happen? } } return(null); }); When(State.Failed, @event => { if (@event.FsmEvent is IClientOp) { return(Stay().Replying(new Status.Failure(new Exception("cannot do " + @event.FsmEvent + " while failed")))); } if (@event.FsmEvent is INetworkOp) { _log.Warning("ignoring network message {0} while Failed", @event.FsmEvent); return(Stay()); } return(null); }); OnTermination(@event => { if (@event.StateData.Channel != null) { @event.StateData.Channel.Close(); } }); Initialize(); }
protected override void Run() { log.Debug("Running SR.Create()"); log.DebugFormat("host='{0}'", Host.Name); log.DebugFormat("name='{0}'", _srName); log.DebugFormat("description='{0}'", _srDescription); log.DebugFormat("type='{0}'", _srType); log.DebugFormat("content type='{0}'", _srContentType); log.DebugFormat("is shared='{0}'", _srIsShared); string secretuuid = null; if (Helpers.MidnightRideOrGreater(Connection)) { string value; if (_dconf.TryGetValue("cifspassword", out value)) { secretuuid = CreateSecret("cifspassword", value); } else if (_dconf.TryGetValue("password", out value)) { secretuuid = CreateSecret("password", value); } else if (_dconf.TryGetValue("chappassword", out value)) { secretuuid = CreateSecret("chappassword", value); } } if (_srType == SR.SRTypes.cslg && !Helpers.BostonOrGreater(Connection)) { // make sure this connection is added to the storagelink service. StorageLinkConnection slCon = _SLConnection; if (slCon != null) { slCon.AddXenConnection(Connection); } } Description = Messages.ACTION_SR_CREATING; XenRef <SR> sr; try { sr = XenAPI.SR.create(Session, Host.opaque_ref, _dconf, 0, _srName, _srDescription, _srType.ToString().ToLowerInvariant(), _srContentType, _srIsShared, new Dictionary <string, string>()); Result = sr; } catch { if (!string.IsNullOrEmpty(secretuuid)) { string opaqref = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, opaqref); } throw; } finally { // Destroy secret after the SR creation is complete. This is safe // since all PBDs will have duplicated the secret (CA-113396). if (!string.IsNullOrEmpty(secretuuid) && Helpers.AugustaOrGreater(Connection)) { string opaqref = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, opaqref); } } log.Debug("Checking that SR.create() actually succeeded"); foreach (XenRef <PBD> pbdRef in XenAPI.SR.get_PBDs(Session, sr.opaque_ref)) { if (!XenAPI.PBD.get_currently_attached(Session, pbdRef)) { // The automatic plug done by the SR.create has failed to plug this PDB: // try the plug manually, and report the failure. Roll back the operation // by forgetting the SR. try { XenAPI.PBD.plug(this.Session, pbdRef); } catch (Exception exn) { if (exn is Failure) { Failure f = (Failure)exn; if (f.ErrorDescription[0] == Failure.HOST_OFFLINE || f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { log.Warn("Unable to check storage settings, due to host being down", f); } } else { log.Debug("Plug failed on a PBD: performing SR.forget"); ForgetFailedSR(sr); throw; } } } } Dictionary <string, string> other_config = new Dictionary <string, string>(); other_config.Add("auto-scan", _srContentType == XenAPI.SR.Content_Type_ISO ? "true" : "false"); XenAPI.SR.set_other_config(Session, Result, other_config); if (isFirstSharedNonISOSR()) { SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling); if (Cancelling) { throw new CancelledException(); } if (new_sr == null) { throw new Failure(Failure.HANDLE_INVALID, "SR", Result); } // Set this SR to be the default new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session); } Description = Messages.ACTION_SR_CREATE_SUCCESSFUL; }
public void OnResolutionFailed(Failure failure, Decision decision, Exception exception) { }
void ProcessAuth(MxAuth auth) { string user = null, pass = null; Failure failure = null; if (auth.SaslMechanism == SaslMechanism.PLAIN) { byte[] buffer = Convert.FromBase64String(auth.Value); string sasl = Encoding.UTF8.GetString(buffer).Trim((char)0); string[] split = sasl.Split((char)0); if (split.Length == 3) { user = split[1]; pass = split[2]; } else if (split.Length == 2) { user = split[0]; pass = split[1]; } else { failure = new Failure(FailureCondition.not_authorized); } } else { failure = new Failure(FailureCondition.invalid_mechanism); } if (failure == null) { user = JIDEscaping.Unescape(user); if (!Server.AuthManager.Auth(user, pass, pass.Length == 32)) failure = new Failure(FailureCondition.not_authorized); } if (failure == null) { Session.SetOnline(user); Session.Send(new Success()); Session.Reset(); } else Session.Send(failure, DataSentAction.Close); }
public void TestThatAFailedOutcomeIsTransformedToAnEmptyOptional() => Assert.Equal( Optional.Empty <int>(), Failure.Of <Exception, int>(RandomException()).AsOptional());
public void Where_on_Failure_returns_Failure() { var fail = new Failure<int>(new TestException()); var where = fail.Where(x => x > 10); Assert.IsTrue(where.IsFailure); Assert.IsInstanceOfType(typeof(TestException), where.Exception); }
public static ArgumentException CannotGenerateName(Type type) { return(Failure.Prepare(new ArgumentException(SR.CannotGenerateName(type)))); }
public static FormatException ContainsSelectorCannotBeEmpty() { return(Failure.Prepare(new FormatException())); }
/// <summary> /// There are no comments for FailureSet in the schema. /// </summary> public void AddToFailureSet(Failure failure) { base.AddObject("FailureSet", failure); }
/// <summary> /// Create a new Failure object. /// </summary> /// <param name="ID">Initial value of Id.</param> /// <param name="testId">Initial value of TestId.</param> /// <param name="changed">Initial value of Changed.</param> public static Failure CreateFailure(int ID, int testId, global::System.DateTimeOffset changed) { Failure failure = new Failure(); failure.Id = ID; failure.TestId = testId; failure.Changed = changed; return failure; }
public override void TestFailure(Failure failure) { Failures_Renamed.IncrementAndGet(); }
public override void TestFailure(Failure failure) { lastTest = 'F'; // failure }
public void Where_via_linq_comprehension_on_Failure_returns_empty_enumerable() { var fail = new Failure<int>(new TestException()); var where = (from x in fail where x > 10 select x); Assert.IsTrue(where.IsFailure); Assert.IsInstanceOfType(typeof(TestException), where.Exception); }
/// <summary> /// Gets all releases metrics for specified Deployment /// </summary> /// <param name='deploymentName'> /// deployment name /// </param> /// <param name='ownerName'> /// The name of the owner /// </param> /// <param name='appName'> /// The name of the application /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="FailureException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse <IList <CodePushReleaseMetric> > > GetWithHttpMessagesAsync(string deploymentName, string ownerName, string appName, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (deploymentName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "deploymentName"); } if (ownerName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "ownerName"); } if (appName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "appName"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("deploymentName", deploymentName); tracingParameters.Add("ownerName", ownerName); tracingParameters.Add("appName", appName); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v0.1/apps/{owner_name}/{app_name}/deployments/{deployment_name}/metrics").ToString(); _url = _url.Replace("{deployment_name}", System.Uri.EscapeDataString(deploymentName)); _url = _url.Replace("{owner_name}", System.Uri.EscapeDataString(ownerName)); _url = _url.Replace("{app_name}", System.Uri.EscapeDataString(appName)); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("GET"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new FailureException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); Failure _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Failure>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <IList <CodePushReleaseMetric> >(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <IList <CodePushReleaseMetric> >(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public void GetHashCode_FirstIsDefaultAndSecondCodeIsDefaultAndSecondMessageIsNullOrEmpty_ExpectHashCodesAreEqual( string?failureMessage) { var first = new Failure <int>(); var second = new Failure <int>(default, failureMessage);
/// <summary> /// Create the failure. /// </summary> /// <param name="cacheId">Id of the cache doing the transfer</param> /// <param name="destinationCacheId">Id of the cache that the file would have been moved to.</param> /// <param name="fileHash">Hash for the file</param> /// <param name="innerFailure">Failure that occurrec when transferring the file</param> /// <param name="message">Additional context information about when the failure occurred.</param> /// <param name="sourceCacheId">Id of the cache the file would have transferred from.</param> public CASTransferFailure(string cacheId, string sourceCacheId, string destinationCacheId, CasHash fileHash, string message, Failure innerFailure) : base(innerFailure) { Contract.Requires(!string.IsNullOrWhiteSpace(sourceCacheId)); Contract.Requires(!string.IsNullOrWhiteSpace(destinationCacheId)); Contract.Requires(!string.IsNullOrWhiteSpace(cacheId)); Contract.Requires(innerFailure != null); m_sourceCacheId = sourceCacheId; m_destinationCacheId = destinationCacheId; m_message = message == null ? string.Empty : message; m_fileHash = fileHash; m_cacheId = cacheId; }
/// <nodoc /> public RocksDbFailureEvent(Exception exception) { Contract.Requires(exception != null); Failure = new Failure <Exception>(exception); }
// Runs test, with multiple threads, using the specific // failure to trigger an IOException public virtual void TestMultipleThreadsFailure(Failure failure) { int NUM_THREADS = 3; for (int iter = 0; iter < 2; iter++) { if (Verbose) { Console.WriteLine("TEST: iter=" + iter); } MockDirectoryWrapper dir = NewMockDirectory(); IndexWriter writer = new IndexWriter( dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)) .SetMaxBufferedDocs(2) .SetMergeScheduler(new ConcurrentMergeScheduler()) .SetMergePolicy(NewLogMergePolicy(4))); ((IConcurrentMergeScheduler)writer.Config.MergeScheduler).SetSuppressExceptions(); IndexerThread[] threads = new IndexerThread[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; i++) { threads[i] = new IndexerThread(writer, true, NewField); } for (int i = 0; i < NUM_THREADS; i++) { threads[i].Start(); } Thread.Sleep(10); dir.FailOn(failure); failure.SetDoFail(); for (int i = 0; i < NUM_THREADS; i++) { threads[i].Join(); Assert.IsTrue(threads[i].error == null, "hit unexpected Throwable"); } bool success = false; try { writer.Dispose(false); success = true; } catch (Exception ioe) when(ioe.IsIOException()) { failure.ClearDoFail(); writer.Dispose(false); } if (Verbose) { Console.WriteLine("TEST: success=" + success); } if (success) { IndexReader reader = DirectoryReader.Open(dir); IBits delDocs = MultiFields.GetLiveDocs(reader); for (int j = 0; j < reader.MaxDoc; j++) { if (delDocs == null || !delDocs.Get(j)) { reader.Document(j); reader.GetTermVectors(j); } } reader.Dispose(); } dir.Dispose(); } }
public void OnFailure(Java.Lang.Exception e) { Failure?.Invoke(this, new EventArgs()); }
public Decision?OnFailure(Failure failure) { return(null); }
/// <summary> /// Constructor for a failure case. /// </summary> private FilteredWorkspaceDefinition(Failure failure, WorkspaceDefinition workspaceDefinition) : this() { Failure = failure; FilteredDefinition = workspaceDefinition; }
public void OnResolutionFinished(Failure failure, Decision decision, Resolution resolution) { }
/// <nodoc /> public static FilteredWorkspaceDefinition Error(Failure failure) { Contract.Requires(failure != null); return(new FilteredWorkspaceDefinition(failure, null)); }
public Result(Failure failure) { Failure = failure; }
internal static void ShowConnectingDialogError_(Form owner, IXenConnection connection, Exception error) { if (error is ExpressRestriction) { ExpressRestriction e = (ExpressRestriction)error; Program.Invoke(Program.MainWindow, delegate() { new LicenseWarningDialog(e.HostName, e.ExistingHostName).ShowDialog(owner); }); return; } if (error is Failure) { Failure f = (Failure)error; if (f.ErrorDescription[0] == Failure.HOST_IS_SLAVE) { string oldHost = connection.Name; string poolMasterName = f.ErrorDescription[1]; string pool_name = XenConnection.ConnectedElsewhere(poolMasterName); if (pool_name != null) { if (!Program.RunInAutomatedTestMode) { if (pool_name == oldHost) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, string.Format(Messages.OLD_CONNECTION_ALREADY_CONNECTED, pool_name), Messages.ADD_NEW_CONNECT_TO))) { dlg.ShowDialog(owner); } } else { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, string.Format(Messages.SLAVE_ALREADY_CONNECTED, oldHost, pool_name), Messages.ADD_NEW_CONNECT_TO))) { dlg.ShowDialog(owner); } } } } else { DialogResult dialogResult; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, String.Format(Messages.SLAVE_CONNECTION_ERROR, oldHost, poolMasterName), Messages.CONNECT_TO_SERVER), ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo)) { dialogResult = dlg.ShowDialog(owner); } if (DialogResult.Yes == dialogResult) { ((XenConnection)connection).Hostname = poolMasterName; BeginConnect(connection, true, owner, false); } } } else if (f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { AddError(owner, connection, Messages.ERROR_NO_PERMISSION, Messages.SOLUTION_NO_PERMISSION); } else if (f.ErrorDescription[0] == XenAPI.Failure.SESSION_AUTHENTICATION_FAILED) { AddError(owner, connection, Messages.ERROR_AUTHENTICATION, Messages.SOLUTION_AUTHENTICATION); } else if (f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { AddError(owner, connection, Messages.ERROR_HOST_STILL_BOOTING, Messages.SOLUTION_HOST_STILL_BOOTING); } else { AddError(owner, connection, string.IsNullOrEmpty(f.Message) ? Messages.ERROR_UNKNOWN : f.Message, string.Empty); } } else if (error is WebException) { if (((XenConnection)connection).SupressErrors) { return; } WebException w = (WebException)error; var solutionCheckXenServer = Properties.Settings.Default.ProxySetting != (int)HTTPHelper.ProxyStyle.DirectConnection ? Messages.SOLUTION_CHECK_XENSERVER_WITH_PROXY : Messages.SOLUTION_CHECK_XENSERVER; switch (w.Status) { case WebExceptionStatus.ConnectionClosed: AddError(owner, connection, Messages.CONNECTION_CLOSED_BY_SERVER, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ConnectFailure: AddError(owner, connection, Messages.CONNECTION_REFUSED, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ProtocolError: if (w.Message != null && w.Message.Contains("(404)")) { AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); } else if (w.Message != null && w.Message.Contains("(407)")) { string proxyAddress = Properties.Settings.Default.ProxyAddress; AddError(owner, connection, string.Format(Messages.ERROR_PROXY_AUTHENTICATION, proxyAddress), string.Format(Messages.SOLUTION_CHECK_PROXY, proxyAddress)); } else { AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); } break; case WebExceptionStatus.NameResolutionFailure: AddError(owner, connection, string.Format(Messages.ERROR_NOT_FOUND, ((XenConnection)connection).Hostname), Messages.SOLUTION_NOT_FOUND); break; case WebExceptionStatus.ReceiveFailure: case WebExceptionStatus.SendFailure: AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.SecureChannelFailure: AddError(owner, connection, string.Format(Messages.ERROR_SECURE_CHANNEL_FAILURE, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN); break; default: AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); break; } } else if (error is UriFormatException) { AddError(owner, connection, string.Format(Messages.ERROR_INVALID_URI, connection.Name), Messages.SOLUTION_NOT_FOUND); } else if (error is FileNotFoundException) { // If you're using the DbProxy AddError(owner, connection, string.Format(string.Format(Messages.ERROR_FILE_NOT_FOUND, ((XenConnection)connection).Hostname), connection.Name), Messages.SOLUTION_UNKNOWN); } else if (error is ConnectionExists) { ConnectionsManager.ClearCacheAndRemoveConnection(connection); if (!Program.RunInAutomatedTestMode) { ConnectionExists c = error as ConnectionExists; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, c.GetDialogMessage(connection), Messages.XENCENTER))) { dlg.ShowDialog(owner); } } } else if (error is ArgumentException) { // This happens if the server API is incompatible with our bindings. This should // never happen in production, but will happen during development if a field // changes type, for example. AddError(owner, connection, Messages.SERVER_API_INCOMPATIBLE, Messages.SOLUTION_UNKNOWN); } else if (error is ServerNotSupported) { // Server version is too old for this version of XenCenter AddError(owner, connection, Messages.SERVER_TOO_OLD, Messages.SERVER_TOO_OLD_SOLUTION); } else { if (((XenConnection)connection).SupressErrors) { return; } AddError(owner, connection, string.Format(Messages.ERROR_UNKNOWN, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN); } }
.Fold(Failure <Configuration>(NotFound(nameof(Configuration))))(record => NewConfiguration(
/// <summary> /// Base failure type for the cache with optional inner failure /// </summary> /// <param name="innerFailure">Optional inner failure</param> protected CacheBaseFailure(Failure innerFailure = null) : base(innerFailure) { }
=> Equals(Successful, other.Successful) && Equals(Failure, other.Failure);
public override void TestAssumptionFailure(Failure failure) { lastTest = 'A'; // assumption failure. }
private async Task <RpcCallResult <T> > CallCore <T>( Func <TrackedConnection, BondCallTracker, Task <T> > callAsync, CancellationToken cancellationToken, string functionName, BondCallTracker callTracker, bool allowInactive = false, Func <T, bool> shouldRetry = null, uint maxTryCount = 0) { Contract.Requires(functionName != null); callTracker = callTracker ?? CreateLoggingCallTracker(functionName); TimeSpan waitForConnectionDuration = default(TimeSpan); Failure lastFailure = null; m_outstandingCalls.AddOrUpdate(functionName, 1, (k, i) => i + 1); // For heartbeat only try once if (maxTryCount == 0) { maxTryCount = DefaultMaxRetryCount; } for (uint retryCount = 0; retryCount < maxTryCount; retryCount++) { callTracker.TryCount = retryCount; if (retryCount != 0) { // For retries, log a call start with the call tracker's updated retry count callTracker.OnStateChanged(BondCallState.Started); // Yield after first iteration to ensure // we don't overflow the stack with async continuations await Task.Yield(); } TrackedConnection connection = null; try { var startWaitForConnection = m_stopwatch.Elapsed; callTracker.OnStateChanged(BondCallState.WaitingForConnection); // Wait for a connection to become active via the a successful heartbeat using (var connectionScope = await WaitForConnectionAsync(callTracker, allowInactive, cancellationToken)) { // Log wait for connection success var iterationWaitForConnectionDuration = GetElapsed(startWaitForConnection); waitForConnectionDuration += iterationWaitForConnectionDuration; callTracker.OnStateChanged(BondCallState.CompletedWaitForConnection); // connection is not returned in the case that the proxy is shutting down or timed out // other case is that this is a failed heartbeat call. In which case, just continue. if (connectionScope.Connection == null) { if (m_isShuttingDown || m_exceededInactivityTimeout) { // Log the failure lastFailure = new RecoverableExceptionFailure(new BuildXLException(m_isShuttingDown ? "Bond RPC Call failure: Proxy is shutting down" : "Bond RPC Call failure: Proxy timed out")); callTracker.LogMessage("Could not retrieve connection. Failure={0}", lastFailure.DescribeIncludingInnerFailures()); callTracker.OnStateChanged(BondCallState.Failed); return(new RpcCallResult <T>(RpcCallResultState.Failed, retryCount + 1, callTracker.TotalDuration, waitForConnectionDuration, lastFailure)); } continue; } connection = connectionScope.Connection; // Make the actual call var result = await callAsync(connection, callTracker); // Check if call should be retried if (shouldRetry != null && shouldRetry(result)) { continue; } // Log the call completion callTracker.OnStateChanged(BondCallState.Succeeded); m_proxyLogger.LogSuccessfulCall(m_loggingContext, functionName, retryCount); connectionScope.MarkSucceeded(); m_services.Counters.AddToCounter(DistributionCounter.SendPipBuildRequestCallDurationMs, (long)callTracker.TotalDuration.TotalMilliseconds); return(new RpcCallResult <T>(result, retryCount + 1, callTracker.TotalDuration, waitForConnectionDuration)); } } catch (OperationCanceledException) { callTracker.OnStateChanged(BondCallState.Canceled); return(new RpcCallResult <T>(RpcCallResultState.Cancelled, retryCount + 1, callTracker.TotalDuration, waitForConnectionDuration)); } catch (Exception ex) { // If shutting down just return the failed result if (ex is ObjectDisposedException && m_isShuttingDown) { lastFailure = new RecoverableExceptionFailure(new BuildXLException("Bond RPC Call failure: Proxy is shutting down", ex)); callTracker.LogMessage("{0}", lastFailure.DescribeIncludingInnerFailures()); callTracker.OnStateChanged(BondCallState.Failed); return(new RpcCallResult <T>(RpcCallResultState.Failed, retryCount + 1, callTracker.TotalDuration, waitForConnectionDuration)); } if (DistributionServices.IsBuildIdMismatchException(ex)) { m_proxyLogger.LogCallException(m_loggingContext, functionName, retryCount, ex); // If a message with different build is received, it means that the sender has participated in a different distributed build. // Then, we need to lose the connection with the sender. OnConnectionTimeOut?.Invoke(this, EventArgs.Empty); return(new RpcCallResult <T>(RpcCallResultState.Failed, retryCount + 1, callTracker.TotalDuration, waitForConnectionDuration)); } // If not a transient exception, log and throw if (!DistributionHelpers.IsTransientBondException(ex, m_services.Counters) && !m_services.IsChecksumMismatchException(ex)) { m_proxyLogger.LogCallException(m_loggingContext, functionName, retryCount, ex); throw; } // Otherwise, the exception is transient, so log exception and try again lastFailure = new RecoverableExceptionFailure(new BuildXLException("Failed Bond RPC call", ex)); callTracker.LogMessage("{0}", lastFailure.DescribeIncludingInnerFailures()); // Deactivate connection so subsequent calls on the proxy will wait for heartbeat before trying to make call. DeactivateConnection(connection); m_services.Counters.AddToCounter(DistributionCounter.FailedSendPipBuildRequestCallDurationMs, (long)callTracker.TotalDuration.TotalMilliseconds); m_services.Counters.IncrementCounter(DistributionCounter.FailedSendPipBuildRequestCount); m_proxyLogger.LogFailedCall(m_loggingContext, functionName, retryCount, lastFailure); } finally { m_outstandingCalls.AddOrUpdate(functionName, 0, (k, i) => i - 1); } } // Exceeded retry count. callTracker.LogMessage("Call failed and exhausted allowed retries. LastFailure={0}", lastFailure?.DescribeIncludingInnerFailures() ?? string.Empty); callTracker.OnStateChanged(BondCallState.Failed); return(new RpcCallResult <T>(RpcCallResultState.Failed, DefaultMaxRetryCount, callTracker.TotalDuration, waitForConnectionDuration, lastFailure)); }
public void OrElse_on_Failure_returns_else() { var t = new Failure<string>(new Exception()); var alt = new Success<string>("bar"); Assert.AreSame(alt, t.OrElse(alt)); }
public async Task <RpcCallResult <Unit> > CallAsync( Func <CallOptions, AsyncUnaryCall <RpcResponse> > func, string operation, CancellationToken cancellationToken = default(CancellationToken), bool waitForConnection = false) { var watch = Stopwatch.StartNew(); TimeSpan waitForConnectionDuration = TimeSpan.Zero; TimeSpan totalCallDuration = TimeSpan.Zero; if (waitForConnection) { bool connectionSucceeded = await TryConnectChannelAsync(GrpcSettings.InactiveTimeout, operation, watch); waitForConnectionDuration = watch.Elapsed; if (!connectionSucceeded) { return(new RpcCallResult <Unit>(RpcCallResultState.Cancelled, attempts: 1, duration: TimeSpan.Zero, waitForConnectionDuration)); } } Guid traceId = Guid.NewGuid(); var headers = new Metadata(); headers.Add(GrpcSettings.TraceIdKey, traceId.ToByteArray()); headers.Add(GrpcSettings.BuildIdKey, m_buildId); headers.Add(GrpcSettings.SenderKey, DistributionHelpers.MachineName); RpcCallResultState state = RpcCallResultState.Succeeded; Failure failure = null; uint numTry = 0; while (numTry < GrpcSettings.MaxRetry) { numTry++; watch.Restart(); try { var callOptions = new CallOptions( deadline: DateTime.UtcNow.Add(GrpcSettings.CallTimeout), cancellationToken: cancellationToken, headers: headers).WithWaitForReady(); Logger.Log.GrpcTrace(m_loggingContext, GenerateLog(traceId.ToString(), "Call", numTry, operation)); await func(callOptions); Logger.Log.GrpcTrace(m_loggingContext, GenerateLog(traceId.ToString(), "Sent", numTry, $"Duration: {watch.ElapsedMilliseconds}ms")); state = RpcCallResultState.Succeeded; break; } catch (RpcException e) { state = e.Status.StatusCode == StatusCode.Cancelled ? RpcCallResultState.Cancelled : RpcCallResultState.Failed; failure = state == RpcCallResultState.Failed ? new RecoverableExceptionFailure(new BuildXLException(e.Message)) : null; Logger.Log.GrpcTrace(m_loggingContext, GenerateFailLog(traceId.ToString(), numTry, watch.ElapsedMilliseconds, e.Message)); // If the call is cancelled or channel is shutdown, then do not retry the call. if (state == RpcCallResultState.Cancelled || m_isShutdownInitiated) { break; } if (numTry == GrpcSettings.MaxRetry - 1) { // If this is the last retry, try to attempt reconnecting. If the connection fails, do not attempt to retry the call. bool connectionSucceeded = await TryConnectChannelAsync(GrpcSettings.CallTimeout, operation); if (!connectionSucceeded) { break; } } } catch (ObjectDisposedException e) { state = RpcCallResultState.Failed; failure = new RecoverableExceptionFailure(new BuildXLException(e.Message)); Logger.Log.GrpcTrace(m_loggingContext, GenerateFailLog(traceId.ToString(), numTry, watch.ElapsedMilliseconds, e.Message)); // If stream is already disposed, we cannot retry call. break; } finally { totalCallDuration += watch.Elapsed; } } if (state == RpcCallResultState.Succeeded) { return(new RpcCallResult <Unit>(Unit.Void, attempts: numTry, duration: totalCallDuration, waitForConnectionDuration: waitForConnectionDuration)); } return(new RpcCallResult <Unit>( state, attempts: numTry, duration: totalCallDuration, waitForConnectionDuration: waitForConnectionDuration, lastFailure: failure)); }
public void Transform_of_Failure_calls_failure_closure() { var t = new Failure<int>(new Exception("fail")); var successCalled = false; var failureCalled = false; Func<int, Try<string>> success = v => { successCalled = true; return new Success<string>(v.ToString()); }; Func<Exception, Try<string>> failure = e => { failureCalled = true; return new Success<string>(e.Message); }; Assert.AreEqual("fail", t.Transform(success, failure).Value); Assert.IsFalse(successCalled); Assert.IsTrue(failureCalled); }
public void TestThatGetOrNullReturnsNullOnAFailure() => Assert.Null(Failure.Of <Exception, object>(RandomException()).GetOrNull());
/// <summary> /// add a Failure object to the list of objects to be evaluated /// at every potential failure point /// </summary> public virtual void FailOn(Failure fail) { lock (this) { if (Failures == null) { Failures = new List<Failure>(); } Failures.Add(fail); } }
public void TestThatAFailedOutcomeIsTransformedToAFailedCompletes() => Assert.True(Failure.Of <Exception, int>(RandomException()).AsCompletes().HasFailed);
public CopyException(Failure f, string msg) : base(msg) { reason = f; }
void Throw(Failure failure) { Assert.AreEqual(ResultError.Error, failure); throw new InvalidOperationException(); }
internal ExceptionEventArgs(Workspace workspace, Failure failure) { this.workspace = workspace; this.failure = failure; }
/// <summary> add a Failure object to the list of objects to be evaluated /// at every potential failure point /// </summary> public virtual void FailOn(Failure fail) { lock (this) { if (failures == null) { failures = new System.Collections.ArrayList(); } failures.Add(fail); } }
protected internal ExpectationFailure(Failure another) : base(another) { }
public void Recover_on_Failure_does_call_closure() { var t = new Failure<string>(new Exception()); Exception e = null; Func<Exception, string> c = ex => { e = ex; return "bar"; }; Assert.AreEqual("bar", t.Recover(c).Value); Assert.AreSame(t.Exception, e); }
/// <param name="o">A session to use for this action: if null, construct a new session and sudo it if necessary</param> private void RunWorkerThread(object o) { StartedRunning = true; if (Cancelled) // already cancelled before it's started { return; } try { // Check that the current user credentials are enough to complete the api calls in this action (if specified) if (o != null) { Session = (Session)o; } else { SetSessionByRole(); } Run(); AuditLogSuccess(); MarkCompleted(); } catch (CancelledException e) { Cancelled = true; AuditLogCancelled(); MarkCompleted(e); } catch (Exception e) { Failure f = e as Failure; if (f != null && Connection != null && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { Failure.ParseRBACFailure(f, Connection, Session ?? Connection.Session); } log.Error(e); AuditLogFailure(); MarkCompleted(e); } finally { Clean(); if (Exception != null) { CleanOnError(); } if (o == null && Session != null && Session.IsElevatedSession) { // The session is a new, sudo-ed session: we need to log these ones out try { Session.logout(); } catch (Failure f) { log.Debug("Session.logout() failed. ", f); } } Session = null; LogoutCancelSession(); } }
public async Task HandleFailure(Failure failure) { await _supervisionStrategy.HandleFailure(this, failure); }
// Runs test, with one thread, using the specific failure // to trigger an IOException public virtual void TestSingleThreadFailure(Func <IConcurrentMergeScheduler> newScheduler, Failure failure) { MockDirectoryWrapper dir = NewMockDirectory(); IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(2).SetMergeScheduler(newScheduler())); Document doc = new Document(); FieldType customType = new FieldType(TextField.TYPE_STORED); customType.StoreTermVectors = true; customType.StoreTermVectorPositions = true; customType.StoreTermVectorOffsets = true; doc.Add(NewField("field", "aaa bbb ccc ddd eee fff ggg hhh iii jjj", customType)); for (int i = 0; i < 6; i++) { writer.AddDocument(doc); } dir.FailOn(failure); failure.SetDoFail(); try { writer.AddDocument(doc); writer.AddDocument(doc); writer.Commit(); Assert.Fail("did not hit exception"); } catch (IOException) { } failure.ClearDoFail(); writer.AddDocument(doc); writer.Dispose(false); dir.Dispose(); }
public void GetOrElse_on_Failure_returns_else() { var t = new Failure<string>(new Exception()); Assert.AreEqual("bar", t.GetOrElse("bar")); }
public override void testFailure(Failure f) { success--; System.out.println("Failure: " + f.getTestHeader()); f.getException().printStackTrace(); }