Exemplo n.º 1
0
def test_LIFO_read_multiple():
    buf = Buffer(yield_next="newest")
    buf.write(["1", "2", "3"])
    assert len(buf.data) == 3

    assert buf.read(3) == ["3", "2", "1"]
    assert len(buf.data) == 0
Exemplo n.º 2
0
def test_FIFO_read_multiple():
    buf = Buffer()
    buf.write(["1", "2", "3"])
    assert len(buf.data) == 3

    assert buf.read(3) == ["1", "2", "3"]
    assert len(buf.data) == 0
Exemplo n.º 3
0
def test_write_multiple_preserves_order():
    buf1 = Buffer()
    buf1.write(["1"])
    buf1.write(["2"])
    buf1.write(["3"])

    buf2 = Buffer()
    buf2.write(["1", "2", "3"])

    assert list(buf1.data) == ["1", "2", "3"]
    assert list(buf2.data) == ["1", "2", "3"]
Exemplo n.º 4
0
def test_GPusher_init():
    in_buf = Buffer()
    out_buf = Buffer()
    gpusher = GammaPusher(in_buf,
                          out_buf,
                          quantity=1,
                          retry_shape=1,
                          cycle_shape=1)

    assert gpusher.source is in_buf
    assert gpusher.sink is out_buf
    assert gpusher.quantity == 1
Exemplo n.º 5
0
def test_DPusher_init():
    in_buf = Buffer()
    out_buf = Buffer()
    dpusher = DeterministicPusher(in_buf,
                                  out_buf,
                                  quantity=1,
                                  retry_delay=0.1,
                                  cycle_delay=1)

    assert dpusher.source is in_buf
    assert dpusher.sink is out_buf
    assert dpusher.quantity == 1
    assert dpusher.retry_delay == 0.1
    assert dpusher.cycle_delay == 1
Exemplo n.º 6
0
def test_transforms():
    buf = Buffer()
    assert len(buf.data) == 0

    doubler = DoublingTransformer(buf)
    doubler.write([1, 2, 3])
    assert list(buf.data) == [2, 4, 6]
Exemplo n.º 7
0
def test_DisAdapter_starts_connected():
    buf = Buffer()
    assert len(buf.data) == 0

    dis_adapter = DeterministicDisconnectAdapter(buf,
                                                 time_until=time_until,
                                                 duration=duration)
    assert dis_adapter.connected
Exemplo n.º 8
0
    def on_start(self):
        """
        on_start is called when a Locust start before any task is scheduled
        """
        # Base Sources/Sinks
        data = [{"data": str(num)} for num in range(1024)]
        test_data = CircularReadBuffer(data)
        device1 = Buffer()
        device2 = Buffer()
        server = HTTPClient(method="POST", url="http://localhost:8000")

        # Data Generation
        gen_worker = DeterministicPusher(test_data,
                                         device1,
                                         retry_delay=0.00001,
                                         cycle_delay=0.1)

        # Device Link
        link_connect = GammaDisconnectAdapter(device2,
                                              time_until_shape=2,
                                              duration_shape=1)
        link_worker = GammaPusher(device1,
                                  link_connect,
                                  quantity=16,
                                  retry_shape=0.00001,
                                  cycle_shape=0.5)

        # Server Upload
        upload_connect = GammaDisconnectAdapter(server,
                                                time_until_shape=2,
                                                duration_shape=1)
        upload_worker = GammaPusher(device2,
                                    upload_connect,
                                    quantity=32,
                                    retry_shape=0.00001,
                                    cycle_shape=0.5)

        # Run Workers
        gen_worker.start()
        link_worker.start()
        upload_worker.start()
        link_connect.start()
        upload_connect.start()

        stats = StatsWorker(device1, link_connect, device2, upload_connect)
        stats.start()
Exemplo n.º 9
0
def test_DisAdapter_blocks_while_disconnected():
    buf = Buffer()
    assert len(buf.data) == 0

    dis_adapter = DeterministicDisconnectAdapter(buf,
                                                 time_until=time_until,
                                                 duration=duration)

    dis_adapter.connected = False
    dis_adapter.write(["test1"])
    assert len(buf.data) == 0
Exemplo n.º 10
0
def test_write_overflow_drop_newest():
    buf = Buffer(drop_next="newest", capacity=3)
    buf.write(["test1", "test2", "test3"])
    assert list(buf.data) == ["test1", "test2", "test3"]
    assert len(buf.data) == 3

    buf.write(["test4"])
    assert list(buf.data) == ["test1", "test2", "test4"]
Exemplo n.º 11
0
def test_DisAdapter_reconnects():
    buf = Buffer()
    assert len(buf.data) == 0

    dis_adapter = DeterministicDisconnectAdapter(buf,
                                                 time_until=time_until,
                                                 duration=duration)

    dis_adapter.start()

    sleep(time_until + duration + (time_until / 2))
    assert dis_adapter.connected

    _reset()
Exemplo n.º 12
0
def test_DPusher_run():
    data = ["test1", "test2"]

    in_buf = Buffer()
    out_buf = Buffer()
    in_buf.write(list(data))

    assert list(in_buf.data) == data
    assert list(out_buf.data) == []

    # Retry should not be triggered
    retry_delay = 0.1
    # cycle_delay was tested to work with values greater than 0.06
    # set to 0.1 for safety margin
    cycle_delay = 0.1

    dpusher = DeterministicPusher(in_buf,
                                  out_buf,
                                  quantity=1,
                                  retry_delay=retry_delay,
                                  cycle_delay=cycle_delay)
    dpusher.start()
    # Offset us to the halfway to the first cycle
    time.sleep(cycle_delay / 2)

    # Wait until halfway after the first cycle
    time.sleep(cycle_delay)
    assert list(in_buf.data) == ["test2"]
    assert list(out_buf.data) == ["test1"]

    # Wait until halfway past the second cycle
    time.sleep(cycle_delay)
    assert list(in_buf.data) == []
    assert list(out_buf.data) == ["test1", "test2"]

    _reset()
Exemplo n.º 13
0
def test_read_empty():
    buf = Buffer()
    assert buf.read() == []
    assert len(buf.data) == 0
Exemplo n.º 14
0
def test_init_illegal_arg():
    with pytest.raises(ValueError):
        Buffer(yield_next='OLD')
Exemplo n.º 15
0
def test_init_valid_args():
    buf = Buffer()
    assert buf.yield_next == "oldest"
    assert buf.drop_next == "oldest"
    assert len(buf.data) == 0