Пример #1
0
            /// <summary>
            /// Tests equality between placements
            /// </summary>
            /// <param name="that">other placement</param>
            /// <returns></returns>
            public override bool Equals(Placement that)
            {
                RoundRobin other = that as RoundRobin;

                return(this == other ||
                       (other != null && this.numProcs == other.numProcs && this.numThreads == other.numThreads));
            }
        public override async Task BuildWorkerTopology()
        {
            //build backward
            //2-layer
            operatorGrains = Enumerable.Range(0, 2).Select(x => new List <IWorkerGrain>()).ToList();
            //last layer
            IWorkerGrain finalGrain = this.GrainFactory.GetGrain <ICountFinalOperatorGrain>(this.GetPrimaryKey(), "final");

            operatorGrains[1].Add(finalGrain);
            //first layer
            ISendStrategy strategy = new RoundRobin(new List <IWorkerGrain> {
                finalGrain
            });

            for (int i = 0; i < DefaultNumGrainsInOneLayer; ++i)
            {
                IWorkerGrain grain = this.GrainFactory.GetGrain <ICountOperatorGrain>(this.GetPrimaryKey(), i.ToString());
                await grain.SetSendStrategy(this.GetPrimaryKey(), strategy);

                operatorGrains[0].Add(grain);
            }
            //set target end flag
            await finalGrain.SetInputInformation(new Dictionary <string, int> {
                { this.GetPrimaryKeyString(), DefaultNumGrainsInOneLayer }
            });
        }
Пример #3
0
        static void Main(string[] args)
        {
            var threadId    = 1;
            var someNumbers = new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var roundRobin  = new RoundRobin <int?>(someNumbers);

            var numThreads = Environment.ProcessorCount - 1;

            // Mangler en <.ToNullable>!!!
            //
            ThreadPool.QueueUserWorkItem(
                (x) => {
                var currentThread = threadId;
                Interlocked.Increment(ref threadId);

                var data        = x as RoundRobin <int>;
                var currentData = new Nullable <int>();

                while ((currentData = data.Get()) != null)
                {
                    Console.WriteLine("Thread {0} got data {1}'", currentThread, currentData);
                }
            }, roundRobin);

            Console.ReadKey();
        }
Пример #4
0
        static void Main(string[] args)
        {
            var threadId = 1;
            var someNumbers = new int?[] { 1,2,3,4,5,6,7,8,9,10 };
            var roundRobin = new RoundRobin<int?>(someNumbers);

            var numThreads = Environment.ProcessorCount - 1;

            // Mangler en <.ToNullable>!!!
            //
            ThreadPool.QueueUserWorkItem(
                (x) => {
                    var currentThread = threadId;
                    Interlocked.Increment(ref threadId);

                    var data = x as RoundRobin<int>;
                    var currentData = new Nullable<int>();

                    while((currentData = data.Get()) != null)
                    {
                        Console.WriteLine("Thread {0} got data {1}'", currentThread, currentData);
                    }

                }, roundRobin);

            Console.ReadKey();
        }
Пример #5
0
        public void RoundRobinOfValueType_ShouldReturnDefault_WhenEmpty()
        {
            var sut    = new RoundRobin <int>();
            var result = sut.Get();

            Assert.Equal(0, result);
        }
Пример #6
0
            public void Configure(IApplicationBuilder app)
            {
                var roundRobin = new RoundRobin
                {
                    new UpstreamHost("http://localhost:5001", weight: 1),
                    new UpstreamHost("http://localhost:5002", weight: 2)
                };

                app.RunProxy(
                    async context =>
                {
                    var host = roundRobin.Next();

                    var response = await context
                                   .ForwardTo(host)
                                   .ApplyXForwardedHeaders()
                                   .Execute();

                    // failover
                    if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        return(await context
                               .ForwardTo(host)
                               .ApplyXForwardedHeaders()
                               .Execute());
                    }

                    return(response);
                });
            }
Пример #7
0
        public void RoundRobinOfReferenceType_ShouldReturnNull_WhenEmpty()
        {
            var sut    = new RoundRobin <string>();
            var result = sut.Get();

            Assert.Null(result);
        }
Пример #8
0
        public override async Task Link()
        {
            List <IWorkerGrain> isolated = new List <IWorkerGrain>();

            foreach (var pair in to.Layer)
            {
                if (!from.Layer.ContainsKey(pair.Key))
                {
                    isolated.AddRange(pair.Value);
                }
            }
            foreach (var pair in from.Layer)
            {
                ISendStrategy strategy = new RoundRobin(batchSize);
                if (to.Layer.ContainsKey(pair.Key))
                {
                    strategy.AddReceivers(to.Layer[pair.Key], true);
                    strategy.AddReceivers(isolated);
                }
                else
                {
                    strategy.AddReceivers(to.Layer.Values.SelectMany(x => x).ToList());
                }
                foreach (IWorkerGrain grain in pair.Value)
                {
                    await grain.SetSendStrategy(id, strategy);
                }
            }
        }
Пример #9
0
        private void Execute()
        {
            IREST <T>         _rest;
            Func <IREST <T> > _command;

            T   _response = null;
            int _retries;
            int _secDelay;

            //get all registered providers
            RoundRobin <string> rr = new RoundRobin <string>(GeneralSettings.roundRobin[0].direction);

            if (GeneralSettings.roundRobin[0].direction != RoundRobin <T> .FIXED)
            {
                foreach (var p in providers)
                {
                    rr.Add(p.Key);
                }
            }

            //retrieve and update geocode, one rec at a time
            foreach (T rec in source().RecordSet)
            {
                _rest     = null;
                _command  = null;
                _response = null;

                while (_response == null)
                {
                    providers.TryGetValue(provider, out _command);
                    _rest     = _command();                                                     //hydrate instantiation
                    _retries  = GeneralSettings.retry[0].numOfRetries;
                    _secDelay = GeneralSettings.retry[0].secondsDelay * Constants.MILLISECONDS; //convert to miliseconds
                    while (_response == null && _retries != 0)                                  //TODO: actually, _response won't be null, but an error bubbled up from Get method
                    {
                        _response = _rest.GetDataAsync(rec);                                    //retrieve rec's from 3rd party
                        //_response = null; //test
                        if (_response != null)
                        {
                            break;
                        }
                        else
                        {
                            _retries--;
                            Thread.Sleep(_secDelay);
                        }
                    }

                    // _retries = 0; //test
                    if (_response == null && _retries == 0 && rr.MethodName != RoundRobin <T> .FIXED)
                    {
                        rr.Move();
                        provider = rr.Current;
                    }
                }

                target().Save(_response);  //update local db with newly retrieved values
            }
        }
Пример #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            RoundRobin robin = new RoundRobin(seasonID);

            this.Close();

            //RoundRobin robin = new RoundRobin(1);
        }
Пример #11
0
 private void DoProcessJob(RoundRobin working, Thread workingThread)
 {
     // used lock to prevent interruption from other threads
     lock (lockObj)
     {
         BeginProcess(working, workingThread);
     }
 }
Пример #12
0
        public void WriteRoundRobinOfQueues()
        {
            var queue1        = new Queue("Queue1", new Project("Project1"), new Project("Project2"));
            var queue2        = new Queue("Queue2", new Project("Project3"), new Project("Project4"));
            var configuration = new RoundRobin("RoundRobin", queue1, queue2);

            PerformSerialisationTest(configuration, "RoundRobinOfQueues");
        }
        public void RunRR()
        {
            timeQuantum = int.Parse(textBoxTimeQuantum.Text);
            RoundRobin RR = new RoundRobin(processesRR, CPU_Count, timeQuantum);

            RR.AlgorithmStart();
            pipelinesRR = RR.MultiCorePipeline;
            totalTimeRR = RR.PipelinesTotalTime;
        }
Пример #14
0
        public void TestEmpty()
        {
            var rr = new RoundRobin <int>(10);

            Assert.AreEqual(0, rr.Count);
            foreach (int item in rr)
            {
                Assert.Fail("Enumeration returned values.");
            }
        }
Пример #15
0
        public void TestRemoveNotSupported()
        {
            var rr = new RoundRobin <int>(10)
            {
                123,
                456
            };

            Assert.ThrowsException <NotSupportedException>(() => rr.Remove(123));
        }
Пример #16
0
        public JsonResult RoundRobin(List <int> values)
        {
            var daocalender = new CalendarDao();
            var robin       = new RoundRobin();

            robin.ListMatches(values);
            var model = daocalender.ListAll();

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Пример #17
0
        public void TestToArray()
        {
            var rr = new RoundRobin <int>(10);

            for (int i = 0; i < 15; i++)
            {
                rr.Add(i);
            }
            CollectionAssert.AreEqual(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, rr.ToArray());
        }
Пример #18
0
        public void TestOverfill()
        {
            var rr = new RoundRobin <int>(10);

            for (int i = 0; i < 15; i++)
            {
                rr.Add(i);
            }
            Assert.AreEqual(10, rr.Count);
            CollectionAssert.AreEqual(new int[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, rr);
        }
Пример #19
0
        public void RoundRobin_ShouldReturnTheOnlyEntry()
        {
            const string theOnlyOne = "theOnlyOne";

            var sut = new RoundRobin <string>();

            sut.Add(theOnlyOne);
            var result = sut.Get();

            Assert.Equal(theOnlyOne, result);
        }
Пример #20
0
 private void IsJobLeft(RoundRobin model, Thread modelThread, Queue <RoundRobin> queueOfModel, Queue <Thread> queueOfThreads)
 {
     // We are checking if we have done our time sliced job, but yet, we are not completely done (we need more time slices)
     // Putting the model at the end of model queue, also put the Model Thread which handle our model at the end of  ModelThreads queue.
     if (model.getIsInitialized() && !model.IsProcessComplete())
     {
         queueOfModel.Enqueue(model);
         queueOfThreads.Enqueue(modelThread);
         Console.WriteLine("File writing process exceed the time quantum: " + model.getTimeQuantum() + " milliseconds, Enqueuing process of file: " + model.getFileName() + "\n");
     }
 }
Пример #21
0
        public RoundRobinTests()
        {
            _services = new List <Service>
            {
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5000), string.Empty, string.Empty, new string[0]),
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5001), string.Empty, string.Empty, new string[0]),
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5001), string.Empty, string.Empty, new string[0])
            };

            _roundRobin = new RoundRobin(() => Task.FromResult(_services));
        }
Пример #22
0
        public void TestPartialFill()
        {
            var rr = new RoundRobin <int>(10);

            for (int i = 0; i < 5; i++)
            {
                rr.Add(i);
            }

            Assert.AreEqual(5, rr.Count);
            CollectionAssert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, rr);
        }
Пример #23
0
        public void CreateAutoGeneratedFixtureRoundRobin()
        {
            login.CreateSession("sSanchez", "user");
            FixtureServices fixtureServices = new FixtureServices(login, encounterRepo, sportRepo, teamRepo, assemblyLoader, commentRepo);

            fixtureServices.CreateFixture("RoundRobin", "Futbol", new DateTime(3000, 10, 10));

            IEnumerable <Encounter> expected = new RoundRobin().GenerateFixture(teamRepo.GetAll(), new DateTime(3000, 10, 10));
            IEnumerable <Encounter> actual   = encounterRepo.GetAll();

            Assert.AreEqual(expected.Count(), actual.Count());
        }
Пример #24
0
        public void Returns_Repeating_Sequence_When_Called_Repeatedly()
        {
            var sequence = new[] { 10, 20, 30 };
            var cut      = new RoundRobin <int>(sequence);

            cut.GetNextItem().ShouldBe(10);
            cut.GetNextItem().ShouldBe(20);
            cut.GetNextItem().ShouldBe(30);
            cut.GetNextItem().ShouldBe(10);
            cut.GetNextItem().ShouldBe(20);
            cut.GetNextItem().ShouldBe(30);
        }
Пример #25
0
        public void TestRoundRobin()
        {
            var bursts1 = new List <BurstCycle> {
                new BurstCycle {
                    CpuBurstTime = 10, IoBurstTime = 15
                }, new BurstCycle {
                    CpuBurstTime = 4, IoBurstTime = 6
                }
            };
            var bursts2 = new List <BurstCycle> {
                new BurstCycle {
                    CpuBurstTime = 8, IoBurstTime = 6
                }, new BurstCycle {
                    CpuBurstTime = 7, IoBurstTime = 0
                }
            };
            var bursts3 = new List <BurstCycle> {
                new BurstCycle {
                    CpuBurstTime = 15, IoBurstTime = 4
                }, new BurstCycle {
                    CpuBurstTime = 8, IoBurstTime = 0
                }
            };
            var process1 = new Process(bursts1)
            {
                ArrivalTime = 0
            };
            var process2 = new Process(bursts2)
            {
                ArrivalTime = 3
            };
            var process3 = new Process(bursts3)
            {
                ArrivalTime = 10
            };

            var processLoad = new ProcessLoad
            {
                Processes = new List <Process>
                {
                    process1,
                    process2,
                    process3,
                }
            };

            var scheduler = new RoundRobin(processLoad, 4);
            var io        = new Io();
            var cpu       = new Cpu();

            var result = this.ProcessDispatcher.Start(scheduler, cpu, io);
        }
Пример #26
0
        public RoundRobinTests()
        {
            _context = new DownstreamContext(new DefaultHttpContext());

            _services = new List <Service>
            {
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5000), string.Empty, string.Empty, new string[0]),
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5001), string.Empty, string.Empty, new string[0]),
                new Service("product", new ServiceHostAndPort("127.0.0.1", 5001), string.Empty, string.Empty, new string[0])
            };

            _roundRobin = new RoundRobin(() => Task.FromResult(_services));
        }
Пример #27
0
        public void SampleAutoRoundRobinFixtureWithTheSameTeamTest()
        {
            List <Team> teams = new List <Team>()
            {
                felix, liverpool, river, cerro, penhiarol, torque, cerro
            };

            DateTime start = new DateTime(3018, 10, 07);

            IFixtureGenerator leagueFixture = new RoundRobin();

            List <Encounter> result = leagueFixture.GenerateFixture(teams, start).ToList();
        }
Пример #28
0
        public void RoundRobin_ShouldReturnDefaultWhenCleared()
        {
            const string firstEntry  = "entry1";
            const string secondEntry = "entry2";
            const string thirdEntry  = "entry3";

            var sut = new RoundRobin <string> {
                firstEntry, secondEntry, thirdEntry
            };

            sut.Clear();
            Assert.Null(sut.Get());
        }
Пример #29
0
        public void RoundRobin_ShouldReturnNextWhenNotExistingEntryRemoved()
        {
            const string firstEntry       = "entry1";
            const string secondEntry      = "entry2";
            const string notExistingEntry = "fakeEntry";

            var sut = new RoundRobin <string> {
                firstEntry, secondEntry
            };

            sut.Remove(notExistingEntry);
            Assert.Equal(firstEntry, sut.Get());
        }
Пример #30
0
        public void RoundRobin_ShouldReturnTheOnlyEntryMultipleTimes()
        {
            const string theOnlyOne = "theOnlyOne";

            var sut = new RoundRobin <string>();

            sut.Add(theOnlyOne);

            Assert.Equal(theOnlyOne, sut.Get());
            Assert.Equal(theOnlyOne, sut.Get());
            Assert.Equal(theOnlyOne, sut.Get());
            Assert.Equal(theOnlyOne, sut.Get());
        }
Пример #31
0
        public void TestICollectionCopyTo()
        {
            ICollection rr = new RoundRobin <int>(10)
            {
                123,
                456
            };

            int[] res = new int[2];

            rr.CopyTo(res, 0);
            CollectionAssert.AreEqual(new int[] { 123, 456 }, res);
        }
        protected override void RegisterComponents(PoorMansIoC container)
        {
            container.RegisterType<AzureServiceBusTransport>(ComponentLifetime.SingleInstance, typeof (INimbusTransport));

            container.RegisterType<BrokeredMessageFactory>(ComponentLifetime.SingleInstance, typeof (IBrokeredMessageFactory));
            container.RegisterType<NamespaceCleanser>(ComponentLifetime.SingleInstance);
            container.RegisterType<AzureQueueManager>(ComponentLifetime.SingleInstance, typeof (IQueueManager));
            container.RegisterType<DelayedDeliveryService>(ComponentLifetime.SingleInstance, typeof (IDelayedDeliveryService));
            container.RegisterType<AzureServiceBusDeadLetterOffice>(ComponentLifetime.SingleInstance, typeof (IDeadLetterOffice));
            container.RegisterType<NamespaceCleanser>(ComponentLifetime.SingleInstance, typeof (INamespaceCleanser));
            container.RegisterType<SqlFilterExpressionGenerator>(ComponentLifetime.SingleInstance, typeof(ISqlFilterExpressionGenerator));

            container.Register(c =>
                               {
                                   var namespaceManagerRoundRobin = new RoundRobin<NamespaceManager>(
                                       c.Resolve<ServerConnectionCountSetting>(),
                                       () =>
                                       {
                                           var namespaceManager = NamespaceManager.CreateFromConnectionString(c.Resolve<ConnectionStringSetting>());
                                           namespaceManager.Settings.OperationTimeout = c.Resolve<DefaultTimeoutSetting>();
                                           return namespaceManager;
                                       },
                                       nsm => false,
                                       nsm => { });

                                   return namespaceManagerRoundRobin;
                               },
                               ComponentLifetime.SingleInstance);

            container.Register<Func<NamespaceManager>>(c => c.Resolve<RoundRobin<NamespaceManager>>().GetNext, ComponentLifetime.InstancePerDependency);

            container.Register(c =>
                               {
                                   var messagingFactoryRoundRobin = new RoundRobin<MessagingFactory>(
                                       container.Resolve<ServerConnectionCountSetting>(),
                                       () =>
                                       {
                                           var messagingFactory = MessagingFactory.CreateFromConnectionString(c.Resolve<ConnectionStringSetting>());
                                           messagingFactory.PrefetchCount = c.Resolve<ConcurrentHandlerLimitSetting>();
                                           return messagingFactory;
                                       },
                                       mf => mf.IsBorked(),
                                       mf => mf.Dispose());

                                   return messagingFactoryRoundRobin;
                               },
                               ComponentLifetime.SingleInstance);

            container.Register<Func<MessagingFactory>>(c => c.Resolve<RoundRobin<MessagingFactory>>().GetNext, ComponentLifetime.InstancePerDependency);
        }
Пример #33
0
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;
            logger.Debug("Constructing bus...");

            var container = new PoorMansIoC();

            RegisterPropertiesFromConfigurationObject(container, configuration);
            RegisterPropertiesFromConfigurationObject(container, configuration.LargeMessageStorageConfiguration);
            RegisterPropertiesFromConfigurationObject(container, configuration.Debugging);

            var namespaceManagerRoundRobin = new RoundRobin<NamespaceManager>(
                container.Resolve<ServerConnectionCountSetting>(),
                () =>
                {
                    var namespaceManager = NamespaceManager.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
                    namespaceManager.Settings.OperationTimeout = TimeSpan.FromSeconds(120);
                    return namespaceManager;
                },
                nsm => false,
                nsm => { });

            container.Register<Func<NamespaceManager>>(c => namespaceManagerRoundRobin.GetNext);

            var messagingFactoryRoundRobin = new RoundRobin<MessagingFactory>(
                container.Resolve<ServerConnectionCountSetting>(),
                () =>
                {
                    var messagingFactory = MessagingFactory.CreateFromConnectionString(container.Resolve<ConnectionStringSetting>());
                    messagingFactory.PrefetchCount = container.Resolve<ConcurrentHandlerLimitSetting>();
                    return messagingFactory;
                },
                mf => mf.IsBorked(),
                mf => { });

            container.Register<Func<MessagingFactory>>(c => messagingFactoryRoundRobin.GetNext);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                var namespaceCleanser = container.Resolve<NamespaceCleanser>();
                namespaceCleanser.RemoveAllExistingNamespaceElements().Wait();
            }

            logger.Debug("Creating message pumps...");

            var messagePumps = new MessagePumpsManager(
                container.Resolve<ResponseMessagePumpFactory>().Create(),
                container.Resolve<RequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<CommandMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastRequestMessagePumpsFactory>().CreateAll(),
                container.Resolve<MulticastEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<CompetingEventMessagePumpsFactory>().CreateAll(),
                container.Resolve<INimbusTaskFactory>());

            logger.Debug("Message pumps are all created.");

            var bus = new Bus(container.Resolve<ILogger>(),
                              container.Resolve<ICommandSender>(),
                              container.Resolve<IRequestSender>(),
                              container.Resolve<IMulticastRequestSender>(),
                              container.Resolve<IEventSender>(),
                              messagePumps,
                              container.Resolve<DeadLetterQueues>(),
                              container.Resolve<INimbusTaskFactory>(),
                              container.Resolve<IHeartbeat>());

            bus.Starting += delegate
                            {
                                container.Resolve<AzureQueueManager>().WarmUp();
                                container.Resolve<PropertyInjector>().Bus = bus;
                            };
            bus.Disposing += delegate { container.Dispose(); };

            logger.Info("Bus built. Job done!");

            return bus;
        }