コード例 #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
 /**
  * A new SubmissionPublisher has no subscribers, a non-null executor, a power-of-two capacity, is
  * not closed, and reports zero demand and lag
  */
 void checkInitialState(SubmissionPublisher<?> p) {
   assertFalse(p.hasSubscribers());
   assertEquals(0, p.getNumberOfSubscribers());
   assertTrue(p.getSubscribers().isEmpty());
   assertFalse(p.isClosed());
   assertNull(p.getClosedException());
   int n = p.getMaxBufferCapacity();
   assertTrue((n & (n - 1)) == 0); // power of two
   assertNotNull(p.getExecutor());
   assertEquals(0, p.estimateMinimumDemand());
   assertEquals(0, p.estimateMaximumLag());
 }