Inheritance: MonoBehaviour
        private async Task FailureTest(Fail failCode, int numOfFailures)
        {
            this.HostedCluster.StartAdditionalSilos(numAdditionalSilos);
            await this.HostedCluster.WaitForLivenessToStabilizeAsync();

            List<SiloHandle> failures = await getSilosToFail(failCode, numOfFailures);
            foreach (SiloHandle fail in failures) // verify before failure
            {
                VerificationScenario(PickKey(fail.SiloAddress)); // fail.SiloAddress.GetConsistentHashCode());
            }

            logger.Info("FailureTest {0}, Code {1}, Stopping silos: {2}", numOfFailures, failCode, Utils.EnumerableToString(failures, handle => handle.SiloAddress.ToString()));
            List<uint> keysToTest = new List<uint>();
            foreach (SiloHandle fail in failures) // verify before failure
            {
                keysToTest.Add(PickKey(fail.SiloAddress)); //fail.SiloAddress.GetConsistentHashCode());
                this.HostedCluster.StopSilo(fail);
            }
            await this.HostedCluster.WaitForLivenessToStabilizeAsync();

            AssertEventually(() =>
            {
                foreach (var key in keysToTest) // verify after failure
                {
                    VerificationScenario(key);
                }
            }, failureTimeout);
        }
示例#2
0
        public virtual void testSomeAllFailures()
        {
            Fail f = new Fail();
            Some     some = new Some(logVisitor(f));
            Logger expected = new Logger(f, new IVisitable[]{n1,n2});

            IVisitable nodeReturned = null;

            try {
                nodeReturned = some.visit(n0);
            }
            catch (VisitFailure)
            {
                Assertion.AssertEquals(expected, logger);
                Assertion.AssertNull(nodeReturned);
            }
        }
 public virtual void testOnceTopDownFail()
 {
     IVisitor f = new Fail();
     OnceTopDown onceTopDown = new OnceTopDown(logVisitor(f));
     Logger expected = new Logger(f, new IVisitable[]{n0,n1,n11,n12,n2});
     IVisitable nodeReturned = null;
     try
     {
         nodeReturned = onceTopDown.visit(n0);
         Assertion.Fail("VisitFailure should have occured!");
     }
     catch (VisitFailure)
     {
         Assertion.AssertEquals("visit trace",expected, logger);
         Assertion.AssertNull("return value",nodeReturned);
     }
 }
        // throws VisitFailure
        public virtual void testTrueFailingThen()
        {
            Fail failingThen = new Fail();
            Logger expected = new Logger();
            expected.log( new Event( failingThen, n0 ) );

            try
            {
                nodeReturned = new IfThenElse( new Identity(), logVisitor(failingThen),	logVisitor(idFalse)).visit(n0);
                Assertion.Fail();
            }
            catch(VisitFailure)
            {
                Assertion.AssertEquals("trace", expected, logger);
                Assertion.AssertNull("returned node", nodeReturned);
            }
        }
示例#5
0
        public static Limb TransitionTo (Limb from, Analyzer.Node.Limb to, float cur_second) {
            if (!IsArcValid(from, to)) {
                throw new ArgumentException();
            }

            if (to == null) {
                throw new ArgumentException();
                /*Limb nxt = new Limb();
                for (int i = 0; i < Limb.PART_COUNT; ++i) {
                    Part part = PartHelper.TransitionTo(from[i], null, cur_second);
                    nxt[i] = part;
                }
                nxt.sanityCheck();
                return nxt;*/
            } else {
                Limb nxt = new Limb();
                for (int i = 0; i < Limb.PART_COUNT; ++i) {
                    Part part = PartHelper.TransitionTo(from[i], to[i], cur_second);
                    nxt[i] = part;
                }
                if (to[Analyzer.Node.Limb.INDEX_EXTRA] == null) {
                    nxt.extra = nxt.sub;
                }
                bool has_main = to.main != null;
                bool has_sub = to.sub != null;
                bool has_extra = to.extra != null;
                Fail fail = new Fail(nxt);
                if (has_main) {
                    if (has_sub) {
                        if (has_extra) {
                            //main+sub+extra
                            if (fail.main_sub) {
                                throw new ArgumentException();
                            }
                            if (fail.main_extra) {
                                throw new ArgumentException();
                            }
                            if (fail.sub_extra) {
                                throw new ArgumentException();
                            }
                        } else {
                            //main+sub
                            if (fail.main_sub) {
                                throw new ArgumentException();
                            }
                            if (fail.main_extra) {
                                nxt.extra = nxt.sub;
                                fail = new Fail(nxt);
                            }
                            if (fail.sub_extra) {
                                nxt.extra = nxt.sub;
                                fail = new Fail(nxt);
                            }
                        }
                    } else if (has_extra) {
                        //main+extra
                        if (fail.main_sub) {
                            nxt.sub = nxt.extra;
                            fail = new Fail(nxt);
                        }
                        if (fail.main_extra) {
                            throw new ArgumentException();
                        }
                        if (fail.sub_extra) {
                            nxt.sub = nxt.extra;
                            fail = new Fail(nxt);
                        }
                    } else {
                        //main
                        if (fail.main_sub) {
                            Panel n = Panel.CalculateBestBracketable(nxt.main.panel, nxt.sub.panel);
                            Part src = nxt.sub;
                            nxt.sub = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );
                            fail = new Fail(nxt);
                        }
                        if (fail.main_extra) {
                            nxt.extra = nxt.sub;
                            fail = new Fail(nxt);
                        }
                        if (fail.sub_extra) {
                            throw new ArgumentException();
                        }
                    }
                } else if (has_sub) {
                    if (has_extra) {
                        //sub+extra
                        if (fail.main_sub) {
                            Panel n = Panel.CalculateBestBracketable(nxt.sub.panel, nxt.main.panel);
                            Part src = nxt.main;
                            nxt.main = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );
                            fail = new Fail(nxt);
                        }
                        if (fail.main_extra) {
                            Panel n = Panel.CalculateBestBracketable(nxt.extra.panel, nxt.main.panel);
                            Part src = nxt.main;
                            nxt.main = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );
                            fail = new Fail(nxt);
                        }
                        if (fail.sub_extra) {
                            throw new ArgumentException();
                        }
                    } else {
                        //sub
                        if (fail.main_sub) {
                            Panel n = Panel.CalculateBestBracketable(nxt.sub.panel, nxt.main.panel);
                            Part src = nxt.main;
                            nxt.main = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );
                            fail = new Fail(nxt);
                        }
                        if (fail.main_extra) {
                            throw new ArgumentException();
                        }
                        if (fail.sub_extra) {
                            nxt.extra = nxt.sub;
                            fail = new Fail(nxt);
                        }
                    }
                } else if (has_extra) {
                    //extra
                    if (fail.main_sub) {
                        throw new ArgumentException();
                    }
                    if (fail.main_extra) {
                        Panel n = Panel.CalculateBestBracketable(nxt.extra.panel, nxt.main.panel);
                        Part src = nxt.main;
                        nxt.main = new Part(
                            Movement.Unknown,
                            n,
                            src.cur_second,
                            cur_second,
                            src.cur_moved_second == cur_second ?
                                src.prv_moved_second : src.cur_moved_second
                        );
                        fail = new Fail(nxt);
                    }
                    if (fail.sub_extra) {
                        nxt.sub = nxt.extra;
                        fail = new Fail(nxt);
                    }
                } else {
                    //NOTHING
                    if (fail.main_sub) {
                        throw new ArgumentException();
                    }
                    if (fail.main_extra) {
                        throw new ArgumentException();
                    }
                    if (fail.sub_extra) {
                        throw new ArgumentException();
                    }
                }
                if (fail.main_sub || fail.main_extra || fail.sub_extra) {
                    throw new ArgumentException();
                }
                nxt.sanityCheck();
                return nxt;
            }
        }
示例#6
0
        /// <inheritdoc />
        public ISessionFactory Open()
        {
            Fail.IfNull(this.factory, "You cannot reopen a database when it was disposed");

            return(this.factory.Value);
        }
 public static CreateScorePolicyCommand Create(string name, string description, List <ScoreRuleDto> scoreRules)
 {
     Fail.IfNullOrEmpty(name);
     Fail.IfNullOrEmpty(scoreRules);
     return(new CreateScorePolicyCommand(name, description, scoreRules));
 }
示例#8
0
        public static string GetColumnName([NotNull] Member property)
        {
            Fail.IfArgumentNull(property, nameof(property));

            return(property.Name + ForeignKeyColumnNameConvention.IdIdentifier);
        }
示例#9
0
 /// <inheritdoc />
 public virtual void Dispose()
 {
     Fail.IfNull(ThreadStaticContextScope <T> .Sack, nameof(ThreadStaticContextScope <T> .Sack) + " is null");
     ThreadStaticContextScope <T> .Sack.Value = default(T);
     ThreadStaticContextScope <T> .Sack       = null;
 }
示例#10
0
        internal static Option <Dictionary <string, object> > CreateEntity <T, TDto, TCreateInterceptor>(
            this Option <ServiceMapping <T, TCreateInterceptor> > serviceMapping,
            Option <TDto> dto)
            where T : class, IEntity
            where TDto : class, IDto
            where TCreateInterceptor : ICreateInterceptor
        {
            try
            {
                return(serviceMapping.GetCreateParametersMapping(dto)
                       .MapFlatten(
                           x =>
                {
                    x.Args.PreValidation?.Invoke(x.Dto);
                    x.Dto.Validate();
                    x.Args.PostValidation?.Invoke(x.Dto);
                    var entity = x.Dto.ToEntity <T>();
                    AsyncHelper.RunSync(() => x.Args.PostMap?.Invoke(entity, x.Repository));
                    var result = x.Repository.Create(entity, x.Args.MessageIfExistFunc);
                    AsyncHelper.RunSync(() => x.Args.PreSave?.Invoke(entity, x.Repository));
                    if (x.Args.PendingSave)
                    {
                        return result;
                    }
                    x.Uow.SaveChanges();
                    return result;
                }));
            }
            catch (ArgumentNullException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (ValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PreValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PostValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PostMapException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PreSaveException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (ExistingEntityException <T> ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
#if NETSTANDARD2_0
            catch (EfCoreDbUpdateException ex)
            {
                var message = ex.HumanizeKeyError();
                return(Fail <Dictionary <string, object> > .Throw(new EfCoreDbUpdateException(message, ex)));
            }
#endif
#if NET471
            catch (EfDbUpdateException ex)
            {
                var message = ex.HumanizeKeyError();
                return(Fail <Dictionary <string, object> > .Throw(new EfDbUpdateException(message, ex)));
            }
#endif
            catch (Exception ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
        }
示例#11
0
 /// <summary>
 /// Sets the on failure delegate.
 /// </summary>
 /// <returns>The on failure delegate.</returns>
 /// <param name="onFail">On fail.</param>
 public Web SetOnFailureDelegate(Fail onFail)
 {
     this.OnFail = onFail;
     return this;
 }
示例#12
0
        internal static async Task <Option <Dictionary <string, object> > > CreateEntityAsync <T, TDto, TCreateInterceptor>(
            this Option <ServiceMapping <T, TCreateInterceptor> > serviceMapping,
            Option <TDto> dto,
            Option <CancellationToken> ctok)
            where T : class, IEntity
            where TDto : class, IDto
            where TCreateInterceptor : ICreateInterceptor
        {
            try
            {
                return(await serviceMapping.GetAsyncCreateParametersMapping(dto, ctok)
                       .MapFlattenAsync(
                           async x =>
                {
                    x.Args.PreValidation?.Invoke(x.Dto);
                    await x.Dto.ValidateAsync();
                    x.Args.PostValidation?.Invoke(x.Dto);
                    var entity = x.Dto.ToEntity <T>();
                    if (x.Args.PostMap != null)
                    {
                        await x.Args.PostMap.Invoke(entity, x.Repository);
                    }
                    var result = await x.Repository.CreateAsync(entity, x.Args.MessageIfExistFunc, x.Ctok);
                    if (x.Args.PreSave != null)
                    {
                        await x.Args.PreSave.Invoke(entity, x.Repository);
                    }
                    if (x.Args.PendingSave)
                    {
                        return result;
                    }
                    await x.Uow.SaveChangesAsync(ctok);
                    return result;
                }));
            }
            catch (ArgumentNullException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (ValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PreValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PostValidationException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PostMapException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (PreSaveException ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
            catch (ExistingEntityException <T> ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
#if NETSTANDARD2_0
            catch (EfCoreDbUpdateException ex)
            {
                var message = ex.HumanizeKeyError();
                return(Fail <Dictionary <string, object> > .Throw(new EfCoreDbUpdateException(message, ex)));
            }
#endif
#if NET471
            catch (EfDbUpdateException ex)
            {
                var message = ex.HumanizeKeyError();
                return(Fail <Dictionary <string, object> > .Throw(new EfDbUpdateException(message, ex)));
            }
#endif
            catch (Exception ex)
            {
                return(Fail <Dictionary <string, object> > .Throw(ex));
            }
        }
示例#13
0
        internal static async Task <Option <bool> > DeleteEntityAsync <T, TDto, TDeleteInterceptor>(
            this Option <ServiceMapping <T, TDeleteInterceptor> > serviceMapping,
            Option <TDto> criteria,
            Option <CancellationToken> ctok)
            where T : class, IEntity
            where TDto : class, IDto
            where TDeleteInterceptor : IDeleteInterceptor
        {
            try
            {
                return(await serviceMapping.GetAsyncDeleteParametersMapping(criteria, ctok)
                       .MapFlattenAsync(
                           async x =>
                {
                    var entityCriteria = x.Criteria.ToEntity <T>();
                    if (x.Args.PreDelete != null)
                    {
                        await x.Args.PreDelete.Invoke(entityCriteria, x.Repository);
                    }
                    var result = await x.Repository.DeleteAsync(entityCriteria, x.Ctok);
                    if (x.Args.PreSave != null)
                    {
                        await x.Args.PreSave.Invoke(entityCriteria, x.Repository);
                    }
                    if (x.Args.PendingSave)
                    {
                        return result;
                    }
                    await x.Uow.SaveChangesAsync(x.Ctok);
                    return result;
                }));
            }
            catch (ArgumentNullException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
            catch (KeyNotFoundException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
            catch (PreDeleteException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
            catch (PreSaveException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
#if NETSTANDARD2_0
            catch (EfCoreDbUpdateException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
#endif
#if NET471
            catch (EfDbUpdateException ex)
            {
                return(Fail <bool> .Throw(ex));
            }
#endif
            catch (Exception ex)
            {
                return(Fail <bool> .Throw(ex));
            }
        }
        public String SendAndRead(String FileName, String OldFileName)
        {
            TcpClient tcpClient    = new TcpClient(_Server, Convert.ToInt32(_Port));
            String    responseData = String.Empty;

            using (FileStream inputStream = File.OpenRead(FileName))
            {
                using (NetworkStream outputStream = tcpClient.GetStream())
                {
                    using (BinaryWriter writer = new BinaryWriter(outputStream))
                    {
                        bool   CloseConnect = false;
                        long   lenght       = inputStream.Length;
                        long   totalBytes   = 0;
                        int    readBytes    = 0;
                        byte[] buffer       = new byte[8192];
                        writer.Write(CloseConnect);
                        writer.Write(SystemArgs.User.Login);
                        writer.Write(OldFileName);
                        writer.Write(SystemArgs.Path.GetFileName(FileName));
                        writer.Write(lenght);
                        do
                        {
                            readBytes = inputStream.Read(buffer, 0, buffer.Length);
                            outputStream.Write(buffer, 0, readBytes);
                            totalBytes += readBytes;
                        } while (tcpClient.Connected && totalBytes < lenght);
                        Byte[]        readingData       = new Byte[256];
                        StringBuilder completeMessage   = new StringBuilder();
                        int           numberOfBytesRead = 0;
                        do
                        {
                            numberOfBytesRead = outputStream.Read(readingData, 0, readingData.Length);
                            completeMessage.AppendFormat("{0}", Encoding.UTF8.GetString(readingData, 0, numberOfBytesRead));
                        }while (outputStream.DataAvailable);
                        responseData = completeMessage.ToString();
                        if (_NeedChecked)
                        {
                            if (AddDecodeSession(responseData.Replace(" ", "")))
                            {
                                Load?.Invoke(_DecodeSession);
                            }
                            else
                            {
                                Fail?.Invoke(OldFileName);
                            }
                        }
                        else if (responseData.Split('_').Length != 6)
                        {
                            Fail?.Invoke(OldFileName);
                        }
                        else
                        {
                            Rename?.Invoke(responseData, OldFileName);
                        }
                    }
                }
            }
            tcpClient.Close();
            return(responseData);
        }
示例#15
0
 public void addFail(Fail fail)
 {
     status = "Suspicious";
     fails.Add(fail);
 }
示例#16
0
        public static ChangeScoreCommand Create(int solutionId, int score)
        {
            Fail.If(solutionId <= 0);

            return(new ChangeScoreCommand(solutionId, score));
        }
示例#17
0
        private async Task <List <SiloHandle> > getSilosToFail(Fail fail, int numOfFailures)
        {
            List <SiloHandle> failures = new List <SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool           usingReminderGrain = this.ClusterConfiguration.Globals.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable tableGrain         = this.GrainFactory.GetGrain <IReminderTableGrain>(Constants.ReminderTableGrainId);
            var            tableGrainId       = ((GrainReference)tableGrain).GrainId;
            SiloAddress    reminderTableGrainPrimaryDirectoryAddress = (await TestUtils.GetDetailedGrainReport(this.HostedCluster.InternalGrainFactory, tableGrainId, this.HostedCluster.Primary)).PrimaryForGrain;
            // ask a detailed report from the directory partition owner, and get the actionvation addresses
            var addresses = (await TestUtils.GetDetailedGrainReport(this.HostedCluster.InternalGrainFactory, tableGrainId, this.HostedCluster.GetSiloForAddress(reminderTableGrainPrimaryDirectoryAddress))).LocalDirectoryActivationAddresses;
            ActivationAddress reminderGrainActivation = addresses.FirstOrDefault();

            SortedList <int, SiloHandle> ids = new SortedList <int, SiloHandle>();

            foreach (var siloHandle in this.HostedCluster.GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.SiloAddress;
                if (siloAddress.Equals(this.HostedCluster.Primary.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
            case Fail.First:
                index = 0;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index++;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Last:
                index = ids.Count - 1;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index--;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Random:
            default:
                while (count++ < numOfFailures)
                {
                    SiloHandle r = ids.Values[random.Next(ids.Count)];
                    while (failures.Contains(r))
                    {
                        r = ids.Values[random.Next(ids.Count)];
                    }
                    failures.Add(r);
                }
                break;
            }
            return(failures);
        }
        private WindsorContainer GetContainerOrFail()
        {
            Fail.IfNull(this.container, $"{nameof(WindsorEngine)} is not started");

            return(this.container);
        }
示例#19
0
        // throws jjtraveler.VisitFailure
        public virtual void testNonStopDownUp()
        {
            Identity downId = new Identity();
            Identity upId = new Identity();
            Fail stop = new Fail();

            Logger expected = new Logger();
            expected.log( new Event(downId, n3) );
            expected.log( new Event(downId, n0) );
            expected.log( new Event(upId, n0) );
            expected.log( new Event(downId, n1) );
            expected.log( new Event(upId, n1) );
            expected.log( new Event(upId, n3) );

            IVisitor  visitor = new DownUp(
                logVisitor(downId), stop, logVisitor(upId) );

            IVisitable nodeReturned = visitor.visit(n3);
            Assertion.AssertEquals(expected, logger);
            Assertion.AssertEquals(n3, nodeReturned);
        }
示例#20
0
 public void IfNotMidnightSuccess()
 {
     // ACT
     Fail.IfNotMidnight(DateTime.Today, "date should have no hour nor second");
 }
示例#21
0
 private void FailIfThreadStaticContextScopeNotAvailable()
 {
     Fail.IfFalse(this.IsAvailable(), Violation.Of(nameof(ThreadStaticContextScope <T>) + " is not available"));
 }
示例#22
0
 public void IfNotMidnightSuccessWithNull()
 {
     // ACT
     Fail.IfNotMidnight(null, "date should have no hour nor second");
 }
示例#23
0
        private List <SiloHandle> getSilosToFail(Fail fail, int numOfFailures)
        {
            List <SiloHandle> failures = new List <SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool              usingReminderGrain = this.HostedCluster.Primary.Silo.GlobalConfig.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable    tableGrain         = GrainClient.GrainFactory.GetGrain <IReminderTableGrain>(Constants.ReminderTableGrainId);
            SiloAddress       reminderTableGrainPrimaryDirectoryAddress = this.HostedCluster.Primary.Silo.LocalGrainDirectory.GetPrimaryForGrain(((GrainReference)tableGrain).GrainId);
            SiloHandle        reminderTableGrainPrimaryDirectory        = this.HostedCluster.GetActiveSilos().Where(sh => sh.Silo.SiloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress)).FirstOrDefault();
            AddressesAndTag   addresses;
            bool              res = reminderTableGrainPrimaryDirectory.Silo.LocalGrainDirectory.LocalLookup(((GrainReference)tableGrain).GrainId, out addresses);
            ActivationAddress reminderGrainActivation = addresses.Addresses.FirstOrDefault();

            SortedList <int, SiloHandle> ids = new SortedList <int, SiloHandle>();

            foreach (var siloHandle in this.HostedCluster.GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.Silo.SiloAddress;
                if (siloAddress.Equals(this.HostedCluster.Primary.Silo.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.Silo.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
            case Fail.First:
                index = 0;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index++;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Last:
                index = ids.Count - 1;
                while (count++ < numOfFailures)
                {
                    while (failures.Contains(ids.Values[index]))
                    {
                        index--;
                    }
                    failures.Add(ids.Values[index]);
                }
                break;

            case Fail.Random:
            default:
                while (count++ < numOfFailures)
                {
                    SiloHandle r = ids.Values[random.Next(ids.Count)];
                    while (failures.Contains(r))
                    {
                        r = ids.Values[random.Next(ids.Count)];
                    }
                    failures.Add(r);
                }
                break;
            }
            return(failures);
        }
示例#24
0
 public void IfDateEmptySuccess()
 {
     // ACT
     Fail.IfEmpty(DateTime.Today, nameof(DateTime.Today));
 }
示例#25
0
        public static ContestsUsersQuery Create(int contestId)
        {
            Fail.If(contestId <= 0);

            return(new ContestsUsersQuery(contestId));
        }
        public static bool IsNotEmpty <T>([NotNull] this IEnumerable <T> collection)
        {
            Fail.IfNull(collection, nameof(collection));

            return(collection.Any());
        }
        /// <summary>
        ///     Creates the installer for specified <see cref="Library" />.
        /// </summary>
        public MvcControllerInstaller([NotNull] Library library)
        {
            Fail.IfArgumentNull(library, nameof(library));

            this.library = library;
        }
示例#28
0
 protected override void NestedPackageFail(PackageResolverVisitor <IPackageInfo> newResolver)
 {
     base.NestedPackageFail(newResolver);
     Fail.AddRange(((LoggingPackageVisitor)newResolver).Fail);
     NotFound.AddRange(((LoggingPackageVisitor)newResolver).NotFound);
 }
示例#29
0
            public AutomappingConfiguration([NotNull] Type[] entities)
            {
                Fail.IfArgumentNull(entities, nameof(entities));

                this.entities = entities;
            }
        /// <summary>
        ///     Allows you to provide your library dependencies - libraries used by your library.
        /// </summary>
        protected Library([NotNull] params Library[] dependencies)
        {
            Fail.IfArgumentNull(dependencies, nameof(dependencies));

            this.Dependencies = dependencies;
        }
        private async Task<List<SiloHandle>> getSilosToFail(Fail fail, int numOfFailures)
        {
            List<SiloHandle> failures = new List<SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool usingReminderGrain = this.HostedCluster.Globals.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable tableGrain = GrainClient.GrainFactory.GetGrain<IReminderTableGrain>(Constants.ReminderTableGrainId);
            var tableGrainId = ((GrainReference)tableGrain).GrainId;
            SiloAddress reminderTableGrainPrimaryDirectoryAddress = (await TestUtils.GetDetailedGrainReport(tableGrainId, this.HostedCluster.Primary)).PrimaryForGrain;
            // ask a detailed report from the directory partition owner, and get the actionvation addresses
            var addresses = (await TestUtils.GetDetailedGrainReport(tableGrainId, this.HostedCluster.GetSiloForAddress(reminderTableGrainPrimaryDirectoryAddress))).LocalDirectoryActivationAddresses;
            ActivationAddress reminderGrainActivation = addresses.FirstOrDefault();

            SortedList<int, SiloHandle> ids = new SortedList<int, SiloHandle>();
            foreach (var siloHandle in this.HostedCluster.GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.SiloAddress;
                if (siloAddress.Equals(this.HostedCluster.Primary.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
                case Fail.First:
                    index = 0;
                    while (count++ < numOfFailures)
                    {
                        while (failures.Contains(ids.Values[index]))
                        {
                            index++;
                        }
                        failures.Add(ids.Values[index]);
                    }
                    break;
                case Fail.Last:
                    index = ids.Count - 1;
                    while (count++ < numOfFailures)
                    {
                        while (failures.Contains(ids.Values[index]))
                        {
                            index--;
                        }
                        failures.Add(ids.Values[index]);
                    }
                    break;
                case Fail.Random:
                default:
                    while (count++ < numOfFailures)
                    {
                        SiloHandle r = ids.Values[random.Next(ids.Count)];
                        while (failures.Contains(r))
                        {
                            r = ids.Values[random.Next(ids.Count)];
                        }
                        failures.Add(r);
                    }
                    break;
            }
            return failures;
        }
        /// <inheritdoc />
        public bool Equals(Library other)
        {
            Fail.IfArgumentNull(other, nameof(other));

            return(this.GetAssembly() == other.GetAssembly());
        }
示例#33
0
        public static ContestEndCommand Create(int contestId)
        {
            Fail.If(contestId <= 0);

            return(new ContestEndCommand(contestId));
        }
        private List<SiloHandle> getSilosToFail(Fail fail, int numOfFailures)
        {
            List<SiloHandle> failures = new List<SiloHandle>();
            int count = 0, index = 0;

            // Figure out the primary directory partition and the silo hosting the ReminderTableGrain.
            bool usingReminderGrain = Primary.Silo.GlobalConfig.ReminderServiceType.Equals(GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain);
            IReminderTable tableGrain = GrainClient.GrainFactory.GetGrain<IReminderTableGrain>(Constants.ReminderTableGrainId);
            SiloAddress reminderTableGrainPrimaryDirectoryAddress = Primary.Silo.LocalGrainDirectory.GetPrimaryForGrain(((GrainReference) tableGrain).GrainId);
            SiloHandle reminderTableGrainPrimaryDirectory = GetActiveSilos().Where(sh => sh.Silo.SiloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress)).FirstOrDefault();
            List<ActivationAddress> addresses = null;
            bool res = reminderTableGrainPrimaryDirectory.Silo.LocalGrainDirectory.LocalLookup(((GrainReference)tableGrain).GrainId, out addresses);
            ActivationAddress reminderGrainActivation = addresses.FirstOrDefault();

            SortedList<int, SiloHandle> ids = new SortedList<int, SiloHandle>();
            foreach (var siloHandle in GetActiveSilos())
            {
                SiloAddress siloAddress = siloHandle.Silo.SiloAddress;
                if (siloAddress.Equals(Primary.Silo.SiloAddress))
                {
                    continue;
                }
                // Don't fail primary directory partition and the silo hosting the ReminderTableGrain.
                if (usingReminderGrain)
                {
                    if (siloAddress.Equals(reminderTableGrainPrimaryDirectoryAddress) || siloAddress.Equals(reminderGrainActivation.Silo))
                    {
                        continue;
                    }
                }
                ids.Add(siloHandle.Silo.SiloAddress.GetConsistentHashCode(), siloHandle);
            }

            // we should not fail the primary!
            // we can't guarantee semantics of 'Fail' if it evalutes to the primary's address
            switch (fail)
            {
                case Fail.First:
                    index = 0;
                    while (count++ < numOfFailures)
                    {
                        while (failures.Contains(ids.Values[index]))
                        {
                            index++;
                        }
                        failures.Add(ids.Values[index]);
                    }
                    break;
                case Fail.Last:
                    index = ids.Count - 1;
                    while (count++ < numOfFailures)
                    {
                        while (failures.Contains(ids.Values[index]))
                        {
                            index--;
                        }
                        failures.Add(ids.Values[index]);
                    }
                    break;
                case Fail.Random:
                default:
                    while (count++ < numOfFailures)
                    {
                        SiloHandle r = ids.Values[random.Next(ids.Count)];
                        while (failures.Contains(r))
                        {
                            r = ids.Values[random.Next(ids.Count)];
                        }
                        failures.Add(r);
                    }
                    break;
            }
            return failures;
        }
示例#35
0
 public CompilationMockQueryHandler Returns(CompilationQueryResult result)
 {
     Fail.IfNull(_onQuery);
     _expectedBehaviors[_onQuery] = result;
     return(this);
 }
示例#36
0
        public static List<Limb> TransitionToV2 (Limb from, Analyzer.Node.Limb to, float cur_second) {
            if (!IsArcValid(from, to)) {
                throw new ArgumentException();
            }
            if (to == null) {
                throw new ArgumentException();
            }

            List<Limb> result = new List<Limb>();

            Limb nxt = new Limb();
            for (int i = 0; i < Limb.PART_COUNT; ++i) {
                Part part = PartHelper.TransitionTo(from[i], to[i], cur_second);
                nxt[i] = part;
            }
            if (to[Analyzer.Node.Limb.INDEX_EXTRA] == null) {
                nxt.extra = nxt.sub;
            }
            bool has_main = to.main != null;
            bool has_sub = to.sub != null;
            bool has_extra = to.extra != null;
            Fail fail = new Fail(nxt);
            if (has_main) {
                if (has_sub) {
                    if (has_extra) {
                        //main+sub+extra
                        if (fail.main_sub) {
                            //throw new ArgumentException();
                        }
                        if (fail.main_extra) {
                            //throw new ArgumentException();
                        }
                        if (fail.sub_extra) {
                            //throw new ArgumentException();
                        }
                    } else {
                        //main+sub
                        if (fail.main_sub) {
                            //throw new ArgumentException();
                        }
                        if (fail.main_extra) {
                            nxt.extra = nxt.sub;
                            fail = new Fail(nxt);
                        }
                        if (fail.sub_extra) {
                            nxt.extra = nxt.sub;
                            fail = new Fail(nxt);
                        }
                    }
                } else if (has_extra) {
                    //main+extra
                    if (fail.main_sub) {
                        nxt.sub = nxt.extra;
                        fail = new Fail(nxt);
                    }
                    if (fail.main_extra) {
                        //throw new ArgumentException();
                    }
                    if (fail.sub_extra) {
                        nxt.sub = nxt.extra;
                        fail = new Fail(nxt);
                    }
                } else {
                    //main
                    if (fail.main_sub) {
                        List<Panel> neighbours = Panel.Neighbours_1D[nxt.main.panel.index];
                        foreach (Panel n in neighbours) {
                            Limb copy = Limb.DirectCopy(nxt);
                            Part src = copy.sub;
                            copy.sub = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );

                            Fail copy_fail = new Fail(copy);
                            if (copy_fail.main_extra) {
                                copy.extra = copy.sub;
                            }
                            AddIfValid(result, copy);
                        }
                    }
                    if (fail.main_extra) {
                        nxt.extra = nxt.sub;
                        fail = new Fail(nxt);
                    }
                    if (fail.sub_extra) {
                        //throw new ArgumentException();
                    }
                }
            } else if (has_sub) {
                if (has_extra) {
                    //sub+extra
                    if (fail.main_sub) {
                        List<Panel> neighbours = Panel.Neighbours_1D[nxt.sub.panel.index];
                        foreach (Panel n in neighbours) {
                            Limb copy = Limb.DirectCopy(nxt);
                            Part src = copy.main;
                            copy.main = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );

                            Fail copy_fail = new Fail(copy);
                            if (copy_fail.main_extra) {
                                List<Panel> neighbours_2 = Panel.Neighbours_1D[nxt.extra.panel.index];
                                foreach (Panel n_2 in neighbours_2) {
                                    Limb copy_2 = Limb.DirectCopy(copy);
                                    Part src_2 = copy_2.main;
                                    copy_2.main = new Part(
                                        Movement.Unknown,
                                        n_2,
                                        src_2.cur_second,
                                        cur_second,
                                        src_2.cur_moved_second == cur_second ?
                                            src_2.prv_moved_second : src_2.cur_moved_second
                                    );
                                    AddIfValid(result, copy_2);
                                }
                            }
                            AddIfValid(result, copy);
                        }
                    }
                    if (fail.main_extra) {
                        List<Panel> neighbours_2 = Panel.Neighbours_1D[nxt.extra.panel.index];
                        foreach (Panel n_2 in neighbours_2) {
                            Limb copy_2 = Limb.DirectCopy(nxt);
                            Part src_2 = copy_2.main;
                            copy_2.main = new Part(
                                Movement.Unknown,
                                n_2,
                                src_2.cur_second,
                                cur_second,
                                src_2.cur_moved_second == cur_second ?
                                    src_2.prv_moved_second : src_2.cur_moved_second
                            );
                            AddIfValid(result, copy_2);
                        }
                    }
                    if (fail.sub_extra) {
                        //throw new ArgumentException();
                    }
                } else {
                    //sub
                    if (fail.main_sub) {
                        List<Panel> neighbours = Panel.Neighbours_1D[nxt.sub.panel.index];
                        foreach (Panel n in neighbours) {
                            Limb copy = Limb.DirectCopy(nxt);
                            Part src = copy.main;
                            copy.main = new Part(
                                Movement.Unknown,
                                n,
                                src.cur_second,
                                cur_second,
                                src.cur_moved_second == cur_second ?
                                    src.prv_moved_second : src.cur_moved_second
                            );

                            Fail copy_fail = new Fail(copy);
                            if (copy_fail.main_extra) {
                                //do nothing
                            }
                            if (copy_fail.sub_extra) {
                                copy.extra = copy.sub;
                            }
                            AddIfValid(result, copy);
                        }
                    }
                    if (fail.main_extra) {
                        //throw new ArgumentException();
                    }
                    if (fail.sub_extra) {
                        nxt.extra = nxt.sub;
                    }
                }
            } else if (has_extra) {
                //extra
                if (fail.main_sub) {
                    //throw new ArgumentException();
                }
                if (fail.main_extra) {
                    List<Panel> neighbours = Panel.Neighbours_1D[nxt.extra.panel.index];
                    foreach (Panel n in neighbours) {
                        Limb copy = Limb.DirectCopy(nxt);
                        Part src = copy.main;
                        copy.main = new Part(
                            Movement.Unknown,
                            n,
                            src.cur_second,
                            cur_second,
                            src.cur_moved_second == cur_second ?
                                src.prv_moved_second : src.cur_moved_second
                        );

                        Fail copy_fail = new Fail(copy);
                        if (copy_fail.sub_extra) {
                            copy.sub = copy.extra;
                        }
                        AddIfValid(result, copy);
                    }
                }
                if (fail.sub_extra) {
                    nxt.sub = nxt.extra;
                }
            } else {
                //NOTHING
                if (fail.main_sub) {
                    //throw new ArgumentException();
                }
                if (fail.main_extra) {
                    //throw new ArgumentException();
                }
                if (fail.sub_extra) {
                    //throw new ArgumentException();
                }
            }
            AddIfValid(result, nxt);
            return result;
        }
        /// <inheritdoc />
        public void Store(T value)
        {
            Fail.IfArgumentNull(value, nameof(value));

            StaticContextStorage <T> .storedValue = value;
        }
示例#38
0
 public void IfEqualSuccess()
 {
     // ACT
     Fail.IfEqual("s1", "s2", "values are equal and shouldn't be");
 }
        private HttpResponse GetResponse()
        {
            Fail.IfFalse(this.IsAvailable(), Violation.Of("HttpContext.Current.Response is not available."));

            return(HttpContext.Current.Response);
        }
示例#40
0
 private static void AddIfValid (List<Limb> list, Limb item) {
     Fail fail = new Fail(item);
     if (fail.main_sub || fail.main_extra || fail.sub_extra) {
         return;
     }
     item.sanityCheck();
     list.Add(item);
 }