Example #1
0
 def data_to_heaps(self, data):
     """Take some data and pass it through the receiver to obtain a set of heaps.
     """
     thread_pool = spead2.ThreadPool()
     stream = recv.Stream(thread_pool, self.flavour.bug_compat)
     stream.add_buffer_reader(data)
     return list(stream)
Example #2
0
 def test_ipv6_interface_address(self):
     config = recv.UdpIbvConfig(endpoints=[('239.255.88.88', 8888)],
                                interface_address='::1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError, match='interface address'):
         stream.add_udp_ibv_reader(config)
Example #3
0
    def test_no_stop_heap(self):
        """A heap containing a stop is not passed to the ring"""
        thread_pool = spead2.ThreadPool(1)
        sender = send.BytesStream(thread_pool)
        ig = send.ItemGroup()
        data = np.array([[6, 7, 8], [10, 11, 12000]], dtype=np.uint16)
        ig.add_item(id=0x2345,
                    name='name',
                    description='description',
                    shape=data.shape,
                    dtype=data.dtype,
                    value=data)
        gen = send.HeapGenerator(ig)
        sender.send_heap(gen.get_heap(data='all'))
        sender.send_heap(gen.get_end())
        receiver = recv.Stream(thread_pool)
        receiver.add_buffer_reader(sender.getvalue())
        heaps = list(receiver)
        assert len(heaps) == 1

        stats = receiver.stats
        assert stats.heaps == 1
        assert stats.packets == 2
        assert stats.incomplete_heaps_evicted == 0
        assert stats.incomplete_heaps_flushed == 0
        assert stats.worker_blocked == 0
Example #4
0
 def test_bad_interface_address(self):
     config = recv.UdpIbvConfig(
         endpoints=[('239.255.88.88', 8888)],
         interface_address='this is not an interface address')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(RuntimeError, match='Host not found'):
         stream.add_udp_ibv_reader(config)
Example #5
0
 def test_ipv6_endpoints(self):
     config = recv.UdpIbvConfig(endpoints=[('::1', 8888)],
                                interface_address='10.0.0.1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError,
                        match='endpoint is not an IPv4 address'):
         stream.add_udp_ibv_reader(config)
Example #6
0
    def setup(self):
        self.receiver = recv.Stream(spead2.ThreadPool())
        recv_sock = socket.socket()
        recv_sock.bind(("127.0.0.1", 0))
        recv_sock.listen(1)
        port = recv_sock.getsockname()[1]
        self.receiver.add_tcp_reader(acceptor=recv_sock)
        recv_sock.close()

        self.send_sock = socket.socket()
        self.send_sock.connect(("127.0.0.1", port))
Example #7
0
    def data_to_heaps(self, data, **kwargs):
        """Take some data and pass it through the receiver to obtain a set of heaps.

        Keyword arguments are passed to the receiver constructor.
        """
        thread_pool = spead2.ThreadPool()
        stop_on_stop_item = kwargs.pop('stop_on_stop_item', None)
        stream = recv.Stream(thread_pool, self.flavour.bug_compat, **kwargs)
        if stop_on_stop_item is not None:
            stream.stop_on_stop_item = stop_on_stop_item
        stream.add_buffer_reader(data)
        return list(stream)
Example #8
0
    def data_to_heaps(self, data, **kwargs):
        """Take some data and pass it through the receiver to obtain a set of heaps.

        Keyword arguments are passed to the receiver constructor.
        """
        thread_pool = spead2.ThreadPool()
        config = recv.StreamConfig(bug_compat=self.flavour.bug_compat)
        ring_config = recv.RingStreamConfig()
        for key in [
                'stop_on_stop_item', 'allow_unsized_heaps',
                'allow_out_of_order'
        ]:
            if key in kwargs:
                setattr(config, key, kwargs.pop(key))
        for key in ['contiguous_only', 'incomplete_keep_payload_ranges']:
            if key in kwargs:
                setattr(ring_config, key, kwargs.pop(key))
        if kwargs:
            raise ValueError(f'Unexpected keyword arguments ({kwargs})')
        stream = recv.Stream(thread_pool, config, ring_config)
        stream.add_buffer_reader(data)
        return list(stream)
Example #9
0
    def test_full_stop(self):
        """Must be able to stop even if the consumer is not consuming
        anything."""
        thread_pool = spead2.ThreadPool(1)
        sender = send.BytesStream(thread_pool)
        ig = send.ItemGroup()
        data = np.array([[6, 7, 8], [10, 11, 12000]], dtype=np.uint16)
        ig.add_item(id=0x2345,
                    name='name',
                    description='description',
                    shape=data.shape,
                    dtype=data.dtype,
                    value=data)
        gen = send.HeapGenerator(ig)
        for i in range(10):
            sender.send_heap(gen.get_heap(data='all'))
        recv_ring_config = recv.RingStreamConfig(heaps=4)
        receiver = recv.Stream(thread_pool, ring_config=recv_ring_config)
        receiver.add_buffer_reader(sender.getvalue())
        # Wait for the ring buffer to block
        while receiver.stats.worker_blocked == 0:
            time.sleep(0.0)
        # Can't usefully check the stats here, because they're only
        # updated at the end of a batch.
        assert receiver.ringbuffer.capacity() == 4
        assert receiver.ringbuffer.size() == 4

        receiver.stop()  # This unblocks all remaining heaps
        stats = receiver.stats
        assert stats.heaps == 10
        assert stats.packets == 10
        assert stats.incomplete_heaps_evicted == 0
        assert stats.incomplete_heaps_flushed == 0
        assert stats.worker_blocked == 1
        assert receiver.ringbuffer.capacity() == 4
        assert receiver.ringbuffer.size() == 4
Example #10
0
 def test_illegal_udp_port(self):
     receiver = recv.Stream(spead2.ThreadPool())
     with pytest.raises(RuntimeError):
         receiver.add_udp_reader(22)
Example #11
0
 def test_out_of_range_udp_port(self):
     receiver = recv.Stream(spead2.ThreadPool())
     with pytest.raises(TypeError):
         receiver.add_udp_reader(100000)
Example #12
0
 def test_no_endpoints(self):
     config = recv.UdpIbvConfig(interface_address='10.0.0.1')
     stream = recv.Stream(spead2.ThreadPool(), recv.StreamConfig(),
                          recv.RingStreamConfig())
     with pytest.raises(ValueError, match='endpoints is empty'):
         stream.add_udp_ibv_reader(config)