def test_init_state(self): sink = TObserver() obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.InitState) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnLeftRight)
def test_exception(self): """ ack.on_next WaitOnRight ------------> Stopped """ sink = TObserver(immediate_continue=0) obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_list([1]) self.right.on_error(self.exception) self.assertEqual(sink.exception, self.exception)
def test_right_complete(self): """ s2.on_completed WaitOnLeftRight -----------------> Stopped InitState RightCompletedState """ sink = TObserver() obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) self.right.on_completed() self.assertIsInstance(self.measure_state(obs), ZipStates.Stopped) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.RightCompletedState) self.assertTrue(sink.is_completed)
def test_left_complete_wait_on_right(self): """ s1.on_completed WaitOnLeftRight ------------> WaitOnRight InitState LeftCompletedState """ sink = TObserver(immediate_continue=0) obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) self.left.on_next_list([1]) self.left.on_completed() self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.LeftCompletedState) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnRight)
def test_emit_left_with_synchronous_ack(self): """ s1.on_next WaitOnLeftRight ------------> WaitOnRight InitState InitState """ sink = TObserver() obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_single(1) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnRight) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.InitState) self.assertFalse(ack1.has_value) self.assertListEqual(sink.received, [])
def test_acknowledge_after_completed(self): """ ack.on_next Stopped ------------> Stopped """ sink = TObserver(immediate_continue=0) obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_list([1]) ack2 = self.right.on_next_list([1]) self.left.on_completed() sink.ack.on_next(continue_ack) self.assertIsInstance(self.measure_state(obs), ZipStates.Stopped) self.assertListEqual(sink.received, [(1, 1)])
def test_wait_on_right_to_wait_on_left_with_synchronous_ack(self): """ s2.on_next WaitOnRight ------------> WaitOnLeft """ sink = TObserver() obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_list([1, 2]) ack2 = self.right.on_next_list([1, 2, 3]) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnLeft) self.assertIsInstance(ack1.value, ContinueAck) self.assertFalse(ack2.has_value) self.assertListEqual(sink.received, [(1, 1), (2, 2)])
def test_multiple_elements_with_synchronous_ack(self): """ s2.on_next WaitOnRight ------------> WaitOnLeftRight """ sink = TObserver() obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_list([1, 2, 3]) ack2 = self.right.on_next_list([1, 2, 3]) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnLeftRight) self.assertIsInstance(ack1.value, ContinueAck) self.assertIsInstance(ack2, ContinueAck) self.assertListEqual(sink.received, [(1, 1), (2, 2), (3, 3)])
def test_left_complete_to_wait_on_right(self): """ s2.on_next WaitOnRight ------------> WaitOnRight LeftComplete LeftComplete """ sink = TObserver(immediate_continue=0) obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) self.left.on_next_list([1, 1]) self.left.on_completed() self.right.on_next_list([1]) self.assertIsInstance(self.measure_termination_state(obs), TerminationStates.LeftCompletedState) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnRight) self.assertListEqual(sink.received, [(1, 1)])
def test_acknowledge_left(self): """ ack.on_next WaitOnLeft ------------> WaitOnLeft """ sink = TObserver(immediate_continue=0) obs = ZipObservable(self.left, self.right) obs.observe(init_observer_info(sink)) ack1 = self.left.on_next_list([1]) ack2 = self.right.on_next_list([1, 2]) sink.ack.on_next(continue_ack) self.assertIsInstance(self.measure_state(obs), ZipStates.WaitOnLeft) self.assertIsInstance(ack1.value, ContinueAck) self.assertFalse(ack2.has_value) self.assertListEqual(sink.received, [(1, 1)])
def unsafe_subscribe(self, subscriber: Subscriber) -> Subscription: left_subscription = self.left.unsafe_subscribe(subscriber=subscriber) right_subscription = self.right.unsafe_subscribe(subscriber=subscriber) return left_subscription.copy(observable=ZipObservable( left=left_subscription.observable, right=right_subscription.observable, stack=self.stack, ), )
def unsafe_subscribe(self, subscriber: Subscriber) -> Subscription: left_subscription = self.left.unsafe_subscribe(subscriber=subscriber) right_subscription = self.right.unsafe_subscribe(subscriber=subscriber) result = left_subscription.index.match_with( right_subscription.index, subscriber=subscriber, stack=self.stack, ) # The resulting zip Flowable propagates selectors from left and right downstream if the bases of # left and right Flowable match if isinstance(result, FlowableBaseAndSelectorsMatch): if isinstance(result.left, IdentitySeqMapInfo) and isinstance( result.right, IdentitySeqMapInfo): base = left_subscription.index.base selectors = {} if left_subscription.index.selectors is not None: selectors = { **selectors, **left_subscription.index.selectors } if right_subscription.index.selectors is not None: selectors = { **selectors, **right_subscription.index.selectors } else: base = None selectors = None else: base = None selectors = None observable = ZipObservable( left=left_subscription.observable, right=right_subscription.observable, stack=self.stack, ) return left_subscription.copy( index=FlowableBaseAndSelectors(base=base, selectors=selectors), observable=observable, )