示例#1
0
 public override IPublisher <int> CreatePublisher(long elements)
 {
     return(Flowable.Range(1, (int)elements)
            .FlatMap(v => v == 1 ? Flowable.Just(v) : Flowable.FromArray(v, v - 1))
            .Distinct()
            .Filter(v => true));
 }
示例#2
0
        public void Shared()
        {
            IExecutorService[] execs = { Executors.Single, Executors.Computation, Executors.IO };
            foreach (var exec in execs)
            {
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Flowable.Just(1).SubscribeOn(exec)
                        .Test()
                        .WithTag("SubscribeOn round " + i + "/" + j + " - " + exec.GetType().Name)
                        .AwaitDone(TimeSpan.FromSeconds(5))
                        .AssertResult(1);

                        Flowable.Just(1).Delay(TimeSpan.FromMilliseconds(10))
                        .Test()
                        .WithTag("Delay round " + i + "/" + j + " - " + exec.GetType().Name)
                        .AwaitDone(TimeSpan.FromSeconds(5))
                        .AssertResult(1);

                        Flowable.Interval(TimeSpan.FromMilliseconds(10))
                        .Take(5)
                        .Test()
                        .WithTag("Interval round " + i + "/" + j + " - " + exec.GetType().Name)
                        .AwaitDone(TimeSpan.FromSeconds(5))
                        .AssertResult(0L, 1L, 2L, 3L, 4L);
                    }
                }
            }
        }
示例#3
0
 public void NormalJust()
 {
     Flowable.Just(1).Buffer(2, 1)
     .Test()
     .AssertResult(
         listOf(1)
         );
 }
示例#4
0
 public void One()
 {
     Flowable.Just(1)
     .Parallel(1)
     .Sequential()
     .Test()
     .AssertResult(1);
 }
示例#5
0
 public void Fallback2()
 {
     Flowable.Just(0)
     .ConcatWith(Flowable.Never <int>())
     .Timeout(TimeSpan.FromMilliseconds(100), Flowable.Range(1, 5))
     .Test()
     .AwaitDone(TimeSpan.FromSeconds(5))
     .AssertResult(0, 1, 2, 3, 4, 5);
 }
 public void InnerErrorEager()
 {
     Flowable.Range(0, 5)
     .FlatMap(x => x == 0 ? Flowable.Error <int>(new Exception()) : Flowable.Just(x).Delay(TimeSpan.FromMilliseconds(10)), Flowable.BufferSize(), Flowable.BufferSize(), false)
     .Test()
     .AwaitDone(TimeSpan.FromSeconds(5))
     .AssertValueCount(0)
     .AssertError(typeof(Exception));
 }
 public void SourceErrorDelayed()
 {
     Flowable.Just(0)
     .ConcatWith(Flowable.Error <int>(new Exception()))
     .FlatMap(x => Flowable.Range(0, 5).Delay(TimeSpan.FromMilliseconds(10)))
     .Test()
     .AwaitDone(TimeSpan.FromSeconds(5))
     .AssertValues(Enumerable.Range(0, 5))
     .AssertError(typeof(Exception));
 }
示例#8
0
        public void ZipTest_SameLength()
        {
            TestSubscriber <int> ts = new TestSubscriber <int>();

            Flowable.Zip(Flowable.Just(1), Flowable.Just(2), (a, b) => a + b).Subscribe(ts);

            ts.AssertValue(3)
            .AssertComplete()
            .AssertNoError();
        }
示例#9
0
 public void LessConcurrency()
 {
     var result = Flowable.Range(0, 3)
                  .ConcatMapEager(x =>
     {
         return(Flowable.Just(x));
     }, 2)
                  .Test()
                  .AssertResult(0, 1, 2);
 }
示例#10
0
        public void ZipTest_FirstEmpty()
        {
            TestSubscriber <int> ts = new TestSubscriber <int>();

            Flowable.Zip(Flowable.Empty <int>(), Flowable.Just(2), (a, b) => a + b).Subscribe(ts);

            ts.AssertNoValues()
            .AssertComplete()
            .AssertNoError();
        }
示例#11
0
 public void ParallelSequentialRepeat()
 {
     Flowable.Just(1)
     .Repeat(1024)
     .Parallel(1)
     .Sequential()
     .Test()
     .AssertValueCount(1024)
     .AssertComplete()
     ;
 }
示例#12
0
 public void Single()
 {
     for (int i = 0; i < 100; i++)
     {
         Flowable.Just(1).SubscribeOn(Executors.Single)
         .Test()
         .WithTag("" + i)
         .AwaitDone(TimeSpan.FromSeconds(5))
         .AssertResult(1);
     }
 }
示例#13
0
        public void Tck102()
        {
            Flowable.Just(1).ConcatWith(Flowable.Error <int>(new Exception()))
            .RetryWhen(f =>
            {
                int[] counter = { 0 };

                return(f.TakeWhile(o => ++ counter[0] < 3));
            })
            .Test(10)
            .AssertResult(1, 1, 1);
        }
        public void Tck102()
        {
            Flowable.Just(1)
            .RepeatWhen(f =>
            {
                int[] counter = { 0 };

                return(f.TakeWhile(o => ++ counter[0] < 3));
            })
            .Test(10)
            .AssertResult(1, 1, 1);
        }
 public void NormalBackpressured()
 {
     Flowable.Range(1, 5).ConcatMap(v => Flowable.Just(v + 1))
     .Test(0L)
     .AssertValues()
     .RequestMore(1)
     .AssertValues(2)
     .RequestMore(2)
     .AssertValues(2, 3, 4)
     .RequestMore(2)
     .AssertResult(2, 3, 4, 5, 6);
 }
示例#16
0
 public void Normal2HideBackpressure()
 {
     Flowable.Just(1).SwitchMap(v => Flowable.Range(1, 5).Hide())
     .Test(0L)
     .AssertValues()
     .RequestMore(1)
     .AssertValues(1)
     .RequestMore(2)
     .AssertValues(1, 2, 3)
     .RequestMore(2)
     .AssertResult(1, 2, 3, 4, 5);
 }
 public void NormalBackpressured()
 {
     Flowable.CombineLatest(Flowable.Just(1), Flowable.Range(1, 5), (a, b) => a + b)
     .Test(0)
     .AssertValues()
     .RequestMore(1)
     .AssertValues(2)
     .RequestMore(2)
     .AssertValues(2, 3, 4)
     .RequestMore(2)
     .AssertResult(2, 3, 4, 5, 6);
 }
示例#18
0
 public void LessConcurrencyAsync3()
 {
     Flowable.Range(0, 10)
     .ConcatMapEager(x =>
     {
         return(Flowable.Just(x)
                .SubscribeOn(Executors.Computation));
     }, 3)
     .Test()
     .AwaitDone(TimeSpan.FromSeconds(5))
     .AssertResult(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
 }
        public override IPublisher <int> CreatePublisher(long elements)
        {
            return(Flowable.Just(1).ConcatWith(Flowable.Error <int>(new Exception("Forced failure")))
                   .RetryWhen(f =>
            {
                int[] counter = { 0 };

                return f.TakeWhile(o =>
                {
                    return ++counter[0] < elements;
                });
            }));
        }
        public override IPublisher <int> CreatePublisher(long elements)
        {
            return(Flowable.Just(1)
                   .RepeatWhen(f =>
            {
                int[] counter = { 0 };

                return f.TakeWhile(o =>
                {
                    return ++counter[0] < elements;
                });
            }));
        }
示例#21
0
        public void Backpressure()
        {
            var ts = Flowable.Just(1).ConcatWith(Flowable.Never <int>())
                     .Timeout(TimeSpan.FromMilliseconds(1), Flowable.Just(2))
                     .Test(1);

            Thread.Sleep(100);

            ts.AssertValues(1)
            .AssertNoError()
            .AssertNotComplete()
            .RequestMore(1)
            .AwaitDone(TimeSpan.FromSeconds(5))
            .AssertResult(1, 2);
        }
        public override IPublisher <int> CreatePublisher(long elements)
        {
            if ((elements & 1) == 0)
            {
                return(Flowable.Range(1, (int)elements / 2).ConcatMap(v => Flowable.Range(v, 2)));
            }

            return(Flowable.Range(0, 1 + (int)elements / 2).ConcatMap(v =>
            {
                if (v == 0)
                {
                    return Flowable.Just(v);
                }
                return Flowable.Range(v, 2);
            }));
        }
示例#23
0
        public async Task ParallelSequentialBlocking()
        {
            var data = Flowable.Just(1)
                       .Repeat(1024)
                       .Parallel(1)
                       .Sequential()
                       .BlockingEnumerable();

            var list = new List <int>();

            await Task.Run(() =>
            {
                foreach (var a in data)
                {
                    list.Add(a);
                }
            });


            Assert.AreEqual(1024, list.Count);
        }
        public void NormalBackpressured()
        {
            Flowable.Just(1)
            .RepeatWhen(f =>
            {
                int[] counter = { 0 };

                return(f.TakeWhile(o => ++ counter[0] < 5));
            })
            .Test(0)
            .AssertEmpty()
            .RequestMore(1)
            .AssertValues(1)
            .RequestMore(1)
            .AssertValues(1, 1)
            .RequestMore(1)
            .AssertValues(1, 1, 1)
            .RequestMore(1)
            .AssertValues(1, 1, 1, 1)
            .RequestMore(1)
            .AssertResult(1, 1, 1, 1, 1)
            ;
        }
示例#25
0
        public void NormalBackpressured()
        {
            Flowable.Just(1).ConcatWith(Flowable.Error <int>(new Exception()))
            .RetryWhen(f =>
            {
                int[] counter = { 0 };

                return(f.TakeWhile(o => ++ counter[0] < 5));
            })
            .Test(0)
            .AssertEmpty()
            .RequestMore(1)
            .AssertValues(1)
            .RequestMore(1)
            .AssertValues(1, 1)
            .RequestMore(1)
            .AssertValues(1, 1, 1)
            .RequestMore(1)
            .AssertValues(1, 1, 1, 1)
            .RequestMore(1)
            .AssertResult(1, 1, 1, 1, 1)
            ;
        }
示例#26
0
        public void SingleShared()
        {
            var w  = Executors.Single.Worker;
            var sw = Executors.NewShared(w);

            try
            {
                Flowable.Just(1).SubscribeOn(Executors.Single)
                .Test()
                .WithTag("NonShared - 1")
                .AwaitDone(TimeSpan.FromSeconds(5))
                .AssertResult(1);

                Flowable.Just(1).SubscribeOn(sw)
                .Test()
                .WithTag("First")
                .AwaitDone(TimeSpan.FromSeconds(5))
                .AssertResult(1);

                Flowable.Just(1).SubscribeOn(Executors.Single)
                .Test()
                .WithTag("NonShared - 2")
                .AwaitDone(TimeSpan.FromSeconds(5))
                .AssertResult(1);

                Flowable.Just(1).SubscribeOn(Executors.NewShared(w))
                .Test()
                .WithTag("Second")
                .AwaitDone(TimeSpan.FromSeconds(5))
                .AssertResult(1);
            }
            finally
            {
                w.Dispose();
            }
        }
 public override IPublisher <int> CreatePublisher(long elements)
 {
     return(Flowable.Range(1, (int)elements).Hide().ConcatMap(v => Flowable.Just(v)));
 }
示例#28
0
 public override IPublisher <int> CreatePublisher(long elements)
 {
     return(Flowable.Range(1, (int)elements).SwitchIfEmpty(Enumerable.Range(1, 3).Select(v => Flowable.Just(-v))));
 }
示例#29
0
 public void Just()
 {
     Flowable.Just(1).GroupBy(v => v).FlatMap(v => v)
     .Test()
     .AssertResult(1);
 }
 public override IPublisher <int> CreatePublisher(long elements)
 {
     return(Flowable.Range(1, (int)elements)
            .SkipUntil(Flowable.Just(1))
            .Filter(v => true));
 }