Ejemplo n.º 1
0
        public async Task PublishAsync_LimitedParallelDelegateSubscription_ProcessingInParallel()
        {
            var parallel = new ParallelTestingUtil();

            var publisher = GetPublisher(config =>
                                         config
                                         .Subscribe <ICommand>(
                                             (ICommand _) => parallel.DoWork(),
                                             new SubscriptionOptions {
                Parallel = true, MaxDegreeOfParallelism = 2
            })
                                         .Subscribe <ICommand>(
                                             async(ICommand _) => await parallel.DoWorkAsync(),
                                             new SubscriptionOptions {
                Parallel = true, MaxDegreeOfParallelism = 2
            }));

            await publisher.PublishAsync(new ICommand[]
            {
                new TestCommandOne(),
                new TestCommandTwo(),
                new TestCommandOne(),
            });

            parallel.Steps.Should().BeEquivalentTo(1, 1, 3, 4, 4, 6);
        }
Ejemplo n.º 2
0
        public void Publish_ParallelDelegateSubscription_ProcessingInParallel()
        {
            var parallel = new ParallelTestingUtil();

            var publisher = GetPublisher(config =>
                                         config
                                         .Subscribe <ICommand>(
                                             (ICommand _) => parallel.DoWork(),
                                             new SubscriptionOptions {
                Parallel = true
            })
                                         .Subscribe <ICommand>(
                                             async(ICommand _) => await parallel.DoWorkAsync(),
                                             new SubscriptionOptions {
                Parallel = true
            }));

            publisher.Publish(new ICommand[]
            {
                new TestCommandOne(),
                new TestCommandTwo(),
            });

            parallel.Steps.Should().BeEquivalentTo(1, 1, 3, 3);
        }
Ejemplo n.º 3
0
        public void Publish_ExclusiveDelegateSubscription_SequentiallyInvoked()
        {
            var parallel = new ParallelTestingUtil();

            var publisher = GetPublisher(config =>
                                         config
                                         .Subscribe <ICommand>(
                                             (ICommand _) => parallel.DoWork())
                                         .Subscribe <ICommand>(
                                             async(ICommand _) => await parallel.DoWorkAsync(),
                                             new SubscriptionOptions {
                Exclusive = true
            }));

            publisher.Publish(new TestCommandOne());

            parallel.Steps.Should().BeEquivalentTo(1, 2);
        }
        public async Task Publish_ToExclusiveDelegateSubscribers_SequentiallyInvoked()
        {
            var parallel        = new ParallelTestingUtil();
            var serviceProvider = ServiceProviderHelper.GetServiceProvider(
                services => services
                .AddFakeLogger()
                .AddSilverback()
                .AddDelegateSubscriber((ICommand _) => parallel.DoWork())
                .AddDelegateSubscriber(
                    async(ICommand _) => await parallel.DoWorkAsync(),
                    new SubscriptionOptions {
                Exclusive = true
            }));
            var publisher = serviceProvider.GetRequiredService <IPublisher>();

            publisher.Publish(new TestCommandOne());
            await publisher.PublishAsync(new TestCommandOne());

            parallel.Steps.Should().BeEquivalentTo(1, 2, 3, 4);
        }
Ejemplo n.º 5
0
        public void Publish_NonExclusiveDelegateSubscription_InvokedInParallel()
        {
            var parallel = new ParallelTestingUtil();

            var publisher = GetPublisher(config =>
                                         config
                                         .Subscribe <ICommand>(
                                             (ICommand _) => parallel.DoWork(),
                                             new SubscriptionOptions {
                Exclusive = false
            })
                                         .Subscribe <ICommand>(
                                             (ICommand _) => parallel.DoWorkAsync(),
                                             new SubscriptionOptions {
                Exclusive = false
            }));

            publisher.Publish(new TestCommandOne());

            parallel.Steps.Should().BeEquivalentTo(1, 1);
        }