Пример #1
0
 /**
  * Upon subscription, the subscriber's onSubscribe is called, no other Subscriber methods are
  * invoked, the publisher hasSubscribers, isSubscribed is true, and existing subscriptions are
  * unaffected.
  */
 public void testSubscribe1() {
   TestSubscriber s = new TestSubscriber();
   SubmissionPublisher<Integer> p = basicPublisher();
   p.subscribe(s);
   assertTrue(p.hasSubscribers());
   assertEquals(1, p.getNumberOfSubscribers());
   assertTrue(p.getSubscribers().contains(s));
   assertTrue(p.isSubscribed(s));
   s.awaitSubscribe();
   assertNotNull(s.sn);
   assertEquals(0, s.nexts);
   assertEquals(0, s.errors);
   assertEquals(0, s.completes);
   TestSubscriber s2 = new TestSubscriber();
   p.subscribe(s2);
   assertTrue(p.hasSubscribers());
   assertEquals(2, p.getNumberOfSubscribers());
   assertTrue(p.getSubscribers().contains(s));
   assertTrue(p.getSubscribers().contains(s2));
   assertTrue(p.isSubscribed(s));
   assertTrue(p.isSubscribed(s2));
   s2.awaitSubscribe();
   assertNotNull(s2.sn);
   assertEquals(0, s2.nexts);
   assertEquals(0, s2.errors);
   assertEquals(0, s2.completes);
   p.close();
 }
Пример #2
0
 /** Cancelling a subscription eventually causes no more onNexts to be issued */
 public void testCancel() {
   SubmissionPublisher<Integer> p = basicPublisher();
   TestSubscriber s1 = new TestSubscriber();
   TestSubscriber s2 = new TestSubscriber();
   p.subscribe(s1);
   p.subscribe(s2);
   s1.awaitSubscribe();
   p.submit(1);
   s1.sn.cancel();
   for (int i = 2; i <= 20; ++i) p.submit(i);
   p.close();
   s2.awaitComplete();
   assertEquals(20, s2.nexts);
   assertEquals(1, s2.completes);
   assertTrue(s1.nexts < 20);
   assertFalse(p.isSubscribed(s1));
 }