Example #1
0
def test_transfered_inactive_non_continuous_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    # Run 2 non-continutes operations
    ticket.run(Operation(0, 100))
    ticket.run(Operation(200, 100))
    assert ticket.transferred() == 200

    # Run last operation filling the hole - with some overlap.
    ticket.run(Operation(80, 120))
    assert ticket.transferred() == 300
Example #2
0
def test_repr():
    ticket = Ticket(testutil.create_ticket(ops=["read"], filename="tmp_file"))
    ticket_repr = repr(ticket)

    info = ticket.info()
    del info["timeout"]

    for key, value in info.items():
        pair = "%s=%r" % (key, value)
        assert pair in ticket_repr
Example #3
0
def test_transfered_inactive_empty_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    ticket.run(Operation(0, 0))
    assert ticket.transferred() == 0

    ticket.run(Operation(1000, 0))
    assert ticket.transferred() == 0
Example #4
0
def test_run_operation_benchmark():
    # Run 1000000 operations with 4 concurrent threads.
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    operations = 10**6
    workers = 4
    chunk = 10**9
    step = chunk * workers // operations

    def worker(offset, size):
        while offset < size:
            ticket.run(Operation(offset, step))
            offset += step

    start = time.time()

    threads = []
    try:
        for i in range(workers):
            t = util.start_thread(worker, args=(i * chunk, chunk))
            threads.append(t)
    finally:
        for t in threads:
            t.join()

    elapsed = time.time() - start

    print("%d operations, %d concurrent threads in %.2f seconds (%d nsec/op)" %
          (operations, workers, elapsed, elapsed * 10**9 // operations))
Example #5
0
def test_ticket_run():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    op = Operation(0, 100)
    assert ticket.transferred() == op.done
    assert op.done == 0

    ticket.run(op)

    assert ticket.transferred() == op.done
    assert op.done == 100
Example #6
0
def test_transferred_benchmark(concurrent):
    # Time trransferred call with multiple ongoing and completed operations.
    ticket = Ticket(testutil.create_ticket(ops=["read"]))

    calls = 10000

    # Add some completed ranges - assume worst case when ranges are not
    # continues.
    for i in xrange(concurrent):
        ticket.run(Operation(i * 1000, 100))

    # Add some ongoing operations - assume worst case when ranges are not
    # continues.
    for i in xrange(concurrent):
        ticket._add_operation(Operation(i * 1000 + 200, 100))

    # Time transferred call - merging ongoing and completed ranges.
    start = time.time()
    for i in xrange(calls):
        ticket.transferred()
    elapsed = time.time() - start

    print("%d concurrent operations, %d calls in %.2f seconds (%d nsec/op)" %
          (concurrent, calls, elapsed, elapsed * 10**9 // calls))
Example #7
0
def test_transfered_nothing():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    assert ticket.transferred() == 0
Example #8
0
def test_transfer_id():
    ticket = Ticket(testutil.create_ticket(transfer_id="123"))
    assert ticket.transfer_id == "123"
Example #9
0
def test_transfer_id_unset():
    ticket = Ticket(testutil.create_ticket())
    assert ticket.transfer_id is None
Example #10
0
def test_transfered_ongoing_non_continues_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))

    # Start 2 ongoing operations.
    # ongoing: 0-0, 200-200
    # completed:
    op1 = Operation(0, 100)
    op2 = Operation(200, 100)
    ticket._add_operation(op1)
    ticket._add_operation(op2)
    assert ticket.transferred() == 0
    assert ticket.active()

    # Consume op1 data:
    # ongoing: 0-100, 200-200
    # completed:
    op1.run()
    ticket._remove_operation(op1)
    assert ticket.transferred() == 100

    # Consume op2 data:
    # ongoing: 0-100, 200-300
    # completed:
    op2.run()
    ticket._remove_operation(op2)
    assert ticket.transferred() == 200
Example #11
0
def test_transfered_inactive_overlapping_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    ticket.run(Operation(0, 120))
    assert ticket.transferred() == 120

    ticket.run(Operation(100, 100))
    assert ticket.transferred() == 200

    ticket.run(Operation(180, 120))
    assert ticket.transferred() == 300
Example #12
0
def test_sparse():
    ticket = Ticket(testutil.create_ticket(sparse=True))
    assert ticket.sparse
Example #13
0
def test_sparse_unset():
    ticket = Ticket(testutil.create_ticket())
    assert not ticket.sparse
Example #14
0
def test_invalid_parameter(kw):
    with pytest.raises(errors.InvalidTicketParameter):
        Ticket(testutil.create_ticket(**kw))
Example #15
0
def test_invalid_argument(arg):
    with pytest.raises(errors.InvalidTicket):
        Ticket(arg)
Example #16
0
def test_transfered_inactive_unordered_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))
    ticket.run(Operation(100, 100))
    assert ticket.transferred() == 100

    ticket.run(Operation(0, 100))
    assert ticket.transferred() == 200

    ticket.run(Operation(200, 100))
    assert ticket.transferred() == 300
Example #17
0
def test_dirty_unset():
    ticket = Ticket(testutil.create_ticket())
    assert not ticket.dirty
Example #18
0
def test_dirty():
    ticket = Ticket(testutil.create_ticket(dirty=True))
    assert ticket.dirty
Example #19
0
def test_transfered_ongoing_overlapping_ops():
    ticket = Ticket(testutil.create_ticket(ops=["read"]))

    # Start 2 ongoing operations.
    # ongoing: 0-0, 80-80
    # completed:
    op1 = Operation(0, 120)
    op2 = Operation(80, 120)
    ticket._add_operation(op1)
    ticket._add_operation(op2)
    assert ticket.transferred() == 0
    assert ticket.active()

    # Consume op1 data:
    # ongoing: 0-120, 80-80
    # completed:
    op1.run()
    ticket._remove_operation(op1)
    assert ticket.transferred() == 120
    assert ticket.active()

    # Consume op2 data:
    # ongoing: 0-120, 80-200
    # completed:
    op2.run()
    ticket._remove_operation(op2)
    assert ticket.transferred() == 200
    assert not ticket.active()