Example #1
0
        private KeyValuePair <int, long>[][] StartTwWithCacheBatch()
        {
            var outputModels = new KeyValuePair <int, long> [ITERATION_CNT / BATCH_KEYS_CNT][];
            var builder      = new TwContainerBuilder();
            var container    = builder
                               .AddAssemblies(typeof(OtherComponents.CacheBatchTest.SlowProducerComponent).Assembly)
                               .AddNamespaces(typeof(OtherComponents.CacheBatchTest.SlowProducerComponent).Namespace)
                               .BuildWithCacheBatch <int, long>(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1));

            var iterations = ITERATION_CNT / BATCH_KEYS_CNT;
            var tasks      = new Task <IEnumerable <KeyValuePair <int, long> > > [iterations];

            for (var i = 0; i < ITERATION_CNT; i += BATCH_KEYS_CNT)
            {
                var key = i % KEYS_CNT;
                if (key == 0)
                {
                    Task.Delay(500).Wait();
                }

                tasks[i / BATCH_KEYS_CNT] = Task.Run(() => container.Run(Enumerable.Range(key, BATCH_KEYS_CNT)).AsTask());
            }
            for (var i = 0; i < iterations; i++)
            {
                outputModels[i] = tasks[i].Result.ToArray();
            }

            return(outputModels);
        }
Example #2
0
        private long[] StartTwWithCache()
        {
            var outputModels = new long[ITERATION_CNT];
            var builder      = new TwContainerBuilder();
            var container    = builder
                               .AddAssemblies(typeof(OtherComponents.CacheTest.SlowProducerComponent).Assembly)
                               .AddNamespaces(typeof(OtherComponents.CacheTest.SlowProducerComponent).Namespace)
                               .BuildWithCache <int, long>(TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1));

            var tasks = new Task <long> [ITERATION_CNT];

            for (var i = 0; i < ITERATION_CNT; i++)
            {
                var key = i % KEYS_CNT;
                if (key == 0)
                {
                    Task.Delay(500).Wait();
                }
                tasks[i] = Task.Run(() => container.Run(key).AsTask());
            }
            for (var i = 0; i < ITERATION_CNT; i++)
            {
                outputModels[i] = tasks[i].Result;
            }

            return(outputModels);
        }
Example #3
0
        public MainBenchmark()
        {
            _resolver = new Resolver();
            var builder = new TwContainerBuilder();

            _container = builder
                         .AddAssemblies(typeof(SingleComponent).Assembly)
                         .AddNamespaces("TypedWorkflowTests.Components")
                         .RegisterExternalDi(_resolver)
                         .Build();
        }
Example #4
0
        public void WithInputAndOutput()
        {
            var componentType = typeof(TypedWorkflowTests.OtherComponents.AsyncCancellationTest.WithInputAndOutput.LongTimeExecutionComponent);
            var builder       = new TwContainerBuilder();
            var container     = builder
                                .AddAssemblies(componentType.Assembly)
                                .AddNamespaces(componentType.Namespace)
                                .Build <int, long>();

            var cancellation = new CancellationTokenSource();
            var t            = container.Run(-1, cancellation.Token).AsTask();

            Task.Delay(500).Wait();

            cancellation.Cancel();

            var ex = Assert.CatchAsync <TaskCanceledException>(() => t);
        }
Example #5
0
        public BasicTest()
        {
            var resolver  = new Resolver();
            var builder   = new TwContainerBuilder();
            var container = builder
                            .AddAssemblies(typeof(SingleComponent).Assembly)
                            .AddNamespaces("TypedWorkflowTests.Components")
                            .RegisterExternalDi(resolver)
                            .Build();

            var tasks = Enumerable.Range(0, ITERATION_CNT).Select(i => Task.Run(() => container.Run().AsTask())).ToArray();

            //var tasks = Enumerable.Range(0, ITERATION_CNT).Select(i => Task.Run(() => DecompositionRunner.Run(resolver).AsTask())).ToArray();
            Task.WaitAll(tasks);

            _resolveCnt             = resolver.ResolveCount;
            _createScopeResolverCnt = resolver.CreateScopeCnt;
            _serviceResult          = resolver.Sb.ToString();
        }
Example #6
0
        public SimpleInputTest()
        {
            var builder   = new TwContainerBuilder();
            var container = builder
                            .AddAssemblies(typeof(ConsumingInputArgComponent).Assembly)
                            .AddNamespaces("TypedWorkflowTests.OtherComponents.SimpleInputTest")
                            .Build <InputModel>();

            var tasks = new Task[ITERATION_CNT];

            for (var i = 0; i < ITERATION_CNT; i++)
            {
                _inputModels[i] = new InputModel {
                    SomeProp = i
                };
                var input = _inputModels[i];
                tasks[i] = Task.Run(() => container.Run(input).AsTask());
            }
            Task.WaitAll(tasks);
        }
Example #7
0
        public CompositeInputTest()
        {
            var builder   = new TwContainerBuilder();
            var container = builder
                            .AddAssemblies(typeof(ConsumingInputArgComponent).Assembly)
                            .AddNamespaces("TypedWorkflowTests.OtherComponents.CompositeInputTest")
                            .Build <(InputModel1, InputModel2)>();

            var tasks = new Task[ITERATION_CNT];

            for (var i = 0; i < ITERATION_CNT; i++)
            {
                var input = (new InputModel1 {
                    SomeProp = i
                }, new InputModel2 {
                    SomeProp = ITERATION_CNT + i
                });
                _inputModels[i] = input;
                tasks[i]        = Task.Run(() => container.Run(input).AsTask());
            }
            Task.WaitAll(tasks);
        }