示例#1
0
  @Test
  public void testRequestFromDecoupledOperatorThatRequestsN() {
    Subscriber<String> s = new TestSubscriber<String>();
    final AtomicLong innerR = new AtomicLong();
    Operator<String, String> o =
        new Operator<String, String>() {

          @Override
          public Subscriber<? super String> call(Subscriber<? super String> child) {
            // we want to decouple the chain so set our own Producer on the child instead of it
            // coming from the parent
            child.setProducer(
                new Producer() {

                  @Override
                  public void request(long n) {
                    innerR.set(n);
                  }
                });

            Subscriber<String> as =
                new Subscriber<String>() {

                  @Override
                  public void onCompleted() {}

                  @Override
                  public void onError(Throwable e) {}

                  @Override
                  public void onNext(String t) {}
                };
            // we request 99 up to the parent
            as.request(99);
            return as;
          }
        };
    s.request(10);
    Subscriber<? super String> ns = o.call(s);

    final AtomicLong r = new AtomicLong();
    // set set the producer at the top of the chain (ns) and it should flow through the operator to
    // the (s) subscriber
    // and then it should request up with the value set on the final Subscriber (s)
    ns.setProducer(
        new Producer() {

          @Override
          public void request(long n) {
            r.set(n);
          }
        });
    assertEquals(99, r.get());
    assertEquals(10, innerR.get());
  }
示例#2
0
  @Test
  public void testRequestFromDecoupledOperator() {
    Subscriber<String> s = new TestSubscriber<String>();
    Operator<String, String> o =
        new Operator<String, String>() {

          @Override
          public Subscriber<? super String> call(Subscriber<? super String> s) {
            return new Subscriber<String>() {

              @Override
              public void onCompleted() {}

              @Override
              public void onError(Throwable e) {}

              @Override
              public void onNext(String t) {}
            };
          }
        };
    s.request(10);
    Subscriber<? super String> ns = o.call(s);

    final AtomicLong r = new AtomicLong();
    // set set the producer at the top of the chain (ns) and it should flow through the operator to
    // the (s) subscriber
    // and then it should request up with the value set on the final Subscriber (s)
    ns.setProducer(
        new Producer() {

          @Override
          public void request(long n) {
            r.set(n);
          }
        });
    // this will be Long.MAX_VALUE because it is decoupled and nothing requested on the Operator
    // subscriber
    assertEquals(Long.MAX_VALUE, r.get());
  }