예제 #1
0
        public static void PerformInternalServiceFaultIfRequested(Guid operationId, ServiceInternalFaultInfo serviceInternalFaultInfo, ActionStateBase actionState, CancellationToken cancellationToken, bool isMidState)
        {
            TestabilityTrace.TraceSource.WriteInfo(StepBase.TraceType, "{0} - enter PerformInternalServiceFaultIfRequested", operationId);
            if (serviceInternalFaultInfo != null)
            {
                if (serviceInternalFaultInfo.TargetStepStateName == actionState.StateProgress.Peek() ||
                    (serviceInternalFaultInfo.TargetStepStateName == Actions.Steps.StepStateNames.MidPerformingActions && isMidState))
                {
                    if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.KillProcess)
                    {
                        TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} Intentionally exiting process using Process.Kill", operationId);
                        Process.GetCurrentProcess().Kill();
                        Task.Delay(Timeout.Infinite, cancellationToken).Wait();
                    }
                    else if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.ReportFaultPermanent)
                    {
                        // TODO - wire in the IStatefulServicePartition so ReportFault() can be called
                        throw new NotImplementedException();
                    }
                    else if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.ReportFaultTransient)
                    {
                        // TODO - wire in the IStatefulServicePartition so ReportFault() can be called
                        throw new NotImplementedException();
                    }
                    else if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.RollbackAction)
                    {
                        TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} {1}", operationId, ActionTest.FatalRollbackExceptionMessage);

                        // Intentionally using this "weird" error code so that it is noticeable.
                        throw new FabricException("Intentional test fault", FabricErrorCode.InvalidConfiguration);
                    }
                    else if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.ThrowThreeTimes)
                    {
                        if (serviceInternalFaultInfo.CountForThrowThreeTimesFault == 0)
                        {
                            TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} - number of test retries reached, now NOT performing fault", operationId);
                        }
                        else
                        {
                            serviceInternalFaultInfo.CountForThrowThreeTimesFault--;
                            throw new InvalidOperationException("Intentional exception from ThrowThreeTimes");
                        }
                    }
                    else if (serviceInternalFaultInfo.FaultType == ServiceInternalFaultType.RollbackActionAndRetry)
                    {
                        TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} Intentionally faliing this action.  It should succeed on retry.", operationId);

                        serviceInternalFaultInfo.SetFaultTypeToNone();
                        throw new FabricTransientException("Intentional test fault", FabricErrorCode.NotReady);
                    }
                }
            }
            else
            {
                TestabilityTrace.TraceSource.WriteInfo(TraceType, "{0} Inside PerformInternalServiceFaultIfRequested, no fault requested", actionState.OperationId);
            }
        }
예제 #2
0
 public static void PerformInternalServiceFaultIfRequested(Guid operationId, ServiceInternalFaultInfo serviceInternalFaultInfo, ActionStateBase actionState, CancellationToken cancellationToken)
 {
     PerformInternalServiceFaultIfRequested(operationId, serviceInternalFaultInfo, actionState, cancellationToken, false);
 }
예제 #3
0
        public static RollbackState PerformTestUserCancelIfRequested(Guid operationId, string location, ServiceInternalFaultInfo serviceInternalFaultInfo, ActionStateBase actionState)
        {
            if (serviceInternalFaultInfo != null)
            {
                TestabilityTrace.TraceSource.WriteInfo(
                    TraceType,
                    "{0} location={1}, serviceInternalFaultInfo.Location={2}, internal test RollbackType={3}",
                    operationId,
                    location,
                    serviceInternalFaultInfo.Location,
                    serviceInternalFaultInfo.RollbackType);

                // "None" means "don't care"
                if (serviceInternalFaultInfo.TargetCancelStepStateName == actionState.StateProgress.Peek() ||
                    serviceInternalFaultInfo.TargetCancelStepStateName == StepStateNames.None)
                {
                    if (location == serviceInternalFaultInfo.Location)
                    {
                        if (serviceInternalFaultInfo.RollbackType == RollbackState.RollingBackDueToUserCancel)
                        {
                            TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} Intentionally canceling command, force==false", operationId);
                            return(RollbackState.RollingBackDueToUserCancel);
                        }
                        else if (serviceInternalFaultInfo.RollbackType == RollbackState.RollingBackForce)
                        {
                            TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} Intentionally canceling command, force==true", operationId);
                            return(RollbackState.RollingBackForce);
                        }
                    }
                }
            }

            return(actionState.RollbackState);
        }