/** submit returns number of lagged items, compatible with result of estimateMaximumLag. */ public void testLaggedSubmit() { SubmissionPublisher<Integer> p = basicPublisher(); TestSubscriber s1 = new TestSubscriber(); s1.request = false; TestSubscriber s2 = new TestSubscriber(); s2.request = false; p.subscribe(s1); p.subscribe(s2); s2.awaitSubscribe(); s1.awaitSubscribe(); assertEquals(1, p.submit(1)); assertTrue(p.estimateMaximumLag() >= 1); assertTrue(p.submit(2) >= 2); assertTrue(p.estimateMaximumLag() >= 2); s1.sn.request(4); assertTrue(p.submit(3) >= 3); assertTrue(p.estimateMaximumLag() >= 3); s2.sn.request(4); p.submit(4); p.close(); s2.awaitComplete(); assertEquals(4, s2.nexts); s1.awaitComplete(); assertEquals(4, s2.nexts); }
/** * 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()); }